From d786c3b9c4fff5d2fc828caf42dd135d289040e4 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Thu, 12 Apr 2018 15:45:28 -0700 Subject: [PATCH] make all ImportStates have a matching ImportStateVerify (#1327) --- .../import_google_kms_crypto_key_iam_test.go | 75 -------- google/import_google_kms_key_ring_iam_test.go | 104 ----------- google/import_google_organization_iam_test.go | 57 ------ google/import_google_project_iam_test.go | 57 ------ google/resource_compute_instance_test.go | 160 ++++------------ .../resource_google_organization_iam_test.go | 18 ++ ...esource_google_project_iam_binding_test.go | 173 ++++++------------ ...resource_google_project_iam_member_test.go | 85 +++++---- google/resource_kms_crypto_key_iam_test.go | 28 +++ google/resource_kms_key_ring_iam_test.go | 24 +++ .../resource_pubsub_subscription_iam_test.go | 28 +-- google/resource_pubsub_topic_iam_test.go | 28 +-- 12 files changed, 242 insertions(+), 595 deletions(-) delete mode 100644 google/import_google_kms_crypto_key_iam_test.go delete mode 100644 google/import_google_kms_key_ring_iam_test.go delete mode 100644 google/import_google_organization_iam_test.go delete mode 100644 google/import_google_project_iam_test.go diff --git a/google/import_google_kms_crypto_key_iam_test.go b/google/import_google_kms_crypto_key_iam_test.go deleted file mode 100644 index 94afee93fde..00000000000 --- a/google/import_google_kms_crypto_key_iam_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccKmsCryptoKeyIamMember_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - projectId := acctest.RandomWithPrefix("tf-test") - billingAccount := getTestBillingAccountFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "roles/cloudkms.cryptoKeyEncrypter" - keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - keyRingId := &kmsKeyRingId{ - Project: projectId, - Location: DEFAULT_KMS_TEST_LOCATION, - Name: keyRingName, - } - cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccKmsCryptoKeyIamMember_basic(projectId, orgId, billingAccount, account, keyRingName, cryptoKeyName, roleId), - }, - - resource.TestStep{ - ResourceName: "google_kms_crypto_key_iam_member.foo", - ImportStateId: fmt.Sprintf("%s/%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), cryptoKeyName, roleId, account, projectId), - ImportState: true, - }, - }, - }) -} - -func TestAccKmsCryptoKeyIamBinding_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - projectId := acctest.RandomWithPrefix("tf-test") - billingAccount := getTestBillingAccountFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "roles/cloudkms.cryptoKeyEncrypter" - keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - keyRingId := &kmsKeyRingId{ - Project: projectId, - Location: DEFAULT_KMS_TEST_LOCATION, - Name: keyRingName, - } - cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccKmsCryptoKeyIamBinding_basic(projectId, orgId, billingAccount, account, keyRingName, cryptoKeyName, roleId), - }, - - resource.TestStep{ - ResourceName: "google_kms_crypto_key_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/%s %s", keyRingId.terraformId(), cryptoKeyName, roleId), - ImportState: true, - }, - }, - }) -} diff --git a/google/import_google_kms_key_ring_iam_test.go b/google/import_google_kms_key_ring_iam_test.go deleted file mode 100644 index 32bcdaedc05..00000000000 --- a/google/import_google_kms_key_ring_iam_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccKmsKeyRingIamMember_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - projectId := acctest.RandomWithPrefix("tf-test") - billingAccount := getTestBillingAccountFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "roles/cloudkms.cryptoKeyEncrypter" - keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - keyRingId := &kmsKeyRingId{ - Project: projectId, - Location: DEFAULT_KMS_TEST_LOCATION, - Name: keyRingName, - } - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccKmsKeyRingIamMember_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), - }, - - resource.TestStep{ - ResourceName: "google_kms_key_ring_iam_member.foo", - ImportStateId: fmt.Sprintf("%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), roleId, account, projectId), - ImportState: true, - }, - }, - }) -} - -func TestAccKmsKeyRingIamPolicy_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - projectId := acctest.RandomWithPrefix("tf-test") - billingAccount := getTestBillingAccountFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "roles/cloudkms.cryptoKeyEncrypter" - keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - keyRingId := &kmsKeyRingId{ - Project: projectId, - Location: DEFAULT_KMS_TEST_LOCATION, - Name: keyRingName, - } - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccKmsKeyRingIamPolicy_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), - }, - - resource.TestStep{ - ResourceName: "google_kms_key_ring_iam_policy.foo", - ImportStateId: keyRingId.terraformId(), - ImportState: true, - }, - }, - }) -} - -func TestAccKmsKeyRingIamBinding_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - projectId := acctest.RandomWithPrefix("tf-test") - billingAccount := getTestBillingAccountFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "roles/cloudkms.cryptoKeyEncrypter" - keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - keyRingId := &kmsKeyRingId{ - Project: projectId, - Location: DEFAULT_KMS_TEST_LOCATION, - Name: keyRingName, - } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccKmsKeyRingIamBinding_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), - }, - - resource.TestStep{ - ResourceName: "google_kms_key_ring_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s %s", keyRingId.terraformId(), roleId), - ImportState: true, - }, - }, - }) -} diff --git a/google/import_google_organization_iam_test.go b/google/import_google_organization_iam_test.go deleted file mode 100644 index f0017ef9d93..00000000000 --- a/google/import_google_organization_iam_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccOrganizationIamMember_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - projectId := getTestProjectFromEnv() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccOrganizationIamMember_basic(account, orgId), - }, - - resource.TestStep{ - ResourceName: "google_organization_iam_member.foo", - ImportStateId: fmt.Sprintf("%s roles/browser serviceAccount:%s@%s.iam.gserviceaccount.com", orgId, account, projectId), - ImportState: true, - }, - }, - }) -} - -func TestAccOrganizationIamBinding_importBasic(t *testing.T) { - t.Parallel() - - orgId := getTestOrgFromEnv(t) - account := acctest.RandomWithPrefix("tf-test") - roleId := "tfIamTest" + acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccOrganizationIamBinding_basic(account, roleId, orgId), - }, - - resource.TestStep{ - ResourceName: "google_organization_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s organizations/%s/roles/%s", orgId, orgId, roleId), - ImportState: true, - }, - }, - }) -} diff --git a/google/import_google_project_iam_test.go b/google/import_google_project_iam_test.go deleted file mode 100644 index b9486ca3d4d..00000000000 --- a/google/import_google_project_iam_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccProjectIamMember_importBasic(t *testing.T) { - t.Parallel() - - resourceName := "google_project_iam_member.acceptance" - org := getTestOrgFromEnv(t) - pid := "terraform-" + acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccProjectAssociateMemberBasic(pid, "Acceptance", org), - }, - - resource.TestStep{ - ResourceName: resourceName, - ImportStateId: fmt.Sprintf("%s %s %s", pid, "roles/compute.instanceAdmin", "user:admin@hashicorptest.com"), - ImportState: true, - }, - }, - }) -} - -func TestAccProjectIamBinding_importBasic(t *testing.T) { - t.Parallel() - - resourceName := "google_project_iam_binding.acceptance" - org := getTestOrgFromEnv(t) - pid := "terraform-" + acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccProjectAssociateBindingBasic(pid, "Acceptance", org), - }, - - resource.TestStep{ - ResourceName: resourceName, - ImportStateId: fmt.Sprintf("%s %s", pid, "roles/compute.instanceAdmin"), - ImportState: true, - }, - }, - }) -} diff --git a/google/resource_compute_instance_test.go b/google/resource_compute_instance_test.go index 4697e240dbf..b766f75f304 100644 --- a/google/resource_compute_instance_test.go +++ b/google/resource_compute_instance_test.go @@ -13,6 +13,22 @@ import ( "google.golang.org/api/compute/v1" ) +func computeInstanceImportStep(zone, instanceName string, additionalImportIgnores []string) resource.TestStep { + // create_timeout has a default value, but it's deprecated so don't worry about it + // metadata is only read into state if set in the config + // since importing doesn't know whether metadata.startup_script vs metadata_startup_script is set in the config, + // it guesses metadata_startup_script + ignores := []string{"create_timeout", "metadata.%", "metadata.startup-script", "metadata_startup_script"} + + return resource.TestStep{ + ResourceName: "google_compute_instance.foobar", + ImportState: true, + ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), zone, instanceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: append(ignores, additionalImportIgnores...), + } +} + func TestAccComputeInstance_basic1(t *testing.T) { t.Parallel() @@ -41,12 +57,7 @@ func TestAccComputeInstance_basic1(t *testing.T) { testAccCheckComputeInstanceHasConfiguredDeletionProtection(&instance, false), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - ImportStateVerifyIgnore: []string{"create_timeout"}, - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}), }, }) } @@ -256,11 +267,7 @@ func TestAccComputeInstance_attachedDisk(t *testing.T) { testAccCheckComputeInstanceDisk(&instance, diskName, false, false), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -285,11 +292,7 @@ func TestAccComputeInstance_attachedDisk_sourceUrl(t *testing.T) { testAccCheckComputeInstanceDisk(&instance, diskName, false, false), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -314,12 +317,7 @@ func TestAccComputeInstance_attachedDisk_modeRo(t *testing.T) { testAccCheckComputeInstanceDisk(&instance, diskName, false, false), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"}, - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -397,11 +395,7 @@ func TestAccComputeInstance_bootDisk_source(t *testing.T) { testAccCheckComputeInstanceBootDisk(&instance, diskName), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -426,11 +420,7 @@ func TestAccComputeInstance_bootDisk_sourceUrl(t *testing.T) { testAccCheckComputeInstanceBootDisk(&instance, diskName), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -478,11 +468,7 @@ func TestAccComputeInstance_scratchDisk(t *testing.T) { testAccCheckComputeInstanceScratchDisk(&instance, []string{"NVME", "SCSI"}), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -571,11 +557,7 @@ func TestAccComputeInstance_stopInstanceToUpdate(t *testing.T) { "google_compute_instance.foobar", &instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"allow_stopping_for_update"}), // Check that updating them works resource.TestStep{ Config: testAccComputeInstance_stopInstanceToUpdate2(instanceName), @@ -584,11 +566,7 @@ func TestAccComputeInstance_stopInstanceToUpdate(t *testing.T) { "google_compute_instance.foobar", &instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"allow_stopping_for_update"}), // Check that removing them works resource.TestStep{ Config: testAccComputeInstance_stopInstanceToUpdate3(instanceName), @@ -597,11 +575,7 @@ func TestAccComputeInstance_stopInstanceToUpdate(t *testing.T) { "google_compute_instance.foobar", &instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"allow_stopping_for_update"}), }, }) } @@ -630,11 +604,7 @@ func TestAccComputeInstance_service_account(t *testing.T) { "https://www.googleapis.com/auth/userinfo.email"), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -657,11 +627,7 @@ func TestAccComputeInstance_scheduling(t *testing.T) { "google_compute_instance.foobar", &instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -685,11 +651,7 @@ func TestAccComputeInstance_subnet_auto(t *testing.T) { testAccCheckComputeInstanceHasSubnet(&instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -713,11 +675,7 @@ func TestAccComputeInstance_subnet_custom(t *testing.T) { testAccCheckComputeInstanceHasSubnet(&instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -838,12 +796,7 @@ func TestAccComputeInstance_forceChangeMachineTypeManually(t *testing.T) { ), ExpectNonEmptyPlan: true, }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - ImportStateVerifyIgnore: []string{"create_timeout"}, - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}), }, }) } @@ -868,11 +821,7 @@ func TestAccComputeInstance_multiNic(t *testing.T) { testAccCheckComputeInstanceHasMultiNic(&instance), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{}), }, }) } @@ -895,11 +844,7 @@ func TestAccComputeInstance_guestAccelerator(t *testing.T) { testAccCheckComputeInstanceHasGuestAccelerator(&instance, "nvidia-tesla-k80", 1), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName), - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}), }, }) @@ -946,11 +891,7 @@ func TestAccComputeInstance_minCpuPlatform(t *testing.T) { testAccCheckComputeInstanceHasMinCpuPlatform(&instance, "Intel Haswell"), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName), - }, + computeInstanceImportStep("us-east1-d", instanceName, []string{}), }, }) } @@ -997,12 +938,7 @@ func TestAccComputeInstance_deletionProtectionExplicitTrueAndUpdateFalse(t *test testAccCheckComputeInstanceHasConfiguredDeletionProtection(&instance, true), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName), - ImportStateVerifyIgnore: []string{"create_timeout"}, - }, + computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.foo"}), // Update deletion_protection to false, otherwise the test harness can't delete the instance resource.TestStep{ Config: testAccComputeInstance_basic_deletionProtectionFalse(instanceName), @@ -1034,11 +970,7 @@ func TestAccComputeInstance_primaryAliasIpRange(t *testing.T) { testAccCheckComputeInstanceHasAliasIpRange(&instance, "", "/24"), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName), - }, + computeInstanceImportStep("us-east1-d", instanceName, []string{}), }, }) } @@ -1063,11 +995,7 @@ func TestAccComputeInstance_secondaryAliasIpRange(t *testing.T) { testAccCheckComputeInstanceHasAliasIpRange(&instance, "inst-test-secondary", "172.16.0.0/24"), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName), - }, + computeInstanceImportStep("us-east1-d", instanceName, []string{}), resource.TestStep{ Config: testAccComputeInstance_secondaryAliasIpRangeUpdate(networkName, subnetName, instanceName), Check: resource.ComposeTestCheckFunc( @@ -1075,11 +1003,7 @@ func TestAccComputeInstance_secondaryAliasIpRange(t *testing.T) { testAccCheckComputeInstanceHasAliasIpRange(&instance, "", "10.0.1.0/24"), ), }, - resource.TestStep{ - ResourceName: "google_compute_instance.foobar", - ImportState: true, - ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName), - }, + computeInstanceImportStep("us-east1-d", instanceName, []string{}), }, }) } @@ -1704,10 +1628,6 @@ resource "google_compute_instance" "foobar" { network_interface { network = "default" } - - metadata { - foo = "bar" - } } `, instance) } @@ -1731,10 +1651,6 @@ resource "google_compute_instance" "foobar" { network_interface { network = "default" } - - metadata { - foo = "bar" - } } `, instance) } diff --git a/google/resource_google_organization_iam_test.go b/google/resource_google_organization_iam_test.go index 2448debfa9f..8b0df19e9d9 100644 --- a/google/resource_google_organization_iam_test.go +++ b/google/resource_google_organization_iam_test.go @@ -35,6 +35,12 @@ func TestAccOrganizationIam(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, getTestProjectFromEnv()), }), }, + { + ResourceName: "google_organization_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s organizations/%s/roles/%s", org, org, roleId), + ImportState: true, + ImportStateVerify: true, + }, { // Test Iam Binding update Config: testAccOrganizationIamBinding_update(account, roleId, org), @@ -43,6 +49,12 @@ func TestAccOrganizationIam(t *testing.T) { fmt.Sprintf("serviceAccount:%s-2@%s.iam.gserviceaccount.com", account, getTestProjectFromEnv()), }), }, + { + ResourceName: "google_organization_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s organizations/%s/roles/%s", org, org, roleId), + ImportState: true, + ImportStateVerify: true, + }, { // Test Iam Member creation (no update for member, no need to test) Config: testAccOrganizationIamMember_basic(account, org), @@ -50,6 +62,12 @@ func TestAccOrganizationIam(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, getTestProjectFromEnv()), ), }, + { + ResourceName: "google_organization_iam_member.foo", + ImportStateId: fmt.Sprintf("%s roles/browser serviceAccount:%s@%s.iam.gserviceaccount.com", org, account, getTestProjectFromEnv()), + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_google_project_iam_binding_test.go b/google/resource_google_project_iam_binding_test.go index 48cc77ce2b9..1bdbf144830 100644 --- a/google/resource_google_project_iam_binding_test.go +++ b/google/resource_google_project_iam_binding_test.go @@ -2,21 +2,28 @@ package google import ( "fmt" - "sort" "testing" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" - "google.golang.org/api/cloudresourcemanager/v1" ) +func projectIamBindingImportStep(resourceName, pid, role string) resource.TestStep { + return resource.TestStep{ + ResourceName: resourceName, + ImportStateId: fmt.Sprintf("%s %s", pid, role), + ImportState: true, + ImportStateVerify: true, + } +} + // Test that an IAM binding can be applied to a project func TestAccProjectIamBinding_basic(t *testing.T) { t.Parallel() org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + role := "roles/compute.instanceAdmin" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -30,14 +37,9 @@ func TestAccProjectIamBinding_basic(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateBindingBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingBasic(pid, pname, org, role), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), }, }) } @@ -48,6 +50,9 @@ func TestAccProjectIamBinding_multiple(t *testing.T) { org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + role := "roles/compute.instanceAdmin" + role2 := "roles/viewer" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -61,28 +66,14 @@ func TestAccProjectIamBinding_multiple(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateBindingBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingBasic(pid, pname, org, role), }, // Apply another IAM binding { - Config: testAccProjectAssociateBindingMultiple(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.multiple", &cloudresourcemanager.Binding{ - Role: "roles/viewer", - Members: []string{"user:paddy@hashicorp.com"}, - }, pid), - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.multiple", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingMultiple(pid, pname, org, role, role2), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), + projectIamBindingImportStep("google_project_iam_binding.multiple", pid, role2), }, }) } @@ -93,6 +84,9 @@ func TestAccProjectIamBinding_multipleAtOnce(t *testing.T) { org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + role := "roles/compute.instanceAdmin" + role2 := "roles/viewer" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -106,18 +100,10 @@ func TestAccProjectIamBinding_multipleAtOnce(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateBindingMultiple(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.multiple", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingMultiple(pid, pname, org, role, role2), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), + projectIamBindingImportStep("google_project_iam_binding.multiple", pid, role2), }, }) } @@ -128,6 +114,8 @@ func TestAccProjectIamBinding_update(t *testing.T) { org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + role := "roles/compute.instanceAdmin" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -141,34 +129,21 @@ func TestAccProjectIamBinding_update(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateBindingBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingBasic(pid, pname, org, role), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), + // Apply an updated IAM binding { - Config: testAccProjectAssociateBindingUpdated(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.updated", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com", "user:paddy@hashicorp.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingUpdated(pid, pname, org, role), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), + // Drop the original member { - Config: testAccProjectAssociateBindingDropMemberFromBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.dropped", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:paddy@hashicorp.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingDropMemberFromBasic(pid, pname, org, role), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), }, }) } @@ -179,6 +154,9 @@ func TestAccProjectIamBinding_remove(t *testing.T) { org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + role := "roles/compute.instanceAdmin" + role2 := "roles/viewer" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -192,18 +170,11 @@ func TestAccProjectIamBinding_remove(t *testing.T) { }, // Apply multiple IAM bindings { - Config: testAccProjectAssociateBindingMultiple(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.multiple", &cloudresourcemanager.Binding{ - Role: "roles/viewer", - Members: []string{"user:paddy@hashicorp.com"}, - }, pid), - testAccCheckGoogleProjectIamBindingExists("google_project_iam_binding.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateBindingMultiple(pid, pname, org, role, role2), }, + projectIamBindingImportStep("google_project_iam_binding.acceptance", pid, role), + projectIamBindingImportStep("google_project_iam_binding.multiple", pid, role2), + // Remove the bindings { Config: testAccProject_create(pid, pname, org), @@ -215,39 +186,7 @@ func TestAccProjectIamBinding_remove(t *testing.T) { }) } -func testAccCheckGoogleProjectIamBindingExists(key string, expected *cloudresourcemanager.Binding, pid string) resource.TestCheckFunc { - return func(s *terraform.State) error { - config := testAccProvider.Meta().(*Config) - projectPolicy, err := getProjectIamPolicy(pid, config) - if err != nil { - return fmt.Errorf("Failed to retrieve IAM policy for project %q: %s", pid, err) - } - - var result *cloudresourcemanager.Binding - for _, binding := range projectPolicy.Bindings { - if binding.Role == expected.Role { - result = binding - break - } - } - if result == nil { - return fmt.Errorf("IAM policy for project %q had no role %q", pid, expected.Role) - } - if len(result.Members) != len(expected.Members) { - return fmt.Errorf("Got %v as members for role %q of project %q, expected %v", result.Members, expected.Role, pid, expected.Members) - } - sort.Strings(result.Members) - sort.Strings(expected.Members) - for pos, exp := range expected.Members { - if result.Members[pos] != exp { - return fmt.Errorf("Expected members for role %q of project %q to be %v, got %v", expected.Role, pid, expected.Members, result.Members) - } - } - return nil - } -} - -func testAccProjectAssociateBindingBasic(pid, name, org string) string { +func testAccProjectAssociateBindingBasic(pid, name, org, role string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -258,12 +197,12 @@ resource "google_project" "acceptance" { resource "google_project_iam_binding" "acceptance" { project = "${google_project.acceptance.project_id}" members = ["user:admin@hashicorptest.com"] - role = "roles/compute.instanceAdmin" + role = "%s" } -`, pid, name, org) +`, pid, name, org, role) } -func testAccProjectAssociateBindingMultiple(pid, name, org string) string { +func testAccProjectAssociateBindingMultiple(pid, name, org, role, role2 string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -274,18 +213,18 @@ resource "google_project" "acceptance" { resource "google_project_iam_binding" "acceptance" { project = "${google_project.acceptance.project_id}" members = ["user:admin@hashicorptest.com"] - role = "roles/compute.instanceAdmin" + role = "%s" } resource "google_project_iam_binding" "multiple" { project = "${google_project.acceptance.project_id}" members = ["user:paddy@hashicorp.com"] - role = "roles/viewer" + role = "%s" } -`, pid, name, org) +`, pid, name, org, role, role2) } -func testAccProjectAssociateBindingUpdated(pid, name, org string) string { +func testAccProjectAssociateBindingUpdated(pid, name, org, role string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -296,12 +235,12 @@ resource "google_project" "acceptance" { resource "google_project_iam_binding" "acceptance" { project = "${google_project.acceptance.project_id}" members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"] - role = "roles/compute.instanceAdmin" + role = "%s" } -`, pid, name, org) +`, pid, name, org, role) } -func testAccProjectAssociateBindingDropMemberFromBasic(pid, name, org string) string { +func testAccProjectAssociateBindingDropMemberFromBasic(pid, name, org, role string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -309,10 +248,10 @@ resource "google_project" "acceptance" { org_id = "%s" } -resource "google_project_iam_binding" "dropped" { +resource "google_project_iam_binding" "acceptance" { project = "${google_project.acceptance.project_id}" members = ["user:paddy@hashicorp.com"] - role = "roles/compute.instanceAdmin" + role = "%s" } -`, pid, name, org) +`, pid, name, org, role) } diff --git a/google/resource_google_project_iam_member_test.go b/google/resource_google_project_iam_member_test.go index cde0fdece35..df280216ad2 100644 --- a/google/resource_google_project_iam_member_test.go +++ b/google/resource_google_project_iam_member_test.go @@ -6,15 +6,26 @@ import ( "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" - "google.golang.org/api/cloudresourcemanager/v1" ) +func projectIamMemberImportStep(resourceName, pid, role, member string) resource.TestStep { + return resource.TestStep{ + ResourceName: resourceName, + ImportStateId: fmt.Sprintf("%s %s %s", pid, role, member), + ImportState: true, + ImportStateVerify: true, + } +} + // Test that an IAM binding can be applied to a project func TestAccProjectIamMember_basic(t *testing.T) { t.Parallel() org := getTestOrgFromEnv(t) pid := "terraform-" + acctest.RandString(10) + resourceName := "google_project_iam_member.acceptance" + role := "roles/compute.instanceAdmin" + member := "user:admin@hashicorptest.com" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -28,14 +39,9 @@ func TestAccProjectIamMember_basic(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateMemberBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_member.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateMemberBasic(pid, pname, org, role, member), }, + projectIamMemberImportStep(resourceName, pid, role, member), }, }) } @@ -48,6 +54,12 @@ func TestAccProjectIamMember_multiple(t *testing.T) { skipIfEnvNotSet(t, "GOOGLE_ORG") pid := "terraform-" + acctest.RandString(10) + resourceName := "google_project_iam_member.acceptance" + resourceName2 := "google_project_iam_member.multiple" + role := "roles/compute.instanceAdmin" + member := "user:admin@hashicorptest.com" + member2 := "user:paddy@hashicorp.com" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -61,24 +73,16 @@ func TestAccProjectIamMember_multiple(t *testing.T) { }, // Apply an IAM binding { - Config: testAccProjectAssociateMemberBasic(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_member.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com"}, - }, pid), - ), + Config: testAccProjectAssociateMemberBasic(pid, pname, org, role, member), }, + projectIamMemberImportStep(resourceName, pid, role, member), + // Apply another IAM binding { - Config: testAccProjectAssociateMemberMultiple(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_member.multiple", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com", "user:paddy@hashicorp.com"}, - }, pid), - ), + Config: testAccProjectAssociateMemberMultiple(pid, pname, org, role, member, role, member2), }, + projectIamMemberImportStep(resourceName, pid, role, member), + projectIamMemberImportStep(resourceName2, pid, role, member2), }, }) } @@ -91,6 +95,11 @@ func TestAccProjectIamMember_remove(t *testing.T) { skipIfEnvNotSet(t, "GOOGLE_ORG") pid := "terraform-" + acctest.RandString(10) + resourceName := "google_project_iam_member.acceptance" + role := "roles/compute.instanceAdmin" + member := "user:admin@hashicorptest.com" + member2 := "user:paddy@hashicorp.com" + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -102,16 +111,14 @@ func TestAccProjectIamMember_remove(t *testing.T) { testAccProjectExistingPolicy(pid), ), }, + // Apply multiple IAM bindings { - Config: testAccProjectAssociateMemberMultiple(pid, pname, org), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleProjectIamBindingExists("google_project_iam_member.acceptance", &cloudresourcemanager.Binding{ - Role: "roles/compute.instanceAdmin", - Members: []string{"user:admin@hashicorptest.com", "user:paddy@hashicorp.com"}, - }, pid), - ), + Config: testAccProjectAssociateMemberMultiple(pid, pname, org, role, member, role, member2), }, + projectIamMemberImportStep(resourceName, pid, role, member), + projectIamMemberImportStep(resourceName, pid, role, member2), + // Remove the bindings { Config: testAccProject_create(pid, pname, org), @@ -123,7 +130,7 @@ func TestAccProjectIamMember_remove(t *testing.T) { }) } -func testAccProjectAssociateMemberBasic(pid, name, org string) string { +func testAccProjectAssociateMemberBasic(pid, name, org, role, member string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -133,13 +140,13 @@ resource "google_project" "acceptance" { resource "google_project_iam_member" "acceptance" { project = "${google_project.acceptance.project_id}" - member = "user:admin@hashicorptest.com" - role = "roles/compute.instanceAdmin" + role = "%s" + member = "%s" } -`, pid, name, org) +`, pid, name, org, role, member) } -func testAccProjectAssociateMemberMultiple(pid, name, org string) string { +func testAccProjectAssociateMemberMultiple(pid, name, org, role, member, role2, member2 string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" @@ -149,14 +156,14 @@ resource "google_project" "acceptance" { resource "google_project_iam_member" "acceptance" { project = "${google_project.acceptance.project_id}" - member = "user:admin@hashicorptest.com" - role = "roles/compute.instanceAdmin" + role = "%s" + member = "%s" } resource "google_project_iam_member" "multiple" { project = "${google_project.acceptance.project_id}" - member = "user:paddy@hashicorp.com" - role = "roles/compute.instanceAdmin" + role = "%s" + member = "%s" } -`, pid, name, org) +`, pid, name, org, role, member, role2, member2) } diff --git a/google/resource_kms_crypto_key_iam_test.go b/google/resource_kms_crypto_key_iam_test.go index b94513261df..eb204512fa7 100644 --- a/google/resource_kms_crypto_key_iam_test.go +++ b/google/resource_kms_crypto_key_iam_test.go @@ -20,6 +20,11 @@ func TestAccKmsCryptoKeyIamBinding(t *testing.T) { account := acctest.RandomWithPrefix("tf-test") roleId := "roles/cloudkms.cryptoKeyDecrypter" keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + keyRingId := &kmsKeyRingId{ + Project: projectId, + Location: DEFAULT_KMS_TEST_LOCATION, + Name: keyRingName, + } cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -33,6 +38,12 @@ func TestAccKmsCryptoKeyIamBinding(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_crypto_key_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s/%s %s", keyRingId.terraformId(), cryptoKeyName, roleId), + ImportState: true, + ImportStateVerify: true, + }, { // Test Iam Binding update Config: testAccKmsCryptoKeyIamBinding_update(projectId, orgId, billingAccount, account, keyRingName, cryptoKeyName, roleId), @@ -41,6 +52,12 @@ func TestAccKmsCryptoKeyIamBinding(t *testing.T) { fmt.Sprintf("serviceAccount:%s-2@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_crypto_key_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s/%s %s", keyRingId.terraformId(), cryptoKeyName, roleId), + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -54,6 +71,11 @@ func TestAccKmsCryptoKeyIamMember(t *testing.T) { account := acctest.RandomWithPrefix("tf-test") roleId := "roles/cloudkms.cryptoKeyEncrypter" keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + keyRingId := &kmsKeyRingId{ + Project: projectId, + Location: DEFAULT_KMS_TEST_LOCATION, + Name: keyRingName, + } cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -67,6 +89,12 @@ func TestAccKmsCryptoKeyIamMember(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, projectId), ), }, + { + ResourceName: "google_kms_crypto_key_iam_member.foo", + ImportStateId: fmt.Sprintf("%s/%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), cryptoKeyName, roleId, account, projectId), + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_kms_key_ring_iam_test.go b/google/resource_kms_key_ring_iam_test.go index e362e61ecc3..1ea0252ddb7 100644 --- a/google/resource_kms_key_ring_iam_test.go +++ b/google/resource_kms_key_ring_iam_test.go @@ -40,6 +40,12 @@ func TestAccKmsKeyRingIamBinding(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_key_ring_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s %s", keyRingId.terraformId(), roleId), + ImportState: true, + ImportStateVerify: true, + }, { // Test Iam Binding update Config: testAccKmsKeyRingIamBinding_update(projectId, orgId, billingAccount, account, keyRingName, roleId), @@ -48,6 +54,12 @@ func TestAccKmsKeyRingIamBinding(t *testing.T) { fmt.Sprintf("serviceAccount:%s-2@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_key_ring_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s %s", keyRingId.terraformId(), roleId), + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -79,6 +91,12 @@ func TestAccKmsKeyRingIamMember(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_key_ring_iam_member.foo", + ImportStateId: fmt.Sprintf("%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), roleId, account, projectId), + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -109,6 +127,12 @@ func TestAccKmsKeyRingIamPolicy(t *testing.T) { fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", account, projectId), }), }, + { + ResourceName: "google_kms_key_ring_iam_policy.foo", + ImportStateId: keyRingId.terraformId(), + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_pubsub_subscription_iam_test.go b/google/resource_pubsub_subscription_iam_test.go index ed864593603..239bad8d0c3 100644 --- a/google/resource_pubsub_subscription_iam_test.go +++ b/google/resource_pubsub_subscription_iam_test.go @@ -2,12 +2,13 @@ package google import ( "fmt" - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" "reflect" "sort" "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" ) func TestAccPubsubSubscriptionIamBinding(t *testing.T) { @@ -37,9 +38,10 @@ func TestAccPubsubSubscriptionIamBinding(t *testing.T) { }), }, { - ResourceName: "google_pubsub_subscription_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s roles/pubsub.subscriber", getComputedSubscriptionName(getTestProjectFromEnv(), subscription)), - ImportState: true, + ResourceName: "google_pubsub_subscription_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s roles/pubsub.subscriber", getComputedSubscriptionName(getTestProjectFromEnv(), subscription)), + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -65,9 +67,10 @@ func TestAccPubsubSubscriptionIamMember(t *testing.T) { }), }, { - ResourceName: "google_pubsub_subscription_iam_member.foo", - ImportStateId: fmt.Sprintf("%s roles/pubsub.subscriber serviceAccount:%s", getComputedSubscriptionName(getTestProjectFromEnv(), subscription), accountEmail), - ImportState: true, + ResourceName: "google_pubsub_subscription_iam_member.foo", + ImportStateId: fmt.Sprintf("%s roles/pubsub.subscriber serviceAccount:%s", getComputedSubscriptionName(getTestProjectFromEnv(), subscription), accountEmail), + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -97,9 +100,10 @@ func TestAccPubsubSubscriptionIamPolicy(t *testing.T) { }), }, { - ResourceName: "google_pubsub_subscription_iam_policy.foo", - ImportStateId: getComputedSubscriptionName(getTestProjectFromEnv(), subscription), - ImportState: true, + ResourceName: "google_pubsub_subscription_iam_policy.foo", + ImportStateId: getComputedSubscriptionName(getTestProjectFromEnv(), subscription), + ImportState: true, + ImportStateVerify: true, }, }, }) diff --git a/google/resource_pubsub_topic_iam_test.go b/google/resource_pubsub_topic_iam_test.go index c8a68701235..50143681e96 100644 --- a/google/resource_pubsub_topic_iam_test.go +++ b/google/resource_pubsub_topic_iam_test.go @@ -2,12 +2,13 @@ package google import ( "fmt" - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" "reflect" "sort" "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" ) func TestAccPubsubTopicIamBinding(t *testing.T) { @@ -36,9 +37,10 @@ func TestAccPubsubTopicIamBinding(t *testing.T) { }), }, { - ResourceName: "google_pubsub_topic_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s roles/pubsub.publisher", getComputedTopicName(getTestProjectFromEnv(), topic)), - ImportState: true, + ResourceName: "google_pubsub_topic_iam_binding.foo", + ImportStateId: fmt.Sprintf("%s roles/pubsub.publisher", getComputedTopicName(getTestProjectFromEnv(), topic)), + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -63,9 +65,10 @@ func TestAccPubsubTopicIamMember(t *testing.T) { }), }, { - ResourceName: "google_pubsub_topic_iam_member.foo", - ImportStateId: fmt.Sprintf("%s roles/pubsub.publisher serviceAccount:%s", getComputedTopicName(getTestProjectFromEnv(), topic), accountEmail), - ImportState: true, + ResourceName: "google_pubsub_topic_iam_member.foo", + ImportStateId: fmt.Sprintf("%s roles/pubsub.publisher serviceAccount:%s", getComputedTopicName(getTestProjectFromEnv(), topic), accountEmail), + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -94,9 +97,10 @@ func TestAccPubsubTopicIamPolicy(t *testing.T) { }), }, { - ResourceName: "google_pubsub_topic_iam_policy.foo", - ImportStateId: getComputedTopicName(getTestProjectFromEnv(), topic), - ImportState: true, + ResourceName: "google_pubsub_topic_iam_policy.foo", + ImportStateId: getComputedTopicName(getTestProjectFromEnv(), topic), + ImportState: true, + ImportStateVerify: true, }, }, })