-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Terraform: Add import tests for CloudIoTRegistry #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
modular-magician
merged 6 commits into
GoogleCloudPlatform:master
from
rileykarson:cloudiot-import
Oct 17, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d467676
Terraform: Add import tests for CloudIoTRegistry
rileykarson fcd7777
Basic structure for singular InSpec resources (#573)
slevenick 2923c48
move puppet logging to debug instead of info (#574)
33a4c2a
Terraform: Add project, organization, folder, service account tests t…
rileykarson 772b9e8
Merge d467676924e0904b097868f0671738f5620195f3 into 33a4c2a429df77c91…
rileykarson 69f6c9c
Update tracked submodules -> HEAD on Wed Oct 17 22:14:16 UTC 2018
modular-magician File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule terraform
updated
from 56f653 to bc31be
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
provider/terraform/tests/resource_cloudiot_registry_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| package google | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform/helper/acctest" | ||
| "github.com/hashicorp/terraform/helper/resource" | ||
| "github.com/hashicorp/terraform/terraform" | ||
| ) | ||
|
|
||
| func TestAccCloudIoTRegistry_basic(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| CheckDestroy: testAccCheckCloudIoTRegistryDestroy, | ||
| Steps: []resource.TestStep{ | ||
| resource.TestStep{ | ||
| Config: testAccCloudIoTRegistry_basic(registryName), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCloudIoTRegistryExists( | ||
| "google_cloudiot_registry.foobar"), | ||
| ), | ||
| }, | ||
| { | ||
| ResourceName: "google_cloudiot_registry.foobar", | ||
| ImportState: true, | ||
| ImportStateVerify: true, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestAccCloudIoTRegistry_extended(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| CheckDestroy: testAccCheckCloudIoTRegistryDestroy, | ||
| Steps: []resource.TestStep{ | ||
| resource.TestStep{ | ||
| Config: testAccCloudIoTRegistry_extended(registryName), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCloudIoTRegistryExists( | ||
| "google_cloudiot_registry.foobar"), | ||
| ), | ||
| }, | ||
| { | ||
| ResourceName: "google_cloudiot_registry.foobar", | ||
| ImportState: true, | ||
| ImportStateVerify: true, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestAccCloudIoTRegistry_update(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| CheckDestroy: testAccCheckCloudIoTRegistryDestroy, | ||
| Steps: []resource.TestStep{ | ||
| resource.TestStep{ | ||
| Config: testAccCloudIoTRegistry_basic(registryName), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCloudIoTRegistryExists( | ||
| "google_cloudiot_registry.foobar"), | ||
| ), | ||
| }, | ||
| resource.TestStep{ | ||
| Config: testAccCloudIoTRegistry_extended(registryName), | ||
| }, | ||
| resource.TestStep{ | ||
| Config: testAccCloudIoTRegistry_basic(registryName), | ||
| }, | ||
| { | ||
| ResourceName: "google_cloudiot_registry.foobar", | ||
| ImportState: true, | ||
| ImportStateVerify: true, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func testAccCheckCloudIoTRegistryDestroy(s *terraform.State) error { | ||
| for _, rs := range s.RootModule().Resources { | ||
| if rs.Type != "google_cloudiot_registry" { | ||
| continue | ||
| } | ||
| config := testAccProvider.Meta().(*Config) | ||
| registry, _ := config.clientCloudIoT.Projects.Locations.Registries.Get(rs.Primary.ID).Do() | ||
| if registry != nil { | ||
| return fmt.Errorf("Registry still present") | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func testAccCloudIoTRegistryExists(n string) resource.TestCheckFunc { | ||
| return func(s *terraform.State) error { | ||
| rs, ok := s.RootModule().Resources[n] | ||
| if !ok { | ||
| return fmt.Errorf("Not found: %s", n) | ||
| } | ||
| if rs.Primary.ID == "" { | ||
| return fmt.Errorf("No ID is set") | ||
| } | ||
| config := testAccProvider.Meta().(*Config) | ||
| _, err := config.clientCloudIoT.Projects.Locations.Registries.Get(rs.Primary.ID).Do() | ||
| if err != nil { | ||
| return fmt.Errorf("Registry does not exist") | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func testAccCloudIoTRegistry_basic(registryName string) string { | ||
| return fmt.Sprintf(` | ||
| resource "google_cloudiot_registry" "foobar" { | ||
| name = "%s" | ||
| }`, registryName) | ||
| } | ||
|
|
||
| func testAccCloudIoTRegistry_extended(registryName string) string { | ||
| return fmt.Sprintf(` | ||
| resource "google_project_iam_binding" "cloud-iot-iam-binding" { | ||
| members = ["serviceAccount:cloud-iot@system.gserviceaccount.com"] | ||
| role = "roles/pubsub.publisher" | ||
| } | ||
|
|
||
| resource "google_pubsub_topic" "default-devicestatus" { | ||
| name = "psregistry-test-devicestatus-%s" | ||
| } | ||
|
|
||
| resource "google_pubsub_topic" "default-telemetry" { | ||
| name = "psregistry-test-telemetry-%s" | ||
| } | ||
|
|
||
| resource "google_cloudiot_registry" "foobar" { | ||
| depends_on = ["google_project_iam_binding.cloud-iot-iam-binding"] | ||
|
|
||
| name = "%s" | ||
|
|
||
| event_notification_config = { | ||
| pubsub_topic_name = "${google_pubsub_topic.default-devicestatus.id}" | ||
| } | ||
|
|
||
| state_notification_config = { | ||
| pubsub_topic_name = "${google_pubsub_topic.default-telemetry.id}" | ||
| } | ||
|
|
||
| http_config = { | ||
| http_enabled_state = "HTTP_DISABLED" | ||
| } | ||
|
|
||
| mqtt_config = { | ||
| mqtt_enabled_state = "MQTT_DISABLED" | ||
| } | ||
|
|
||
| credentials = [ | ||
| { | ||
| "public_key_certificate" = { | ||
| format = "X509_CERTIFICATE_PEM" | ||
| certificate = "${file("test-fixtures/rsa_cert.pem")}" | ||
| } | ||
| }, | ||
| ] | ||
| } | ||
| `, acctest.RandString(10), acctest.RandString(10), registryName) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.