diff --git a/google/acctest/resource_test_utils.go b/google/acctest/resource_test_utils.go index cdaf439ab5d..0378c9c637d 100644 --- a/google/acctest/resource_test_utils.go +++ b/google/acctest/resource_test_utils.go @@ -127,6 +127,21 @@ func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc } } +// ConditionTitleIfPresent returns empty string if condition is not preset and " {condition.0.title}" if it is. +func BuildIAMImportId(name, role, member, condition string) string { + ret := name + if role != "" { + ret += " " + role + } + if member != "" { + ret += " " + member + } + if condition != "" { + ret += " " + condition + } + return ret +} + // testStringValue returns string values from string pointers, handling nil pointers. func testStringValue(sPtr *string) string { if sPtr == nil { diff --git a/google/services/apigee/iam_apigee_environment_generated_test.go b/google/services/apigee/iam_apigee_environment_generated_test.go index 35764531c37..1c6b1fd14a9 100644 --- a/google/services/apigee/iam_apigee_environment_generated_test.go +++ b/google/services/apigee/iam_apigee_environment_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccApigeeEnvironmentIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_apigee_environment_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/environments/%s roles/viewer", fmt.Sprintf("organizations/tf-test%s", context["random_suffix"]), fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateApigeeEnvironmentIAMBindingStateID("google_apigee_environment_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccApigeeEnvironmentIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_apigee_environment_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/environments/%s roles/viewer", fmt.Sprintf("organizations/tf-test%s", context["random_suffix"]), fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateApigeeEnvironmentIAMBindingStateID("google_apigee_environment_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccApigeeEnvironmentIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_apigee_environment_iam_member.foo", - ImportStateId: fmt.Sprintf("%s/environments/%s roles/viewer user:admin@hashicorptest.com", fmt.Sprintf("organizations/tf-test%s", context["random_suffix"]), fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateApigeeEnvironmentIAMMemberStateID("google_apigee_environment_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccApigeeEnvironmentIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_apigee_environment_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/environments/%s", fmt.Sprintf("organizations/tf-test%s", context["random_suffix"]), fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateApigeeEnvironmentIAMPolicyStateID("google_apigee_environment_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccApigeeEnvironmentIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_apigee_environment_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/environments/%s", fmt.Sprintf("organizations/tf-test%s", context["random_suffix"]), fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateApigeeEnvironmentIAMPolicyStateID("google_apigee_environment_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -599,3 +600,54 @@ resource "google_apigee_environment_iam_binding" "foo" { } `, context) } + +func generateApigeeEnvironmentIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + org_id := rawState["org_id"] + env_id := tpgresource.GetResourceNameFromSelfLink(rawState["env_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/environments/%s", org_id, env_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateApigeeEnvironmentIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + org_id := rawState["org_id"] + env_id := tpgresource.GetResourceNameFromSelfLink(rawState["env_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/environments/%s", org_id, env_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateApigeeEnvironmentIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + org_id := rawState["org_id"] + env_id := tpgresource.GetResourceNameFromSelfLink(rawState["env_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/environments/%s", org_id, env_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/artifactregistry/iam_artifact_registry_repository_generated_test.go b/google/services/artifactregistry/iam_artifact_registry_repository_generated_test.go index bdb141022fa..1f5406dbce3 100644 --- a/google/services/artifactregistry/iam_artifact_registry_repository_generated_test.go +++ b/google/services/artifactregistry/iam_artifact_registry_repository_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccArtifactRegistryRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_artifact_registry_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/artifactregistry.reader", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateArtifactRegistryRepositoryIAMBindingStateID("google_artifact_registry_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccArtifactRegistryRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_artifact_registry_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/artifactregistry.reader", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateArtifactRegistryRepositoryIAMBindingStateID("google_artifact_registry_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccArtifactRegistryRepositoryIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_artifact_registry_repository_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/artifactregistry.reader user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateArtifactRegistryRepositoryIAMMemberStateID("google_artifact_registry_repository_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccArtifactRegistryRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_artifact_registry_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateArtifactRegistryRepositoryIAMPolicyStateID("google_artifact_registry_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccArtifactRegistryRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_artifact_registry_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateArtifactRegistryRepositoryIAMPolicyStateID("google_artifact_registry_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -245,3 +246,57 @@ resource "google_artifact_registry_repository_iam_binding" "foo" { } `, context) } + +func generateArtifactRegistryRepositoryIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository := tpgresource.GetResourceNameFromSelfLink(rawState["repository"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository), "", "", rawState["condition.0.title"]), nil + } +} + +func generateArtifactRegistryRepositoryIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository := tpgresource.GetResourceNameFromSelfLink(rawState["repository"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateArtifactRegistryRepositoryIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository := tpgresource.GetResourceNameFromSelfLink(rawState["repository"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/beyondcorp/iam_beyondcorp_security_gateway_application_generated_test.go b/google/services/beyondcorp/iam_beyondcorp_security_gateway_application_generated_test.go index 36242478e01..805e5e020de 100644 --- a/google/services/beyondcorp/iam_beyondcorp_security_gateway_application_generated_test.go +++ b/google/services/beyondcorp/iam_beyondcorp_security_gateway_application_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamBindingGenerated(t *testing.T }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamBindingGenerated(t *testing.T }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamMemberGenerated(t *testing.T) }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID("google_beyondcorp_security_gateway_application_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamPolicyGenerated(t *testing.T) }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMPolicyStateID("google_beyondcorp_security_gateway_application_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamPolicyGenerated(t *testing.T) }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMPolicyStateID("google_beyondcorp_security_gateway_application_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamBindingGenerated_withConditio }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamBindingGenerated_withAndWitho }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID("google_beyondcorp_security_gateway_application_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamMemberGenerated_withCondition }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID("google_beyondcorp_security_gateway_application_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamMemberGenerated_withAndWithou }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID("google_beyondcorp_security_gateway_application_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID("google_beyondcorp_security_gateway_application_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID("google_beyondcorp_security_gateway_application_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccBeyondcorpSecurityGatewayApplicationIamPolicyGenerated_withCondition }, { ResourceName: "google_beyondcorp_security_gateway_application_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-default-sg%s", context["random_suffix"]), fmt.Sprintf("tf-test-google-sga%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayApplicationIAMPolicyStateID("google_beyondcorp_security_gateway_application_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -708,3 +709,56 @@ resource "google_beyondcorp_security_gateway_application_iam_policy" "foo" { } `, context) } +func generateBeyondcorpSecurityGatewayApplicationIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + application_id := tpgresource.GetResourceNameFromSelfLink(rawState["application_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", project, security_gateway_id, application_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBeyondcorpSecurityGatewayApplicationIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + application_id := tpgresource.GetResourceNameFromSelfLink(rawState["application_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", project, security_gateway_id, application_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBeyondcorpSecurityGatewayApplicationIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + application_id := tpgresource.GetResourceNameFromSelfLink(rawState["application_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", project, security_gateway_id, application_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/beyondcorp/iam_beyondcorp_security_gateway_generated_test.go b/google/services/beyondcorp/iam_beyondcorp_security_gateway_generated_test.go index 6f2a9be9169..f62d076c03b 100644 --- a/google/services/beyondcorp/iam_beyondcorp_security_gateway_generated_test.go +++ b/google/services/beyondcorp/iam_beyondcorp_security_gateway_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccBeyondcorpSecurityGatewayIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccBeyondcorpSecurityGatewayIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccBeyondcorpSecurityGatewayIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_beyondcorp_security_gateway_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMMemberStateID("google_beyondcorp_security_gateway_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccBeyondcorpSecurityGatewayIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_beyondcorp_security_gateway_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMPolicyStateID("google_beyondcorp_security_gateway_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccBeyondcorpSecurityGatewayIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_beyondcorp_security_gateway_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMPolicyStateID("google_beyondcorp_security_gateway_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccBeyondcorpSecurityGatewayIamBindingGenerated_withCondition(t *testin }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccBeyondcorpSecurityGatewayIamBindingGenerated_withAndWithoutCondition }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMBindingStateID("google_beyondcorp_security_gateway_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccBeyondcorpSecurityGatewayIamMemberGenerated_withCondition(t *testing }, { ResourceName: "google_beyondcorp_security_gateway_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMMemberStateID("google_beyondcorp_security_gateway_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccBeyondcorpSecurityGatewayIamMemberGenerated_withAndWithoutCondition( }, { ResourceName: "google_beyondcorp_security_gateway_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMMemberStateID("google_beyondcorp_security_gateway_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMMemberStateID("google_beyondcorp_security_gateway_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_beyondcorp_security_gateway_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s roles/beyondcorp.securityGatewayUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMMemberStateID("google_beyondcorp_security_gateway_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccBeyondcorpSecurityGatewayIamPolicyGenerated_withCondition(t *testing }, { ResourceName: "google_beyondcorp_security_gateway_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", envvar.GetTestProjectFromEnv(), "global", fmt.Sprintf("default%s", context["random_suffix"])), + ImportStateIdFunc: generateBeyondcorpSecurityGatewayIAMPolicyStateID("google_beyondcorp_security_gateway_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -618,3 +619,56 @@ resource "google_beyondcorp_security_gateway_iam_policy" "foo" { } `, context) } +func generateBeyondcorpSecurityGatewayIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", project, location, security_gateway_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBeyondcorpSecurityGatewayIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", project, location, security_gateway_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBeyondcorpSecurityGatewayIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + security_gateway_id := tpgresource.GetResourceNameFromSelfLink(rawState["security_gateway_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/securityGateways/%s", project, location, security_gateway_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigquery/iam_bigquery_table_generated_test.go b/google/services/bigquery/iam_bigquery_table_generated_test.go index 737a0269d5b..ac09236099f 100644 --- a/google/services/bigquery/iam_bigquery_table_generated_test.go +++ b/google/services/bigquery/iam_bigquery_table_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBigQueryTableIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_table_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/datasets/%s/tables/%s roles/bigquery.dataOwner", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf_test_dataset_id%s", context["random_suffix"]), fmt.Sprintf("tf_test_table_id%s", context["random_suffix"])), + ImportStateIdFunc: generateBigQueryTableIAMBindingStateID("google_bigquery_table_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBigQueryTableIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_table_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/datasets/%s/tables/%s roles/bigquery.dataOwner", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf_test_dataset_id%s", context["random_suffix"]), fmt.Sprintf("tf_test_table_id%s", context["random_suffix"])), + ImportStateIdFunc: generateBigQueryTableIAMBindingStateID("google_bigquery_table_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBigQueryTableIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_table_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/datasets/%s/tables/%s roles/bigquery.dataOwner user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf_test_dataset_id%s", context["random_suffix"]), fmt.Sprintf("tf_test_table_id%s", context["random_suffix"])), + ImportStateIdFunc: generateBigQueryTableIAMMemberStateID("google_bigquery_table_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBigQueryTableIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_table_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/datasets/%s/tables/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf_test_dataset_id%s", context["random_suffix"]), fmt.Sprintf("tf_test_table_id%s", context["random_suffix"])), + ImportStateIdFunc: generateBigQueryTableIAMPolicyStateID("google_bigquery_table_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBigQueryTableIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_table_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/datasets/%s/tables/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf_test_dataset_id%s", context["random_suffix"]), fmt.Sprintf("tf_test_table_id%s", context["random_suffix"])), + ImportStateIdFunc: generateBigQueryTableIAMPolicyStateID("google_bigquery_table_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -485,3 +486,57 @@ resource "google_bigquery_table_iam_binding" "foo" { } `, context) } + +func generateBigQueryTableIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + dataset_id := tpgresource.GetResourceNameFromSelfLink(rawState["dataset_id"]) + table_id := tpgresource.GetResourceNameFromSelfLink(rawState["table_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/datasets/%s/tables/%s", project, dataset_id, table_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigQueryTableIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + dataset_id := tpgresource.GetResourceNameFromSelfLink(rawState["dataset_id"]) + table_id := tpgresource.GetResourceNameFromSelfLink(rawState["table_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/datasets/%s/tables/%s", project, dataset_id, table_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigQueryTableIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + dataset_id := tpgresource.GetResourceNameFromSelfLink(rawState["dataset_id"]) + table_id := tpgresource.GetResourceNameFromSelfLink(rawState["table_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/datasets/%s/tables/%s", project, dataset_id, table_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_data_exchange_generated_test.go b/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_data_exchange_generated_test.go index 9b87218580d..c2f7d690dc7 100644 --- a/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_data_exchange_generated_test.go +++ b/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_data_exchange_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubDataExchangeIAMBindingStateID("google_bigquery_analytics_hub_data_exchange_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubDataExchangeIAMBindingStateID("google_bigquery_analytics_hub_data_exchange_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubDataExchangeIAMMemberStateID("google_bigquery_analytics_hub_data_exchange_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubDataExchangeIAMPolicyStateID("google_bigquery_analytics_hub_data_exchange_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubDataExchangeIAMPolicyStateID("google_bigquery_analytics_hub_data_exchange_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -245,3 +246,57 @@ resource "google_bigquery_analytics_hub_data_exchange_iam_binding" "foo" { } `, context) } + +func generateBigqueryAnalyticsHubDataExchangeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", project, location, data_exchange_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryAnalyticsHubDataExchangeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", project, location, data_exchange_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryAnalyticsHubDataExchangeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", project, location, data_exchange_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_listing_generated_test.go b/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_listing_generated_test.go index 6c5f0e1b69f..887a5a335ac 100644 --- a/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_listing_generated_test.go +++ b/google/services/bigqueryanalyticshub/iam_bigquery_analytics_hub_listing_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBigqueryAnalyticsHubListingIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_listing_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubListingIAMBindingStateID("google_bigquery_analytics_hub_listing_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBigqueryAnalyticsHubListingIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_listing_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubListingIAMBindingStateID("google_bigquery_analytics_hub_listing_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBigqueryAnalyticsHubListingIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_listing_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubListingIAMMemberStateID("google_bigquery_analytics_hub_listing_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBigqueryAnalyticsHubListingIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_listing_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubListingIAMPolicyStateID("google_bigquery_analytics_hub_listing_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBigqueryAnalyticsHubListingIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_analytics_hub_listing_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryAnalyticsHubListingIAMPolicyStateID("google_bigquery_analytics_hub_listing_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -346,3 +347,60 @@ resource "google_bigquery_analytics_hub_listing_iam_binding" "foo" { } `, context) } + +func generateBigqueryAnalyticsHubListingIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + listing_id := tpgresource.GetResourceNameFromSelfLink(rawState["listing_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", project, location, data_exchange_id, listing_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryAnalyticsHubListingIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + listing_id := tpgresource.GetResourceNameFromSelfLink(rawState["listing_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", project, location, data_exchange_id, listing_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryAnalyticsHubListingIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_exchange_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_exchange_id"]) + listing_id := tpgresource.GetResourceNameFromSelfLink(rawState["listing_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", project, location, data_exchange_id, listing_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigqueryconnection/iam_bigquery_connection_generated_test.go b/google/services/bigqueryconnection/iam_bigquery_connection_generated_test.go index a6c3cd18f13..fce8b3773f0 100644 --- a/google/services/bigqueryconnection/iam_bigquery_connection_generated_test.go +++ b/google/services/bigqueryconnection/iam_bigquery_connection_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -59,7 +60,7 @@ func TestAccBigqueryConnectionConnectionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_connection_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/connections/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf-test-my-connection%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryConnectionConnectionIAMBindingStateID("google_bigquery_connection_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -69,7 +70,7 @@ func TestAccBigqueryConnectionConnectionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_connection_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/connections/%s roles/viewer", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf-test-my-connection%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryConnectionConnectionIAMBindingStateID("google_bigquery_connection_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -99,7 +100,7 @@ func TestAccBigqueryConnectionConnectionIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_connection_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/connections/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf-test-my-connection%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryConnectionConnectionIAMMemberStateID("google_bigquery_connection_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccBigqueryConnectionConnectionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_connection_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/connections/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf-test-my-connection%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryConnectionConnectionIAMPolicyStateID("google_bigquery_connection_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -138,7 +139,7 @@ func TestAccBigqueryConnectionConnectionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_connection_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/connections/%s", envvar.GetTestProjectFromEnv(), "US", fmt.Sprintf("tf-test-my-connection%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryConnectionConnectionIAMPolicyStateID("google_bigquery_connection_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -262,3 +263,57 @@ resource "google_bigquery_connection_iam_binding" "foo" { } `, context) } + +func generateBigqueryConnectionConnectionIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + connection_id := tpgresource.GetResourceNameFromSelfLink(rawState["connection_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, connection_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryConnectionConnectionIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + connection_id := tpgresource.GetResourceNameFromSelfLink(rawState["connection_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, connection_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryConnectionConnectionIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + connection_id := tpgresource.GetResourceNameFromSelfLink(rawState["connection_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, connection_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigquerydatapolicy/iam_bigquery_datapolicy_data_policy_generated_test.go b/google/services/bigquerydatapolicy/iam_bigquery_datapolicy_data_policy_generated_test.go index 9eb7cf8443e..e6f16b453e7 100644 --- a/google/services/bigquerydatapolicy/iam_bigquery_datapolicy_data_policy_generated_test.go +++ b/google/services/bigquerydatapolicy/iam_bigquery_datapolicy_data_policy_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicy_data_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyDataPolicyIAMBindingStateID("google_bigquery_datapolicy_data_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicy_data_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyDataPolicyIAMBindingStateID("google_bigquery_datapolicy_data_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicy_data_policy_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyDataPolicyIAMMemberStateID("google_bigquery_datapolicy_data_policy_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicy_data_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyDataPolicyIAMPolicyStateID("google_bigquery_datapolicy_data_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicy_data_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyDataPolicyIAMPolicyStateID("google_bigquery_datapolicy_data_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -310,3 +311,57 @@ resource "google_bigquery_datapolicy_data_policy_iam_binding" "foo" { } `, context) } + +func generateBigqueryDatapolicyDataPolicyIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryDatapolicyDataPolicyIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryDatapolicyDataPolicyIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/bigquerydatapolicyv2/iam_bigquery_datapolicyv2_data_policy_generated_test.go b/google/services/bigquerydatapolicyv2/iam_bigquery_datapolicyv2_data_policy_generated_test.go index 955af91a258..2a39bc1e2ad 100644 --- a/google/services/bigquerydatapolicyv2/iam_bigquery_datapolicyv2_data_policy_generated_test.go +++ b/google/services/bigquerydatapolicyv2/iam_bigquery_datapolicyv2_data_policy_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBigqueryDatapolicyv2DataPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicyv2_data_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_basic_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyv2DataPolicyIAMBindingStateID("google_bigquery_datapolicyv2_data_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBigqueryDatapolicyv2DataPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicyv2_data_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_basic_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyv2DataPolicyIAMBindingStateID("google_bigquery_datapolicyv2_data_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBigqueryDatapolicyv2DataPolicyIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicyv2_data_policy_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_basic_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyv2DataPolicyIAMMemberStateID("google_bigquery_datapolicyv2_data_policy_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBigqueryDatapolicyv2DataPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicyv2_data_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_basic_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyv2DataPolicyIAMPolicyStateID("google_bigquery_datapolicyv2_data_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBigqueryDatapolicyv2DataPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_bigquery_datapolicyv2_data_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_basic_data_policy%s", context["random_suffix"])), + ImportStateIdFunc: generateBigqueryDatapolicyv2DataPolicyIAMPolicyStateID("google_bigquery_datapolicyv2_data_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -240,3 +241,57 @@ resource "google_bigquery_datapolicyv2_data_policy_iam_binding" "foo" { } `, context) } + +func generateBigqueryDatapolicyv2DataPolicyIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryDatapolicyv2DataPolicyIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBigqueryDatapolicyv2DataPolicyIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataPolicies/%s", project, location, data_policy_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/binaryauthorization/iam_binary_authorization_attestor_generated_test.go b/google/services/binaryauthorization/iam_binary_authorization_attestor_generated_test.go index c7caa4d4684..98facfc1d77 100644 --- a/google/services/binaryauthorization/iam_binary_authorization_attestor_generated_test.go +++ b/google/services/binaryauthorization/iam_binary_authorization_attestor_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccBinaryAuthorizationAttestorIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_binary_authorization_attestor_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/attestors/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-test-attestor%s", context["random_suffix"])), + ImportStateIdFunc: generateBinaryAuthorizationAttestorIAMBindingStateID("google_binary_authorization_attestor_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccBinaryAuthorizationAttestorIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_binary_authorization_attestor_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/attestors/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-test-attestor%s", context["random_suffix"])), + ImportStateIdFunc: generateBinaryAuthorizationAttestorIAMBindingStateID("google_binary_authorization_attestor_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccBinaryAuthorizationAttestorIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_binary_authorization_attestor_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/attestors/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-test-attestor%s", context["random_suffix"])), + ImportStateIdFunc: generateBinaryAuthorizationAttestorIAMMemberStateID("google_binary_authorization_attestor_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccBinaryAuthorizationAttestorIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_binary_authorization_attestor_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/attestors/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-test-attestor%s", context["random_suffix"])), + ImportStateIdFunc: generateBinaryAuthorizationAttestorIAMPolicyStateID("google_binary_authorization_attestor_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccBinaryAuthorizationAttestorIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_binary_authorization_attestor_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/attestors/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-test-attestor%s", context["random_suffix"])), + ImportStateIdFunc: generateBinaryAuthorizationAttestorIAMPolicyStateID("google_binary_authorization_attestor_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -384,3 +385,54 @@ resource "google_binary_authorization_attestor_iam_binding" "foo" { } `, context) } + +func generateBinaryAuthorizationAttestorIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + attestor := tpgresource.GetResourceNameFromSelfLink(rawState["attestor"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/attestors/%s", project, attestor), "", "", rawState["condition.0.title"]), nil + } +} + +func generateBinaryAuthorizationAttestorIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + attestor := tpgresource.GetResourceNameFromSelfLink(rawState["attestor"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/attestors/%s", project, attestor), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateBinaryAuthorizationAttestorIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + attestor := tpgresource.GetResourceNameFromSelfLink(rawState["attestor"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/attestors/%s", project, attestor), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudbuildv2/iam_cloudbuildv2_connection_generated_test.go b/google/services/cloudbuildv2/iam_cloudbuildv2_connection_generated_test.go index 1734ccd8ea1..f1804dd58f3 100644 --- a/google/services/cloudbuildv2/iam_cloudbuildv2_connection_generated_test.go +++ b/google/services/cloudbuildv2/iam_cloudbuildv2_connection_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -245,3 +246,57 @@ resource "google_cloudbuildv2_connection_iam_binding" "foo" { } `, context) } + +func generateCloudbuildv2ConnectionIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudbuildv2ConnectionIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudbuildv2ConnectionIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/connections/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/clouddeploy/iam_clouddeploy_custom_target_type_generated_test.go b/google/services/clouddeploy/iam_clouddeploy_custom_target_type_generated_test.go index bc596af3be6..0d14733ca58 100644 --- a/google/services/clouddeploy/iam_clouddeploy_custom_target_type_generated_test.go +++ b/google/services/clouddeploy/iam_clouddeploy_custom_target_type_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccClouddeployCustomTargetTypeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_custom_target_type_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-custom-target-type%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployCustomTargetTypeIAMBindingStateID("google_clouddeploy_custom_target_type_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccClouddeployCustomTargetTypeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_custom_target_type_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-custom-target-type%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployCustomTargetTypeIAMBindingStateID("google_clouddeploy_custom_target_type_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccClouddeployCustomTargetTypeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_custom_target_type_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-custom-target-type%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployCustomTargetTypeIAMMemberStateID("google_clouddeploy_custom_target_type_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccClouddeployCustomTargetTypeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_custom_target_type_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-custom-target-type%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployCustomTargetTypeIAMPolicyStateID("google_clouddeploy_custom_target_type_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccClouddeployCustomTargetTypeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_custom_target_type_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-custom-target-type%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployCustomTargetTypeIAMPolicyStateID("google_clouddeploy_custom_target_type_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -300,3 +301,57 @@ resource "google_clouddeploy_custom_target_type_iam_binding" "foo" { } `, context) } + +func generateClouddeployCustomTargetTypeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployCustomTargetTypeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployCustomTargetTypeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/customTargetTypes/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/clouddeploy/iam_clouddeploy_delivery_pipeline_generated_test.go b/google/services/clouddeploy/iam_clouddeploy_delivery_pipeline_generated_test.go index 03c091356b8..ad9355adbdf 100644 --- a/google/services/clouddeploy/iam_clouddeploy_delivery_pipeline_generated_test.go +++ b/google/services/clouddeploy/iam_clouddeploy_delivery_pipeline_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccClouddeployDeliveryPipelineIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_delivery_pipeline_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-delivery-pipeline%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployDeliveryPipelineIAMBindingStateID("google_clouddeploy_delivery_pipeline_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccClouddeployDeliveryPipelineIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_delivery_pipeline_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-delivery-pipeline%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployDeliveryPipelineIAMBindingStateID("google_clouddeploy_delivery_pipeline_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccClouddeployDeliveryPipelineIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_delivery_pipeline_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-delivery-pipeline%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployDeliveryPipelineIAMMemberStateID("google_clouddeploy_delivery_pipeline_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccClouddeployDeliveryPipelineIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_delivery_pipeline_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-delivery-pipeline%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployDeliveryPipelineIAMPolicyStateID("google_clouddeploy_delivery_pipeline_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccClouddeployDeliveryPipelineIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_delivery_pipeline_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-delivery-pipeline%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployDeliveryPipelineIAMPolicyStateID("google_clouddeploy_delivery_pipeline_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -265,3 +266,57 @@ resource "google_clouddeploy_delivery_pipeline_iam_binding" "foo" { } `, context) } + +func generateClouddeployDeliveryPipelineIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployDeliveryPipelineIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployDeliveryPipelineIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/deliveryPipelines/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/clouddeploy/iam_clouddeploy_target_generated_test.go b/google/services/clouddeploy/iam_clouddeploy_target_generated_test.go index 8bb458411df..718f4e75057 100644 --- a/google/services/clouddeploy/iam_clouddeploy_target_generated_test.go +++ b/google/services/clouddeploy/iam_clouddeploy_target_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccClouddeployTargetIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_target_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/targets/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-target%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployTargetIAMBindingStateID("google_clouddeploy_target_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccClouddeployTargetIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_target_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/targets/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-target%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployTargetIAMBindingStateID("google_clouddeploy_target_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccClouddeployTargetIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_target_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/targets/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-target%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployTargetIAMMemberStateID("google_clouddeploy_target_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccClouddeployTargetIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_target_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/targets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-target%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployTargetIAMPolicyStateID("google_clouddeploy_target_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccClouddeployTargetIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_clouddeploy_target_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/targets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cd-target%s", context["random_suffix"])), + ImportStateIdFunc: generateClouddeployTargetIAMPolicyStateID("google_clouddeploy_target_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -235,3 +236,57 @@ resource "google_clouddeploy_target_iam_binding" "foo" { } `, context) } + +func generateClouddeployTargetIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/targets/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployTargetIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/targets/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateClouddeployTargetIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/targets/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudfunctions/iam_cloudfunctions_function_generated_test.go b/google/services/cloudfunctions/iam_cloudfunctions_function_generated_test.go index 5d5d88b66b0..c575614a4f2 100644 --- a/google/services/cloudfunctions/iam_cloudfunctions_function_generated_test.go +++ b/google/services/cloudfunctions/iam_cloudfunctions_function_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccCloudFunctionsCloudFunctionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions_function_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-function%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudFunctionsCloudFunctionIAMBindingStateID("google_cloudfunctions_function_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccCloudFunctionsCloudFunctionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions_function_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-function%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudFunctionsCloudFunctionIAMBindingStateID("google_cloudfunctions_function_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccCloudFunctionsCloudFunctionIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions_function_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-function%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudFunctionsCloudFunctionIAMMemberStateID("google_cloudfunctions_function_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccCloudFunctionsCloudFunctionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions_function_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-function%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudFunctionsCloudFunctionIAMPolicyStateID("google_cloudfunctions_function_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccCloudFunctionsCloudFunctionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions_function_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-function%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudFunctionsCloudFunctionIAMPolicyStateID("google_cloudfunctions_function_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -333,3 +334,57 @@ resource "google_cloudfunctions_function_iam_binding" "foo" { } `, context) } + +func generateCloudFunctionsCloudFunctionIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, region, cloud_function), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudFunctionsCloudFunctionIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, region, cloud_function), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudFunctionsCloudFunctionIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, region, cloud_function), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudfunctions2/iam_cloudfunctions2_function_generated_test.go b/google/services/cloudfunctions2/iam_cloudfunctions2_function_generated_test.go index 49086d22f85..f01dae874f2 100644 --- a/google/services/cloudfunctions2/iam_cloudfunctions2_function_generated_test.go +++ b/google/services/cloudfunctions2/iam_cloudfunctions2_function_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -59,7 +60,7 @@ func TestAccCloudfunctions2functionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions2_function_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-function-v2%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudfunctions2functionIAMBindingStateID("google_cloudfunctions2_function_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -69,7 +70,7 @@ func TestAccCloudfunctions2functionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions2_function_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-function-v2%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudfunctions2functionIAMBindingStateID("google_cloudfunctions2_function_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -99,7 +100,7 @@ func TestAccCloudfunctions2functionIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions2_function_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-function-v2%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudfunctions2functionIAMMemberStateID("google_cloudfunctions2_function_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccCloudfunctions2functionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions2_function_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-function-v2%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudfunctions2functionIAMPolicyStateID("google_cloudfunctions2_function_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -138,7 +139,7 @@ func TestAccCloudfunctions2functionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloudfunctions2_function_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/functions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-function-v2%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudfunctions2functionIAMPolicyStateID("google_cloudfunctions2_function_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -417,3 +418,57 @@ resource "google_cloudfunctions2_function_iam_binding" "foo" { } `, context) } + +func generateCloudfunctions2functionIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, location, cloud_function), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudfunctions2functionIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, location, cloud_function), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudfunctions2functionIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_function := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_function"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, location, cloud_function), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudrun/iam_cloud_run_service_generated_test.go b/google/services/cloudrun/iam_cloud_run_service_generated_test.go index 925a800b409..9e0a9fec6e1 100644 --- a/google/services/cloudrun/iam_cloud_run_service_generated_test.go +++ b/google/services/cloudrun/iam_cloud_run_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccCloudRunServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunServiceIAMBindingStateID("google_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccCloudRunServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunServiceIAMBindingStateID("google_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccCloudRunServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunServiceIAMMemberStateID("google_cloud_run_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccCloudRunServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunServiceIAMPolicyStateID("google_cloud_run_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccCloudRunServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunServiceIAMPolicyStateID("google_cloud_run_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -303,3 +304,57 @@ resource "google_cloud_run_service_iam_binding" "foo" { } `, context) } + +func generateCloudRunServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudrunv2/iam_cloud_run_v2_job_generated_test.go b/google/services/cloudrunv2/iam_cloud_run_v2_job_generated_test.go index 574d65f86c2..4309d2fedbd 100644 --- a/google/services/cloudrunv2/iam_cloud_run_v2_job_generated_test.go +++ b/google/services/cloudrunv2/iam_cloud_run_v2_job_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccCloudRunV2JobIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_job_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/jobs/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-job%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2JobIAMBindingStateID("google_cloud_run_v2_job_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccCloudRunV2JobIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_job_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/jobs/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-job%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2JobIAMBindingStateID("google_cloud_run_v2_job_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccCloudRunV2JobIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_job_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/jobs/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-job%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2JobIAMMemberStateID("google_cloud_run_v2_job_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccCloudRunV2JobIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_job_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-job%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2JobIAMPolicyStateID("google_cloud_run_v2_job_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccCloudRunV2JobIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_job_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-job%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2JobIAMPolicyStateID("google_cloud_run_v2_job_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -280,3 +281,57 @@ resource "google_cloud_run_v2_job_iam_binding" "foo" { } `, context) } + +func generateCloudRunV2JobIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/jobs/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2JobIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/jobs/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2JobIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/jobs/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudrunv2/iam_cloud_run_v2_service_generated_test.go b/google/services/cloudrunv2/iam_cloud_run_v2_service_generated_test.go index 461710c947a..538c863fec2 100644 --- a/google/services/cloudrunv2/iam_cloud_run_v2_service_generated_test.go +++ b/google/services/cloudrunv2/iam_cloud_run_v2_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccCloudRunV2ServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2ServiceIAMBindingStateID("google_cloud_run_v2_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccCloudRunV2ServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2ServiceIAMBindingStateID("google_cloud_run_v2_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccCloudRunV2ServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2ServiceIAMMemberStateID("google_cloud_run_v2_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccCloudRunV2ServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2ServiceIAMPolicyStateID("google_cloud_run_v2_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccCloudRunV2ServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2ServiceIAMPolicyStateID("google_cloud_run_v2_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -295,3 +296,57 @@ resource "google_cloud_run_v2_service_iam_binding" "foo" { } `, context) } + +func generateCloudRunV2ServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2ServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2ServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudrunv2/iam_cloud_run_v2_worker_pool_generated_test.go b/google/services/cloudrunv2/iam_cloud_run_v2_worker_pool_generated_test.go index b0e3e867f06..d594eaedbc0 100644 --- a/google/services/cloudrunv2/iam_cloud_run_v2_worker_pool_generated_test.go +++ b/google/services/cloudrunv2/iam_cloud_run_v2_worker_pool_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccCloudRunV2WorkerPoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_worker_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/workerPools/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-worker-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2WorkerPoolIAMBindingStateID("google_cloud_run_v2_worker_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccCloudRunV2WorkerPoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_worker_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/workerPools/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-worker-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2WorkerPoolIAMBindingStateID("google_cloud_run_v2_worker_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccCloudRunV2WorkerPoolIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_worker_pool_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/workerPools/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-worker-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2WorkerPoolIAMMemberStateID("google_cloud_run_v2_worker_pool_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccCloudRunV2WorkerPoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_worker_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-worker-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2WorkerPoolIAMPolicyStateID("google_cloud_run_v2_worker_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccCloudRunV2WorkerPoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_run_v2_worker_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloudrun-worker-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudRunV2WorkerPoolIAMPolicyStateID("google_cloud_run_v2_worker_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -275,3 +276,57 @@ resource "google_cloud_run_v2_worker_pool_iam_binding" "foo" { } `, context) } + +func generateCloudRunV2WorkerPoolIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2WorkerPoolIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudRunV2WorkerPoolIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/cloudtasks/iam_cloud_tasks_queue_generated_test.go b/google/services/cloudtasks/iam_cloud_tasks_queue_generated_test.go index 0ec6b337f38..37a30e66c2b 100644 --- a/google/services/cloudtasks/iam_cloud_tasks_queue_generated_test.go +++ b/google/services/cloudtasks/iam_cloud_tasks_queue_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccCloudTasksQueueIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_tasks_queue_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/queues/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-tasks-queue-test%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudTasksQueueIAMBindingStateID("google_cloud_tasks_queue_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccCloudTasksQueueIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_cloud_tasks_queue_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/queues/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-tasks-queue-test%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudTasksQueueIAMBindingStateID("google_cloud_tasks_queue_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccCloudTasksQueueIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_cloud_tasks_queue_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/queues/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-tasks-queue-test%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudTasksQueueIAMMemberStateID("google_cloud_tasks_queue_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccCloudTasksQueueIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_tasks_queue_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/queues/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-tasks-queue-test%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudTasksQueueIAMPolicyStateID("google_cloud_tasks_queue_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccCloudTasksQueueIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_cloud_tasks_queue_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/queues/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-tasks-queue-test%s", context["random_suffix"])), + ImportStateIdFunc: generateCloudTasksQueueIAMPolicyStateID("google_cloud_tasks_queue_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -235,3 +236,57 @@ resource "google_cloud_tasks_queue_iam_binding" "foo" { } `, context) } + +func generateCloudTasksQueueIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/queues/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateCloudTasksQueueIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/queues/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateCloudTasksQueueIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/queues/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/colab/iam_colab_runtime_template_generated_test.go b/google/services/colab/iam_colab_runtime_template_generated_test.go index 5b112f8bdf4..c71084d54a4 100644 --- a/google/services/colab/iam_colab_runtime_template_generated_test.go +++ b/google/services/colab/iam_colab_runtime_template_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccColabRuntimeTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_colab_runtime_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-colab-runtime-template%s", context["random_suffix"])), + ImportStateIdFunc: generateColabRuntimeTemplateIAMBindingStateID("google_colab_runtime_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccColabRuntimeTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_colab_runtime_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-colab-runtime-template%s", context["random_suffix"])), + ImportStateIdFunc: generateColabRuntimeTemplateIAMBindingStateID("google_colab_runtime_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccColabRuntimeTemplateIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_colab_runtime_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-colab-runtime-template%s", context["random_suffix"])), + ImportStateIdFunc: generateColabRuntimeTemplateIAMMemberStateID("google_colab_runtime_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccColabRuntimeTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_colab_runtime_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-colab-runtime-template%s", context["random_suffix"])), + ImportStateIdFunc: generateColabRuntimeTemplateIAMPolicyStateID("google_colab_runtime_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccColabRuntimeTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_colab_runtime_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-colab-runtime-template%s", context["random_suffix"])), + ImportStateIdFunc: generateColabRuntimeTemplateIAMPolicyStateID("google_colab_runtime_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -280,3 +281,57 @@ resource "google_colab_runtime_template_iam_binding" "foo" { } `, context) } + +func generateColabRuntimeTemplateIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_template := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s", project, location, runtime_template), "", "", rawState["condition.0.title"]), nil + } +} + +func generateColabRuntimeTemplateIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_template := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s", project, location, runtime_template), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateColabRuntimeTemplateIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_template := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/notebookRuntimeTemplates/%s", project, location, runtime_template), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_disk_generated_test.go b/google/services/compute/iam_compute_disk_generated_test.go index 8109b1f67b9..61e75e08d5c 100644 --- a/google/services/compute/iam_compute_disk_generated_test.go +++ b/google/services/compute/iam_compute_disk_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccComputeDiskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_disk_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/disks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-test-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeDiskIAMBindingStateID("google_compute_disk_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccComputeDiskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_disk_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/disks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-test-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeDiskIAMBindingStateID("google_compute_disk_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccComputeDiskIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_disk_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/disks/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-test-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeDiskIAMMemberStateID("google_compute_disk_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccComputeDiskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_disk_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/disks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-test-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeDiskIAMPolicyStateID("google_compute_disk_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccComputeDiskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_disk_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/disks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-test-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeDiskIAMPolicyStateID("google_compute_disk_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -265,3 +266,57 @@ resource "google_compute_disk_iam_binding" "foo" { } `, context) } + +func generateComputeDiskIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/disks/%s", project, zone, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeDiskIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/disks/%s", project, zone, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeDiskIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/disks/%s", project, zone, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_image_generated_test.go b/google/services/compute/iam_compute_image_generated_test.go index 4bd7b0513d5..a6c34796ca7 100644 --- a/google/services/compute/iam_compute_image_generated_test.go +++ b/google/services/compute/iam_compute_image_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccComputeImageIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_image_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccComputeImageIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_image_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccComputeImageIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_image_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMMemberStateID("google_compute_image_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccComputeImageIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_image_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMPolicyStateID("google_compute_image_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccComputeImageIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_image_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMPolicyStateID("google_compute_image_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccComputeImageIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_image_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccComputeImageIamBindingGenerated_withAndWithoutCondition(t *testing.T }, { ResourceName: "google_compute_image_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_image_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_image_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeImageIAMBindingStateID("google_compute_image_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccComputeImageIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_image_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeImageIAMMemberStateID("google_compute_image_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccComputeImageIamMemberGenerated_withAndWithoutCondition(t *testing.T) }, { ResourceName: "google_compute_image_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMMemberStateID("google_compute_image_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_image_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeImageIAMMemberStateID("google_compute_image_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_image_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s roles/compute.imageUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeImageIAMMemberStateID("google_compute_image_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccComputeImageIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_image_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/images/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeImageIAMPolicyStateID("google_compute_image_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -733,3 +734,53 @@ resource "google_compute_image_iam_policy" "foo" { } `, context) } +func generateComputeImageIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + image := tpgresource.GetResourceNameFromSelfLink(rawState["image"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/images/%s", project, image), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeImageIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + image := tpgresource.GetResourceNameFromSelfLink(rawState["image"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/images/%s", project, image), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeImageIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + image := tpgresource.GetResourceNameFromSelfLink(rawState["image"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/images/%s", project, image), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_instance_generated_test.go b/google/services/compute/iam_compute_instance_generated_test.go index a26ca3a64aa..dcbef84ac07 100644 --- a/google/services/compute/iam_compute_instance_generated_test.go +++ b/google/services/compute/iam_compute_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccComputeInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccComputeInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccComputeInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMMemberStateID("google_compute_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccComputeInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMPolicyStateID("google_compute_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccComputeInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMPolicyStateID("google_compute_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccComputeInstanceIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccComputeInstanceIamBindingGenerated_withAndWithoutCondition(t *testin }, { ResourceName: "google_compute_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstanceIAMBindingStateID("google_compute_instance_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccComputeInstanceIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceIAMMemberStateID("google_compute_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccComputeInstanceIamMemberGenerated_withAndWithoutCondition(t *testing }, { ResourceName: "google_compute_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMMemberStateID("google_compute_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceIAMMemberStateID("google_compute_instance_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s roles/compute.osLogin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstanceIAMMemberStateID("google_compute_instance_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccComputeInstanceIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceIAMPolicyStateID("google_compute_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -718,3 +719,56 @@ resource "google_compute_instance_iam_policy" "foo" { } `, context) } +func generateComputeInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_instance_template_generated_test.go b/google/services/compute/iam_compute_instance_template_generated_test.go index 680982cd5d7..8b7657f15cd 100644 --- a/google/services/compute/iam_compute_instance_template_generated_test.go +++ b/google/services/compute/iam_compute_instance_template_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccComputeInstanceTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccComputeInstanceTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccComputeInstanceTemplateIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMMemberStateID("google_compute_instance_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccComputeInstanceTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMPolicyStateID("google_compute_instance_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccComputeInstanceTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instance_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMPolicyStateID("google_compute_instance_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccComputeInstanceTemplateIamBindingGenerated_withCondition(t *testing. }, { ResourceName: "google_compute_instance_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccComputeInstanceTemplateIamBindingGenerated_withAndWithoutCondition(t }, { ResourceName: "google_compute_instance_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_template_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_template_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMBindingStateID("google_compute_instance_template_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccComputeInstanceTemplateIamMemberGenerated_withCondition(t *testing.T }, { ResourceName: "google_compute_instance_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMMemberStateID("google_compute_instance_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccComputeInstanceTemplateIamMemberGenerated_withAndWithoutCondition(t }, { ResourceName: "google_compute_instance_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMMemberStateID("google_compute_instance_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_template_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMMemberStateID("google_compute_instance_template_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instance_template_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s roles/compute.instanceAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstanceTemplateIAMMemberStateID("google_compute_instance_template_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccComputeInstanceTemplateIamPolicyGenerated_withCondition(t *testing.T }, { ResourceName: "google_compute_instance_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/instanceTemplates/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-instance-template%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstanceTemplateIAMPolicyStateID("google_compute_instance_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -673,3 +674,53 @@ resource "google_compute_instance_template_iam_policy" "foo" { } `, context) } +func generateComputeInstanceTemplateIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstanceTemplateIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstanceTemplateIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_instant_snapshot_generated_test.go b/google/services/compute/iam_compute_instant_snapshot_generated_test.go index 015e57c3358..6dd2182a608 100644 --- a/google/services/compute/iam_compute_instant_snapshot_generated_test.go +++ b/google/services/compute/iam_compute_instant_snapshot_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccComputeInstantSnapshotIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccComputeInstantSnapshotIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccComputeInstantSnapshotIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_instant_snapshot_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMMemberStateID("google_compute_instant_snapshot_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccComputeInstantSnapshotIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instant_snapshot_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMPolicyStateID("google_compute_instant_snapshot_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccComputeInstantSnapshotIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_instant_snapshot_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMPolicyStateID("google_compute_instant_snapshot_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccComputeInstantSnapshotIamBindingGenerated_withCondition(t *testing.T }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccComputeInstantSnapshotIamBindingGenerated_withAndWithoutCondition(t }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instant_snapshot_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMBindingStateID("google_compute_instant_snapshot_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccComputeInstantSnapshotIamMemberGenerated_withCondition(t *testing.T) }, { ResourceName: "google_compute_instant_snapshot_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMMemberStateID("google_compute_instant_snapshot_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccComputeInstantSnapshotIamMemberGenerated_withAndWithoutCondition(t * }, { ResourceName: "google_compute_instant_snapshot_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMMemberStateID("google_compute_instant_snapshot_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instant_snapshot_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMMemberStateID("google_compute_instant_snapshot_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_instant_snapshot_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s roles/compute.storageAdmin user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeInstantSnapshotIAMMemberStateID("google_compute_instant_snapshot_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccComputeInstantSnapshotIamPolicyGenerated_withCondition(t *testing.T) }, { ResourceName: "google_compute_instant_snapshot_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeInstantSnapshotIAMPolicyStateID("google_compute_instant_snapshot_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -678,3 +679,56 @@ resource "google_compute_instant_snapshot_iam_policy" "foo" { } `, context) } +func generateComputeInstantSnapshotIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", project, zone, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstantSnapshotIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", project, zone, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeInstantSnapshotIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/zones/%s/instantSnapshots/%s", project, zone, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_region_disk_generated_test.go b/google/services/compute/iam_compute_region_disk_generated_test.go index c4801f821d8..4b9c5ab9704 100644 --- a/google/services/compute/iam_compute_region_disk_generated_test.go +++ b/google/services/compute/iam_compute_region_disk_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccComputeRegionDiskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_region_disk_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/disks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-region-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeRegionDiskIAMBindingStateID("google_compute_region_disk_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccComputeRegionDiskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_region_disk_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/disks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-region-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeRegionDiskIAMBindingStateID("google_compute_region_disk_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccComputeRegionDiskIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_region_disk_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/disks/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-region-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeRegionDiskIAMMemberStateID("google_compute_region_disk_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccComputeRegionDiskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_region_disk_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/disks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-region-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeRegionDiskIAMPolicyStateID("google_compute_region_disk_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccComputeRegionDiskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_region_disk_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/disks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-region-disk%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeRegionDiskIAMPolicyStateID("google_compute_region_disk_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -330,3 +331,57 @@ resource "google_compute_region_disk_iam_binding" "foo" { } `, context) } + +func generateComputeRegionDiskIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/disks/%s", project, region, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeRegionDiskIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/disks/%s", project, region, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeRegionDiskIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/disks/%s", project, region, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_snapshot_generated_test.go b/google/services/compute/iam_compute_snapshot_generated_test.go index 794466f3d71..3d020c1a46d 100644 --- a/google/services/compute/iam_compute_snapshot_generated_test.go +++ b/google/services/compute/iam_compute_snapshot_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccComputeSnapshotIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSnapshotIAMBindingStateID("google_compute_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccComputeSnapshotIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_snapshot_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSnapshotIAMBindingStateID("google_compute_snapshot_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccComputeSnapshotIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_snapshot_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSnapshotIAMMemberStateID("google_compute_snapshot_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccComputeSnapshotIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_snapshot_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSnapshotIAMPolicyStateID("google_compute_snapshot_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccComputeSnapshotIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_snapshot_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSnapshotIAMPolicyStateID("google_compute_snapshot_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -319,3 +320,54 @@ resource "google_compute_snapshot_iam_binding" "foo" { } `, context) } + +func generateComputeSnapshotIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/snapshots/%s", project, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeSnapshotIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/snapshots/%s", project, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeSnapshotIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/global/snapshots/%s", project, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/compute/iam_compute_subnetwork_generated_test.go b/google/services/compute/iam_compute_subnetwork_generated_test.go index 71b65612f7d..82e456b33cf 100644 --- a/google/services/compute/iam_compute_subnetwork_generated_test.go +++ b/google/services/compute/iam_compute_subnetwork_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccComputeSubnetworkIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccComputeSubnetworkIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccComputeSubnetworkIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMMemberStateID("google_compute_subnetwork_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccComputeSubnetworkIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMPolicyStateID("google_compute_subnetwork_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccComputeSubnetworkIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMPolicyStateID("google_compute_subnetwork_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccComputeSubnetworkIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccComputeSubnetworkIamBindingGenerated_withAndWithoutCondition(t *test }, { ResourceName: "google_compute_subnetwork_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_subnetwork_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_subnetwork_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeSubnetworkIAMBindingStateID("google_compute_subnetwork_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccComputeSubnetworkIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeSubnetworkIAMMemberStateID("google_compute_subnetwork_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccComputeSubnetworkIamMemberGenerated_withAndWithoutCondition(t *testi }, { ResourceName: "google_compute_subnetwork_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMMemberStateID("google_compute_subnetwork_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_subnetwork_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateComputeSubnetworkIAMMemberStateID("google_compute_subnetwork_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_compute_subnetwork_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s roles/compute.networkUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateComputeSubnetworkIAMMemberStateID("google_compute_subnetwork_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccComputeSubnetworkIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_compute_subnetwork_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-test-subnetwork%s", context["random_suffix"])), + ImportStateIdFunc: generateComputeSubnetworkIAMPolicyStateID("google_compute_subnetwork_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -718,3 +719,56 @@ resource "google_compute_subnetwork_iam_policy" "foo" { } `, context) } +func generateComputeSubnetworkIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + subnetwork := tpgresource.GetResourceNameFromSelfLink(rawState["subnetwork"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", project, region, subnetwork), "", "", rawState["condition.0.title"]), nil + } +} + +func generateComputeSubnetworkIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + subnetwork := tpgresource.GetResourceNameFromSelfLink(rawState["subnetwork"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", project, region, subnetwork), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateComputeSubnetworkIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + subnetwork := tpgresource.GetResourceNameFromSelfLink(rawState["subnetwork"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", project, region, subnetwork), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/containeranalysis/iam_container_analysis_note_generated_test.go b/google/services/containeranalysis/iam_container_analysis_note_generated_test.go index addc19a34cb..a4c8a0ee126 100644 --- a/google/services/containeranalysis/iam_container_analysis_note_generated_test.go +++ b/google/services/containeranalysis/iam_container_analysis_note_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccContainerAnalysisNoteIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_container_analysis_note_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/notes/%s roles/containeranalysis.notes.occurrences.viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-attestor-note%s", context["random_suffix"])), + ImportStateIdFunc: generateContainerAnalysisNoteIAMBindingStateID("google_container_analysis_note_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccContainerAnalysisNoteIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_container_analysis_note_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/notes/%s roles/containeranalysis.notes.occurrences.viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-attestor-note%s", context["random_suffix"])), + ImportStateIdFunc: generateContainerAnalysisNoteIAMBindingStateID("google_container_analysis_note_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccContainerAnalysisNoteIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_container_analysis_note_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/notes/%s roles/containeranalysis.notes.occurrences.viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-attestor-note%s", context["random_suffix"])), + ImportStateIdFunc: generateContainerAnalysisNoteIAMMemberStateID("google_container_analysis_note_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccContainerAnalysisNoteIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_container_analysis_note_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/notes/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-attestor-note%s", context["random_suffix"])), + ImportStateIdFunc: generateContainerAnalysisNoteIAMPolicyStateID("google_container_analysis_note_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccContainerAnalysisNoteIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_container_analysis_note_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/notes/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-attestor-note%s", context["random_suffix"])), + ImportStateIdFunc: generateContainerAnalysisNoteIAMPolicyStateID("google_container_analysis_note_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -249,3 +250,54 @@ resource "google_container_analysis_note_iam_binding" "foo" { } `, context) } + +func generateContainerAnalysisNoteIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + note := tpgresource.GetResourceNameFromSelfLink(rawState["note"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/notes/%s", project, note), "", "", rawState["condition.0.title"]), nil + } +} + +func generateContainerAnalysisNoteIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + note := tpgresource.GetResourceNameFromSelfLink(rawState["note"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/notes/%s", project, note), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateContainerAnalysisNoteIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + note := tpgresource.GetResourceNameFromSelfLink(rawState["note"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/notes/%s", project, note), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/datacatalog/iam_data_catalog_entry_group_generated_test.go b/google/services/datacatalog/iam_data_catalog_entry_group_generated_test.go index 1031141dfc2..dfb3bd59b57 100644 --- a/google/services/datacatalog/iam_data_catalog_entry_group_generated_test.go +++ b/google/services/datacatalog/iam_data_catalog_entry_group_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccDataCatalogEntryGroupIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_entry_group_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_group%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogEntryGroupIAMBindingStateID("google_data_catalog_entry_group_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccDataCatalogEntryGroupIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_entry_group_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_group%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogEntryGroupIAMBindingStateID("google_data_catalog_entry_group_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccDataCatalogEntryGroupIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_entry_group_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_group%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogEntryGroupIAMMemberStateID("google_data_catalog_entry_group_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccDataCatalogEntryGroupIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_entry_group_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_group%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogEntryGroupIAMPolicyStateID("google_data_catalog_entry_group_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataCatalogEntryGroupIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_entry_group_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_group%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogEntryGroupIAMPolicyStateID("google_data_catalog_entry_group_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -218,3 +219,57 @@ resource "google_data_catalog_entry_group_iam_binding" "foo" { } `, context) } + +func generateDataCatalogEntryGroupIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + entry_group := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, region, entry_group), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogEntryGroupIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + entry_group := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, region, entry_group), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogEntryGroupIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + entry_group := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, region, entry_group), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/datacatalog/iam_data_catalog_policy_tag_generated_test.go b/google/services/datacatalog/iam_data_catalog_policy_tag_generated_test.go index caff667c789..cf309e6dfe9 100644 --- a/google/services/datacatalog/iam_data_catalog_policy_tag_generated_test.go +++ b/google/services/datacatalog/iam_data_catalog_policy_tag_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -228,3 +229,51 @@ resource "google_data_catalog_policy_tag_iam_binding" "foo" { } `, context) } + +func generateDataCatalogPolicyTagIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + policy_tag := rawState["policy_tag"] + return acctest.BuildIAMImportId(fmt.Sprintf("%s", policy_tag), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogPolicyTagIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + policy_tag := rawState["policy_tag"] + return acctest.BuildIAMImportId(fmt.Sprintf("%s", policy_tag), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogPolicyTagIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + policy_tag := rawState["policy_tag"] + return acctest.BuildIAMImportId(fmt.Sprintf("%s", policy_tag), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/datacatalog/iam_data_catalog_tag_template_generated_test.go b/google/services/datacatalog/iam_data_catalog_tag_template_generated_test.go index 292415a34d7..810ca5a22d4 100644 --- a/google/services/datacatalog/iam_data_catalog_tag_template_generated_test.go +++ b/google/services/datacatalog/iam_data_catalog_tag_template_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataCatalogTagTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_tag_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_template%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogTagTemplateIAMBindingStateID("google_data_catalog_tag_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataCatalogTagTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_tag_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_template%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogTagTemplateIAMBindingStateID("google_data_catalog_tag_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataCatalogTagTemplateIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_tag_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_template%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogTagTemplateIAMMemberStateID("google_data_catalog_tag_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataCatalogTagTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_tag_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_template%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogTagTemplateIAMPolicyStateID("google_data_catalog_tag_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataCatalogTagTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_catalog_tag_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_my_template%s", context["random_suffix"])), + ImportStateIdFunc: generateDataCatalogTagTemplateIAMPolicyStateID("google_data_catalog_tag_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -416,3 +417,57 @@ resource "google_data_catalog_tag_template_iam_binding" "foo" { } `, context) } + +func generateDataCatalogTagTemplateIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + tag_template := tpgresource.GetResourceNameFromSelfLink(rawState["tag_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s", project, region, tag_template), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogTagTemplateIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + tag_template := tpgresource.GetResourceNameFromSelfLink(rawState["tag_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s", project, region, tag_template), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogTagTemplateIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + tag_template := tpgresource.GetResourceNameFromSelfLink(rawState["tag_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/tagTemplates/%s", project, region, tag_template), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/datacatalog/iam_data_catalog_taxonomy_generated_test.go b/google/services/datacatalog/iam_data_catalog_taxonomy_generated_test.go index 445859a9af4..4fbd75ff988 100644 --- a/google/services/datacatalog/iam_data_catalog_taxonomy_generated_test.go +++ b/google/services/datacatalog/iam_data_catalog_taxonomy_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -198,3 +199,57 @@ resource "google_data_catalog_taxonomy_iam_binding" "foo" { } `, context) } + +func generateDataCatalogTaxonomyIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + taxonomy := tpgresource.GetResourceNameFromSelfLink(rawState["taxonomy"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/taxonomies/%s", project, region, taxonomy), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogTaxonomyIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + taxonomy := tpgresource.GetResourceNameFromSelfLink(rawState["taxonomy"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/taxonomies/%s", project, region, taxonomy), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataCatalogTaxonomyIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + taxonomy := tpgresource.GetResourceNameFromSelfLink(rawState["taxonomy"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/taxonomies/%s", project, region, taxonomy), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/datafusion/iam_data_fusion_instance.go b/google/services/datafusion/iam_data_fusion_instance.go index a37bf0d0519..b8d28ee8449 100644 --- a/google/services/datafusion/iam_data_fusion_instance.go +++ b/google/services/datafusion/iam_data_fusion_instance.go @@ -91,7 +91,7 @@ func DataFusionInstanceIamUpdaterProducer(d tpgresource.TerraformResourceData, c } // We may have gotten either a long or short name, so attempt to parse long name if possible - m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("name").(string)) + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("name").(string)) if err != nil { return nil, err } @@ -134,7 +134,7 @@ func DataFusionInstanceIdParseFunc(d *schema.ResourceData, config *transport_tpg values["region"] = region } - m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) if err != nil { return err } diff --git a/google/services/datafusion/iam_data_fusion_instance_generated_test.go b/google/services/datafusion/iam_data_fusion_instance_generated_test.go index c133a786429..69daca4a86c 100644 --- a/google/services/datafusion/iam_data_fusion_instance_generated_test.go +++ b/google/services/datafusion/iam_data_fusion_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataFusionInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_fusion_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateDataFusionInstanceIAMBindingStateID("google_data_fusion_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataFusionInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_data_fusion_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateDataFusionInstanceIAMBindingStateID("google_data_fusion_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataFusionInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_data_fusion_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateDataFusionInstanceIAMMemberStateID("google_data_fusion_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataFusionInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_fusion_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateDataFusionInstanceIAMPolicyStateID("google_data_fusion_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataFusionInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_data_fusion_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateDataFusionInstanceIAMPolicyStateID("google_data_fusion_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -248,3 +249,57 @@ resource "google_data_fusion_instance_iam_binding" "foo" { } `, context) } + +func generateDataFusionInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataFusionInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataFusionInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_aspect_type_generated_test.go b/google/services/dataplex/iam_dataplex_aspect_type_generated_test.go index 621ce822935..b46dd7106ec 100644 --- a/google/services/dataplex/iam_dataplex_aspect_type_generated_test.go +++ b/google/services/dataplex/iam_dataplex_aspect_type_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -353,3 +354,57 @@ resource "google_dataplex_aspect_type_iam_binding" "foo" { } `, context) } + +func generateDataplexAspectTypeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + aspect_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["aspect_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/aspectTypes/%s", project, location, aspect_type_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexAspectTypeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + aspect_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["aspect_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/aspectTypes/%s", project, location, aspect_type_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexAspectTypeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + aspect_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["aspect_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/aspectTypes/%s", project, location, aspect_type_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_asset_generated_test.go b/google/services/dataplex/iam_dataplex_asset_generated_test.go index 0c5a1610aec..e4896af63ab 100644 --- a/google/services/dataplex/iam_dataplex_asset_generated_test.go +++ b/google/services/dataplex/iam_dataplex_asset_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataplexAssetIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_asset_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"]), fmt.Sprintf("tf-test-asset%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexAssetIAMBindingStateID("google_dataplex_asset_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataplexAssetIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_asset_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"]), fmt.Sprintf("tf-test-asset%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexAssetIAMBindingStateID("google_dataplex_asset_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataplexAssetIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_asset_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"]), fmt.Sprintf("tf-test-asset%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexAssetIAMMemberStateID("google_dataplex_asset_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataplexAssetIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_asset_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"]), fmt.Sprintf("tf-test-asset%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexAssetIAMPolicyStateID("google_dataplex_asset_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataplexAssetIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_asset_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"]), fmt.Sprintf("tf-test-asset%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexAssetIAMPolicyStateID("google_dataplex_asset_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -530,3 +531,63 @@ resource "google_dataplex_asset_iam_binding" "foo" { } `, context) } + +func generateDataplexAssetIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + asset := tpgresource.GetResourceNameFromSelfLink(rawState["asset"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s", project, location, lake, dataplex_zone, asset), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexAssetIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + asset := tpgresource.GetResourceNameFromSelfLink(rawState["asset"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s", project, location, lake, dataplex_zone, asset), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexAssetIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + asset := tpgresource.GetResourceNameFromSelfLink(rawState["asset"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s/assets/%s", project, location, lake, dataplex_zone, asset), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_datascan_generated_test.go b/google/services/dataplex/iam_dataplex_datascan_generated_test.go index a3a735a5a13..17cf44039e4 100644 --- a/google/services/dataplex/iam_dataplex_datascan_generated_test.go +++ b/google/services/dataplex/iam_dataplex_datascan_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataplexDatascanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_datascan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataprofile-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexDatascanIAMBindingStateID("google_dataplex_datascan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataplexDatascanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_datascan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataprofile-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexDatascanIAMBindingStateID("google_dataplex_datascan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataplexDatascanIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_datascan_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataprofile-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexDatascanIAMMemberStateID("google_dataplex_datascan_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataplexDatascanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_datascan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataprofile-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexDatascanIAMPolicyStateID("google_dataplex_datascan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataplexDatascanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_datascan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataprofile-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexDatascanIAMPolicyStateID("google_dataplex_datascan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -308,3 +309,57 @@ resource "google_dataplex_datascan_iam_binding" "foo" { } `, context) } + +func generateDataplexDatascanIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_scan_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_scan_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", project, location, data_scan_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexDatascanIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_scan_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_scan_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", project, location, data_scan_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexDatascanIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_scan_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_scan_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", project, location, data_scan_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_entry_group_generated_test.go b/google/services/dataplex/iam_dataplex_entry_group_generated_test.go index 91715928793..3f78e0d4e26 100644 --- a/google/services/dataplex/iam_dataplex_entry_group_generated_test.go +++ b/google/services/dataplex/iam_dataplex_entry_group_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -213,3 +214,57 @@ resource "google_dataplex_entry_group_iam_binding" "foo" { } `, context) } + +func generateDataplexEntryGroupIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_group_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, location, entry_group_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexEntryGroupIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_group_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, location, entry_group_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexEntryGroupIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_group_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_group_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", project, location, entry_group_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_entry_type_generated_test.go b/google/services/dataplex/iam_dataplex_entry_type_generated_test.go index 8414620e499..2fff846f318 100644 --- a/google/services/dataplex/iam_dataplex_entry_type_generated_test.go +++ b/google/services/dataplex/iam_dataplex_entry_type_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -213,3 +214,57 @@ resource "google_dataplex_entry_type_iam_binding" "foo" { } `, context) } + +func generateDataplexEntryTypeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryTypes/%s", project, location, entry_type_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexEntryTypeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryTypes/%s", project, location, entry_type_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexEntryTypeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + entry_type_id := tpgresource.GetResourceNameFromSelfLink(rawState["entry_type_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/entryTypes/%s", project, location, entry_type_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_glossary_generated_test.go b/google/services/dataplex/iam_dataplex_glossary_generated_test.go index 36ee57db4ac..ec90662a154 100644 --- a/google/services/dataplex/iam_dataplex_glossary_generated_test.go +++ b/google/services/dataplex/iam_dataplex_glossary_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccDataplexGlossaryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_glossary_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/glossaries/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-glossary-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexGlossaryIAMBindingStateID("google_dataplex_glossary_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccDataplexGlossaryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_glossary_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/glossaries/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-glossary-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexGlossaryIAMBindingStateID("google_dataplex_glossary_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccDataplexGlossaryIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_glossary_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/glossaries/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-glossary-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexGlossaryIAMMemberStateID("google_dataplex_glossary_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccDataplexGlossaryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_glossary_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/glossaries/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-glossary-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexGlossaryIAMPolicyStateID("google_dataplex_glossary_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataplexGlossaryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_glossary_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/glossaries/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-glossary-basic%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexGlossaryIAMPolicyStateID("google_dataplex_glossary_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -235,3 +236,57 @@ resource "google_dataplex_glossary_iam_binding" "foo" { } `, context) } + +func generateDataplexGlossaryIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + glossary_id := tpgresource.GetResourceNameFromSelfLink(rawState["glossary_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/glossaries/%s", project, location, glossary_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexGlossaryIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + glossary_id := tpgresource.GetResourceNameFromSelfLink(rawState["glossary_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/glossaries/%s", project, location, glossary_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexGlossaryIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + glossary_id := tpgresource.GetResourceNameFromSelfLink(rawState["glossary_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/glossaries/%s", project, location, glossary_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_lake_generated_test.go b/google/services/dataplex/iam_dataplex_lake_generated_test.go index 6bfcea28100..a47c8e040b5 100644 --- a/google/services/dataplex/iam_dataplex_lake_generated_test.go +++ b/google/services/dataplex/iam_dataplex_lake_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataplexLakeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_lake_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexLakeIAMBindingStateID("google_dataplex_lake_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataplexLakeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_lake_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexLakeIAMBindingStateID("google_dataplex_lake_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataplexLakeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_lake_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexLakeIAMMemberStateID("google_dataplex_lake_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataplexLakeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_lake_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexLakeIAMPolicyStateID("google_dataplex_lake_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataplexLakeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_lake_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexLakeIAMPolicyStateID("google_dataplex_lake_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -278,3 +279,57 @@ resource "google_dataplex_lake_iam_binding" "foo" { } `, context) } + +func generateDataplexLakeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s", project, location, lake), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexLakeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s", project, location, lake), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexLakeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s", project, location, lake), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_task_generated_test.go b/google/services/dataplex/iam_dataplex_task_generated_test.go index ebc674ededc..0f97059d669 100644 --- a/google/services/dataplex/iam_dataplex_task_generated_test.go +++ b/google/services/dataplex/iam_dataplex_task_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataplexTaskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_task_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-task%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexTaskIAMBindingStateID("google_dataplex_task_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataplexTaskIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_task_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-task%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexTaskIAMBindingStateID("google_dataplex_task_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataplexTaskIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_task_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-task%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexTaskIAMMemberStateID("google_dataplex_task_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataplexTaskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_task_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-task%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexTaskIAMPolicyStateID("google_dataplex_task_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataplexTaskIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_task_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-task%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexTaskIAMPolicyStateID("google_dataplex_task_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -454,3 +455,60 @@ resource "google_dataplex_task_iam_binding" "foo" { } `, context) } + +func generateDataplexTaskIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + task_id := tpgresource.GetResourceNameFromSelfLink(rawState["task_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s", project, location, lake, task_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexTaskIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + task_id := tpgresource.GetResourceNameFromSelfLink(rawState["task_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s", project, location, lake, task_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexTaskIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + task_id := tpgresource.GetResourceNameFromSelfLink(rawState["task_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/tasks/%s", project, location, lake, task_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataplex/iam_dataplex_zone_generated_test.go b/google/services/dataplex/iam_dataplex_zone_generated_test.go index a99fc0e5ee3..65a3ca3b15d 100644 --- a/google/services/dataplex/iam_dataplex_zone_generated_test.go +++ b/google/services/dataplex/iam_dataplex_zone_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDataplexZoneIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_zone_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexZoneIAMBindingStateID("google_dataplex_zone_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDataplexZoneIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_zone_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexZoneIAMBindingStateID("google_dataplex_zone_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDataplexZoneIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_zone_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexZoneIAMMemberStateID("google_dataplex_zone_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDataplexZoneIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_zone_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexZoneIAMPolicyStateID("google_dataplex_zone_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDataplexZoneIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataplex_zone_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-lake%s", context["random_suffix"]), fmt.Sprintf("tf-test-zone%s", context["random_suffix"])), + ImportStateIdFunc: generateDataplexZoneIAMPolicyStateID("google_dataplex_zone_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -389,3 +390,60 @@ resource "google_dataplex_zone_iam_binding" "foo" { } `, context) } + +func generateDataplexZoneIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s", project, location, lake, dataplex_zone), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexZoneIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s", project, location, lake, dataplex_zone), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexZoneIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + lake := tpgresource.GetResourceNameFromSelfLink(rawState["lake"]) + dataplex_zone := tpgresource.GetResourceNameFromSelfLink(rawState["dataplex_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/lakes/%s/zones/%s", project, location, lake, dataplex_zone), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataproc/iam_dataproc_autoscaling_policy_generated_test.go b/google/services/dataproc/iam_dataproc_autoscaling_policy_generated_test.go index e661bf933df..a74565af35c 100644 --- a/google/services/dataproc/iam_dataproc_autoscaling_policy_generated_test.go +++ b/google/services/dataproc/iam_dataproc_autoscaling_policy_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccDataprocAutoscalingPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_autoscaling_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocAutoscalingPolicyIAMBindingStateID("google_dataproc_autoscaling_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccDataprocAutoscalingPolicyIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_autoscaling_policy_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocAutoscalingPolicyIAMBindingStateID("google_dataproc_autoscaling_policy_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccDataprocAutoscalingPolicyIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_autoscaling_policy_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocAutoscalingPolicyIAMMemberStateID("google_dataproc_autoscaling_policy_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccDataprocAutoscalingPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_autoscaling_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocAutoscalingPolicyIAMPolicyStateID("google_dataproc_autoscaling_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataprocAutoscalingPolicyIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_autoscaling_policy_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocAutoscalingPolicyIAMPolicyStateID("google_dataproc_autoscaling_policy_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -300,3 +301,57 @@ resource "google_dataproc_autoscaling_policy_iam_binding" "foo" { } `, context) } + +func generateDataprocAutoscalingPolicyIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", project, location, policy_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocAutoscalingPolicyIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", project, location, policy_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocAutoscalingPolicyIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + policy_id := tpgresource.GetResourceNameFromSelfLink(rawState["policy_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", project, location, policy_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataprocmetastore/iam_dataproc_metastore_database_generated_test.go b/google/services/dataprocmetastore/iam_dataproc_metastore_database_generated_test.go index d6f19ca32ec..70f5f186268 100644 --- a/google/services/dataprocmetastore/iam_dataproc_metastore_database_generated_test.go +++ b/google/services/dataprocmetastore/iam_dataproc_metastore_database_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -58,7 +59,7 @@ func TestAccDataprocMetastoreDatabaseIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_database_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"), + ImportStateIdFunc: generateDataprocMetastoreDatabaseIAMBindingStateID("google_dataproc_metastore_database_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -68,7 +69,7 @@ func TestAccDataprocMetastoreDatabaseIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_database_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"), + ImportStateIdFunc: generateDataprocMetastoreDatabaseIAMBindingStateID("google_dataproc_metastore_database_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -97,7 +98,7 @@ func TestAccDataprocMetastoreDatabaseIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_database_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"), + ImportStateIdFunc: generateDataprocMetastoreDatabaseIAMMemberStateID("google_dataproc_metastore_database_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataprocMetastoreDatabaseIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_database_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"), + ImportStateIdFunc: generateDataprocMetastoreDatabaseIAMPolicyStateID("google_dataproc_metastore_database_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -135,7 +136,7 @@ func TestAccDataprocMetastoreDatabaseIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_database_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb"), + ImportStateIdFunc: generateDataprocMetastoreDatabaseIAMPolicyStateID("google_dataproc_metastore_database_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -560,3 +561,60 @@ resource "google_dataproc_metastore_database_iam_binding" "foo" { } `, context) } + +func generateDataprocMetastoreDatabaseIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + database := tpgresource.GetResourceNameFromSelfLink(rawState["database"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s", project, location, serviceId, database), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreDatabaseIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + database := tpgresource.GetResourceNameFromSelfLink(rawState["database"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s", project, location, serviceId, database), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreDatabaseIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + database := tpgresource.GetResourceNameFromSelfLink(rawState["database"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s", project, location, serviceId, database), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataprocmetastore/iam_dataproc_metastore_federation_generated_test.go b/google/services/dataprocmetastore/iam_dataproc_metastore_federation_generated_test.go index 8a698a72fd0..671fd14ac75 100644 --- a/google/services/dataprocmetastore/iam_dataproc_metastore_federation_generated_test.go +++ b/google/services/dataprocmetastore/iam_dataproc_metastore_federation_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -305,3 +306,57 @@ resource "google_dataproc_metastore_federation_iam_binding" "foo" { } `, context) } + +func generateDataprocMetastoreFederationIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + federation_id := tpgresource.GetResourceNameFromSelfLink(rawState["federation_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/federations/%s", project, location, federation_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreFederationIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + federation_id := tpgresource.GetResourceNameFromSelfLink(rawState["federation_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/federations/%s", project, location, federation_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreFederationIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + federation_id := tpgresource.GetResourceNameFromSelfLink(rawState["federation_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/federations/%s", project, location, federation_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataprocmetastore/iam_dataproc_metastore_service_generated_test.go b/google/services/dataprocmetastore/iam_dataproc_metastore_service_generated_test.go index 590e388dc9d..95280b453f0 100644 --- a/google/services/dataprocmetastore/iam_dataproc_metastore_service_generated_test.go +++ b/google/services/dataprocmetastore/iam_dataproc_metastore_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccDataprocMetastoreServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocMetastoreServiceIAMBindingStateID("google_dataproc_metastore_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccDataprocMetastoreServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocMetastoreServiceIAMBindingStateID("google_dataproc_metastore_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccDataprocMetastoreServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocMetastoreServiceIAMMemberStateID("google_dataproc_metastore_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccDataprocMetastoreServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocMetastoreServiceIAMPolicyStateID("google_dataproc_metastore_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataprocMetastoreServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])), + ImportStateIdFunc: generateDataprocMetastoreServiceIAMPolicyStateID("google_dataproc_metastore_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -310,3 +311,57 @@ resource "google_dataproc_metastore_service_iam_binding" "foo" { } `, context) } + +func generateDataprocMetastoreServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, service_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dataprocmetastore/iam_dataproc_metastore_table_generated_test.go b/google/services/dataprocmetastore/iam_dataproc_metastore_table_generated_test.go index ff7241501cc..4cf7095b2df 100644 --- a/google/services/dataprocmetastore/iam_dataproc_metastore_table_generated_test.go +++ b/google/services/dataprocmetastore/iam_dataproc_metastore_table_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -58,7 +59,7 @@ func TestAccDataprocMetastoreTableIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_table_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"), + ImportStateIdFunc: generateDataprocMetastoreTableIAMBindingStateID("google_dataproc_metastore_table_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -68,7 +69,7 @@ func TestAccDataprocMetastoreTableIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_table_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"), + ImportStateIdFunc: generateDataprocMetastoreTableIAMBindingStateID("google_dataproc_metastore_table_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -97,7 +98,7 @@ func TestAccDataprocMetastoreTableIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_table_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"), + ImportStateIdFunc: generateDataprocMetastoreTableIAMMemberStateID("google_dataproc_metastore_table_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccDataprocMetastoreTableIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_table_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"), + ImportStateIdFunc: generateDataprocMetastoreTableIAMPolicyStateID("google_dataproc_metastore_table_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -135,7 +136,7 @@ func TestAccDataprocMetastoreTableIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dataproc_metastore_table_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-metastore-srv-%s", context["random_suffix"]), "testdb", "testtbl"), + ImportStateIdFunc: generateDataprocMetastoreTableIAMPolicyStateID("google_dataproc_metastore_table_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -576,3 +577,63 @@ resource "google_dataproc_metastore_table_iam_binding" "foo" { } `, context) } + +func generateDataprocMetastoreTableIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + databaseId := tpgresource.GetResourceNameFromSelfLink(rawState["database_id"]) + table := tpgresource.GetResourceNameFromSelfLink(rawState["table"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s", project, location, serviceId, databaseId, table), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreTableIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + databaseId := tpgresource.GetResourceNameFromSelfLink(rawState["database_id"]) + table := tpgresource.GetResourceNameFromSelfLink(rawState["table"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s", project, location, serviceId, databaseId, table), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataprocMetastoreTableIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + serviceId := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + databaseId := tpgresource.GetResourceNameFromSelfLink(rawState["database_id"]) + table := tpgresource.GetResourceNameFromSelfLink(rawState["table"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/services/%s/databases/%s/tables/%s", project, location, serviceId, databaseId, table), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/dns/iam_dns_managed_zone_generated_test.go b/google/services/dns/iam_dns_managed_zone_generated_test.go index 2558960540b..540ae3e61a4 100644 --- a/google/services/dns/iam_dns_managed_zone_generated_test.go +++ b/google/services/dns/iam_dns_managed_zone_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccDNSManagedZoneIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dns_managed_zone_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/managedZones/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-zone-googlecloudexample%s", context["random_suffix"])), + ImportStateIdFunc: generateDNSManagedZoneIAMBindingStateID("google_dns_managed_zone_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccDNSManagedZoneIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_dns_managed_zone_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/managedZones/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-zone-googlecloudexample%s", context["random_suffix"])), + ImportStateIdFunc: generateDNSManagedZoneIAMBindingStateID("google_dns_managed_zone_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccDNSManagedZoneIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_dns_managed_zone_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/managedZones/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-zone-googlecloudexample%s", context["random_suffix"])), + ImportStateIdFunc: generateDNSManagedZoneIAMMemberStateID("google_dns_managed_zone_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccDNSManagedZoneIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dns_managed_zone_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/managedZones/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-zone-googlecloudexample%s", context["random_suffix"])), + ImportStateIdFunc: generateDNSManagedZoneIAMPolicyStateID("google_dns_managed_zone_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccDNSManagedZoneIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_dns_managed_zone_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/managedZones/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-zone-googlecloudexample%s", context["random_suffix"])), + ImportStateIdFunc: generateDNSManagedZoneIAMPolicyStateID("google_dns_managed_zone_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -482,3 +483,54 @@ resource "google_dns_managed_zone_iam_binding" "foo" { } `, context) } + +func generateDNSManagedZoneIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + managed_zone := tpgresource.GetResourceNameFromSelfLink(rawState["managed_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/managedZones/%s", project, managed_zone), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDNSManagedZoneIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + managed_zone := tpgresource.GetResourceNameFromSelfLink(rawState["managed_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/managedZones/%s", project, managed_zone), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDNSManagedZoneIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + managed_zone := tpgresource.GetResourceNameFromSelfLink(rawState["managed_zone"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/managedZones/%s", project, managed_zone), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/gkebackup/iam_gke_backup_backup_plan_generated_test.go b/google/services/gkebackup/iam_gke_backup_backup_plan_generated_test.go index 3997129210f..d17b740487c 100644 --- a/google/services/gkebackup/iam_gke_backup_backup_plan_generated_test.go +++ b/google/services/gkebackup/iam_gke_backup_backup_plan_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccGKEBackupBackupPlanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_backup_plan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-basic-plan%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupBackupPlanIAMBindingStateID("google_gke_backup_backup_plan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccGKEBackupBackupPlanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_backup_plan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-basic-plan%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupBackupPlanIAMBindingStateID("google_gke_backup_backup_plan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccGKEBackupBackupPlanIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_backup_plan_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-basic-plan%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupBackupPlanIAMMemberStateID("google_gke_backup_backup_plan_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccGKEBackupBackupPlanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_backup_plan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-basic-plan%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupBackupPlanIAMPolicyStateID("google_gke_backup_backup_plan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccGKEBackupBackupPlanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_backup_plan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-basic-plan%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupBackupPlanIAMPolicyStateID("google_gke_backup_backup_plan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -365,3 +366,57 @@ resource "google_gke_backup_backup_plan_iam_binding" "foo" { } `, context) } + +func generateGKEBackupBackupPlanIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateGKEBackupBackupPlanIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateGKEBackupBackupPlanIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/backupPlans/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/gkebackup/iam_gke_backup_restore_plan_generated_test.go b/google/services/gkebackup/iam_gke_backup_restore_plan_generated_test.go index 5f1da80ab43..04cb4185bf2 100644 --- a/google/services/gkebackup/iam_gke_backup_restore_plan_generated_test.go +++ b/google/services/gkebackup/iam_gke_backup_restore_plan_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccGKEBackupRestorePlanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_restore_plan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-restore-all-ns%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupRestorePlanIAMBindingStateID("google_gke_backup_restore_plan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccGKEBackupRestorePlanIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_restore_plan_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-restore-all-ns%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupRestorePlanIAMBindingStateID("google_gke_backup_restore_plan_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccGKEBackupRestorePlanIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_restore_plan_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-restore-all-ns%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupRestorePlanIAMMemberStateID("google_gke_backup_restore_plan_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccGKEBackupRestorePlanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_restore_plan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-restore-all-ns%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupRestorePlanIAMPolicyStateID("google_gke_backup_restore_plan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccGKEBackupRestorePlanIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_backup_restore_plan_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-restore-all-ns%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEBackupRestorePlanIAMPolicyStateID("google_gke_backup_restore_plan_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -445,3 +446,57 @@ resource "google_gke_backup_restore_plan_iam_binding" "foo" { } `, context) } + +func generateGKEBackupRestorePlanIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateGKEBackupRestorePlanIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateGKEBackupRestorePlanIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/restorePlans/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/gkehub/iam_gke_hub_membership_generated_test.go b/google/services/gkehub/iam_gke_hub_membership_generated_test.go index 956a4c4c6cc..0ccec6cbe2c 100644 --- a/google/services/gkehub/iam_gke_hub_membership_generated_test.go +++ b/google/services/gkehub/iam_gke_hub_membership_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccGKEHubMembershipIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_membership_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/memberships/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("basic%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHubMembershipIAMBindingStateID("google_gke_hub_membership_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccGKEHubMembershipIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_membership_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/memberships/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("basic%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHubMembershipIAMBindingStateID("google_gke_hub_membership_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccGKEHubMembershipIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_membership_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/memberships/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("basic%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHubMembershipIAMMemberStateID("google_gke_hub_membership_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccGKEHubMembershipIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_membership_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/memberships/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("basic%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHubMembershipIAMPolicyStateID("google_gke_hub_membership_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccGKEHubMembershipIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_membership_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/memberships/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("basic%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHubMembershipIAMPolicyStateID("google_gke_hub_membership_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -320,3 +321,57 @@ resource "google_gke_hub_membership_iam_binding" "foo" { } `, context) } + +func generateGKEHubMembershipIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + membership_id := tpgresource.GetResourceNameFromSelfLink(rawState["membership_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/memberships/%s", project, location, membership_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateGKEHubMembershipIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + membership_id := tpgresource.GetResourceNameFromSelfLink(rawState["membership_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/memberships/%s", project, location, membership_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateGKEHubMembershipIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + membership_id := tpgresource.GetResourceNameFromSelfLink(rawState["membership_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/memberships/%s", project, location, membership_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/gkehub2/iam_gke_hub_scope_generated_test.go b/google/services/gkehub2/iam_gke_hub_scope_generated_test.go index f4770561059..200658b290c 100644 --- a/google/services/gkehub2/iam_gke_hub_scope_generated_test.go +++ b/google/services/gkehub2/iam_gke_hub_scope_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccGKEHub2ScopeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_scope_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/scopes/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-scope%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHub2ScopeIAMBindingStateID("google_gke_hub_scope_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccGKEHub2ScopeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_scope_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/scopes/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-scope%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHub2ScopeIAMBindingStateID("google_gke_hub_scope_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccGKEHub2ScopeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_scope_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/scopes/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-scope%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHub2ScopeIAMMemberStateID("google_gke_hub_scope_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccGKEHub2ScopeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_scope_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/scopes/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-scope%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHub2ScopeIAMPolicyStateID("google_gke_hub_scope_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccGKEHub2ScopeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_gke_hub_scope_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/global/scopes/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-scope%s", context["random_suffix"])), + ImportStateIdFunc: generateGKEHub2ScopeIAMPolicyStateID("google_gke_hub_scope_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,3 +278,54 @@ resource "google_gke_hub_scope_iam_binding" "foo" { } `, context) } + +func generateGKEHub2ScopeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + scope_id := tpgresource.GetResourceNameFromSelfLink(rawState["scope_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/scopes/%s", project, scope_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateGKEHub2ScopeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + scope_id := tpgresource.GetResourceNameFromSelfLink(rawState["scope_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/scopes/%s", project, scope_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateGKEHub2ScopeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + scope_id := tpgresource.GetResourceNameFromSelfLink(rawState["scope_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/global/scopes/%s", project, scope_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/healthcare/iam_healthcare_consent_store_generated_test.go b/google/services/healthcare/iam_healthcare_consent_store_generated_test.go index 4078e1c0d20..188df200eb0 100644 --- a/google/services/healthcare/iam_healthcare_consent_store_generated_test.go +++ b/google/services/healthcare/iam_healthcare_consent_store_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccHealthcareConsentStoreIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_healthcare_consent_store_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/consentStores/%s roles/viewer", fmt.Sprintf("projects/%s/locations/%s/datasets/tf-test-my-dataset%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"]), fmt.Sprintf("tf-test-my-consent-store%s", context["random_suffix"])), + ImportStateIdFunc: generateHealthcareConsentStoreIAMBindingStateID("google_healthcare_consent_store_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccHealthcareConsentStoreIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_healthcare_consent_store_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/consentStores/%s roles/viewer", fmt.Sprintf("projects/%s/locations/%s/datasets/tf-test-my-dataset%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"]), fmt.Sprintf("tf-test-my-consent-store%s", context["random_suffix"])), + ImportStateIdFunc: generateHealthcareConsentStoreIAMBindingStateID("google_healthcare_consent_store_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccHealthcareConsentStoreIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_healthcare_consent_store_iam_member.foo", - ImportStateId: fmt.Sprintf("%s/consentStores/%s roles/viewer user:admin@hashicorptest.com", fmt.Sprintf("projects/%s/locations/%s/datasets/tf-test-my-dataset%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"]), fmt.Sprintf("tf-test-my-consent-store%s", context["random_suffix"])), + ImportStateIdFunc: generateHealthcareConsentStoreIAMMemberStateID("google_healthcare_consent_store_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccHealthcareConsentStoreIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_healthcare_consent_store_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/consentStores/%s", fmt.Sprintf("projects/%s/locations/%s/datasets/tf-test-my-dataset%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"]), fmt.Sprintf("tf-test-my-consent-store%s", context["random_suffix"])), + ImportStateIdFunc: generateHealthcareConsentStoreIAMPolicyStateID("google_healthcare_consent_store_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccHealthcareConsentStoreIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_healthcare_consent_store_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/consentStores/%s", fmt.Sprintf("projects/%s/locations/%s/datasets/tf-test-my-dataset%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"]), fmt.Sprintf("tf-test-my-consent-store%s", context["random_suffix"])), + ImportStateIdFunc: generateHealthcareConsentStoreIAMPolicyStateID("google_healthcare_consent_store_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -254,3 +255,54 @@ resource "google_healthcare_consent_store_iam_binding" "foo" { } `, context) } + +func generateHealthcareConsentStoreIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + dataset := rawState["dataset"] + consent_store_id := tpgresource.GetResourceNameFromSelfLink(rawState["consent_store_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/consentStores/%s", dataset, consent_store_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateHealthcareConsentStoreIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + dataset := rawState["dataset"] + consent_store_id := tpgresource.GetResourceNameFromSelfLink(rawState["consent_store_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/consentStores/%s", dataset, consent_store_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateHealthcareConsentStoreIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + dataset := rawState["dataset"] + consent_store_id := tpgresource.GetResourceNameFromSelfLink(rawState["consent_store_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/consentStores/%s", dataset, consent_store_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iamworkforcepool/iam_iam_workforce_pool_generated_test.go b/google/services/iamworkforcepool/iam_iam_workforce_pool_generated_test.go index f06d4c01272..c2f423f6e1a 100644 --- a/google/services/iamworkforcepool/iam_iam_workforce_pool_generated_test.go +++ b/google/services/iamworkforcepool/iam_iam_workforce_pool_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -57,7 +58,7 @@ func TestAccIAMWorkforcePoolWorkforcePoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iam_workforce_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("locations/%s/workforcePools/%s roles/iam.workforcePoolViewer", "global", fmt.Sprintf("tf-test-example-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateIAMWorkforcePoolWorkforcePoolIAMBindingStateID("google_iam_workforce_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -67,7 +68,7 @@ func TestAccIAMWorkforcePoolWorkforcePoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iam_workforce_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("locations/%s/workforcePools/%s roles/iam.workforcePoolViewer", "global", fmt.Sprintf("tf-test-example-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateIAMWorkforcePoolWorkforcePoolIAMBindingStateID("google_iam_workforce_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -95,7 +96,7 @@ func TestAccIAMWorkforcePoolWorkforcePoolIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iam_workforce_pool_iam_member.foo", - ImportStateId: fmt.Sprintf("locations/%s/workforcePools/%s roles/iam.workforcePoolViewer user:admin@hashicorptest.com", "global", fmt.Sprintf("tf-test-example-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateIAMWorkforcePoolWorkforcePoolIAMMemberStateID("google_iam_workforce_pool_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccIAMWorkforcePoolWorkforcePoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iam_workforce_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("locations/%s/workforcePools/%s", "global", fmt.Sprintf("tf-test-example-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateIAMWorkforcePoolWorkforcePoolIAMPolicyStateID("google_iam_workforce_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -135,7 +136,7 @@ func TestAccIAMWorkforcePoolWorkforcePoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iam_workforce_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("locations/%s/workforcePools/%s", "global", fmt.Sprintf("tf-test-example-pool%s", context["random_suffix"])), + ImportStateIdFunc: generateIAMWorkforcePoolWorkforcePoolIAMPolicyStateID("google_iam_workforce_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -247,3 +248,54 @@ resource "google_iam_workforce_pool_iam_binding" "foo" { } `, context) } + +func generateIAMWorkforcePoolWorkforcePoolIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + workforce_pool_id := tpgresource.GetResourceNameFromSelfLink(rawState["workforce_pool_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("locations/%s/workforcePools/%s", location, workforce_pool_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIAMWorkforcePoolWorkforcePoolIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + workforce_pool_id := tpgresource.GetResourceNameFromSelfLink(rawState["workforce_pool_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("locations/%s/workforcePools/%s", location, workforce_pool_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIAMWorkforcePoolWorkforcePoolIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + workforce_pool_id := tpgresource.GetResourceNameFromSelfLink(rawState["workforce_pool_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("locations/%s/workforcePools/%s", location, workforce_pool_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_app_engine_version_generated_test.go b/google/services/iap/iam_iap_app_engine_version_generated_test.go index 654d272d880..bf7afda5ab0 100644 --- a/google/services/iap/iam_iap_app_engine_version_generated_test.go +++ b/google/services/iap/iam_iap_app_engine_version_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapAppEngineVersionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapAppEngineVersionIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapAppEngineVersionIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMMemberStateID("google_iap_app_engine_version_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapAppEngineVersionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMPolicyStateID("google_iap_app_engine_version_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapAppEngineVersionIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMPolicyStateID("google_iap_app_engine_version_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapAppEngineVersionIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapAppEngineVersionIamBindingGenerated_withAndWithoutCondition(t *te }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_app_engine_version_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMBindingStateID("google_iap_app_engine_version_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapAppEngineVersionIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMMemberStateID("google_iap_app_engine_version_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapAppEngineVersionIamMemberGenerated_withAndWithoutCondition(t *tes }, { ResourceName: "google_iap_app_engine_version_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMMemberStateID("google_iap_app_engine_version_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_app_engine_version_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMMemberStateID("google_iap_app_engine_version_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_app_engine_version_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"], context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMMemberStateID("google_iap_app_engine_version_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapAppEngineVersionIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_app_engine_version_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestProjectFromEnv(), "default", context["random_suffix"]), + ImportStateIdFunc: generateIapAppEngineVersionIAMPolicyStateID("google_iap_app_engine_version_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -873,3 +874,59 @@ resource "google_iap_app_engine_version_iam_policy" "foo" { } `, context) } +func generateIapAppEngineVersionIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + versionId := tpgresource.GetResourceNameFromSelfLink(rawState["version_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", project, appId, service, versionId), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapAppEngineVersionIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + versionId := tpgresource.GetResourceNameFromSelfLink(rawState["version_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", project, appId, service, versionId), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapAppEngineVersionIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + service := tpgresource.GetResourceNameFromSelfLink(rawState["service"]) + versionId := tpgresource.GetResourceNameFromSelfLink(rawState["version_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s/services/%s/versions/%s", project, appId, service, versionId), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_tunnel_dest_group_generated_test.go b/google/services/iap/iam_iap_tunnel_dest_group_generated_test.go index 8e7ff65ea15..82c7d62a2ca 100644 --- a/google/services/iap/iam_iap_tunnel_dest_group_generated_test.go +++ b/google/services/iap/iam_iap_tunnel_dest_group_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -596,3 +597,56 @@ resource "google_iap_tunnel_dest_group_iam_policy" "foo" { } `, context) } +func generateIapTunnelDestGroupIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + dest_group := tpgresource.GetResourceNameFromSelfLink(rawState["dest_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/locations/%s/destGroups/%s", project, region, dest_group), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelDestGroupIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + dest_group := tpgresource.GetResourceNameFromSelfLink(rawState["dest_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/locations/%s/destGroups/%s", project, region, dest_group), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelDestGroupIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + dest_group := tpgresource.GetResourceNameFromSelfLink(rawState["dest_group"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/locations/%s/destGroups/%s", project, region, dest_group), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_tunnel_generated_test.go b/google/services/iap/iam_iap_tunnel_generated_test.go index 1d0b4623d3c..a8227a44d17 100644 --- a/google/services/iap/iam_iap_tunnel_generated_test.go +++ b/google/services/iap/iam_iap_tunnel_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -66,7 +67,7 @@ func TestAccIapTunnelIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -76,7 +77,7 @@ func TestAccIapTunnelIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -113,7 +114,7 @@ func TestAccIapTunnelIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMMemberStateID("google_iap_tunnel_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -150,7 +151,7 @@ func TestAccIapTunnelIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMPolicyStateID("google_iap_tunnel_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -159,7 +160,7 @@ func TestAccIapTunnelIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMPolicyStateID("google_iap_tunnel_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -195,7 +196,7 @@ func TestAccIapTunnelIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -233,19 +234,19 @@ func TestAccIapTunnelIamBindingGenerated_withAndWithoutCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapTunnelIAMBindingStateID("google_iap_tunnel_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -281,7 +282,7 @@ func TestAccIapTunnelIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelIAMMemberStateID("google_iap_tunnel_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -319,19 +320,19 @@ func TestAccIapTunnelIamMemberGenerated_withAndWithoutCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMMemberStateID("google_iap_tunnel_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelIAMMemberStateID("google_iap_tunnel_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapTunnelIAMMemberStateID("google_iap_tunnel_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -377,7 +378,7 @@ func TestAccIapTunnelIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelIAMPolicyStateID("google_iap_tunnel_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -786,3 +787,50 @@ resource "google_iap_tunnel_iam_policy" "foo" { } `, context) } +func generateIapTunnelIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel", project), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel", project), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel", project), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_tunnel_instance_generated_test.go b/google/services/iap/iam_iap_tunnel_instance_generated_test.go index 793498c24af..6091f03a58d 100644 --- a/google/services/iap/iam_iap_tunnel_instance_generated_test.go +++ b/google/services/iap/iam_iap_tunnel_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapTunnelInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapTunnelInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapTunnelInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMMemberStateID("google_iap_tunnel_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapTunnelInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMPolicyStateID("google_iap_tunnel_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapTunnelInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMPolicyStateID("google_iap_tunnel_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapTunnelInstanceIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapTunnelInstanceIamBindingGenerated_withAndWithoutCondition(t *test }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_instance_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMBindingStateID("google_iap_tunnel_instance_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapTunnelInstanceIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMMemberStateID("google_iap_tunnel_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapTunnelInstanceIamMemberGenerated_withAndWithoutCondition(t *testi }, { ResourceName: "google_iap_tunnel_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMMemberStateID("google_iap_tunnel_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_instance_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMMemberStateID("google_iap_tunnel_instance_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_tunnel_instance_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapTunnelInstanceIAMMemberStateID("google_iap_tunnel_instance_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapTunnelInstanceIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel-vm%s", context["random_suffix"])), + ImportStateIdFunc: generateIapTunnelInstanceIAMPolicyStateID("google_iap_tunnel_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -718,3 +719,56 @@ resource "google_iap_tunnel_instance_iam_policy" "foo" { } `, context) } +func generateIapTunnelInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance := tpgresource.GetResourceNameFromSelfLink(rawState["instance"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", project, zone, instance), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance := tpgresource.GetResourceNameFromSelfLink(rawState["instance"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", project, zone, instance), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapTunnelInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + zone := tpgresource.GetResourceNameFromSelfLink(rawState["zone"]) + instance := tpgresource.GetResourceNameFromSelfLink(rawState["instance"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", project, zone, instance), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_backend_service_generated_test.go b/google/services/iap/iam_iap_web_backend_service_generated_test.go index e3b15e190fa..b0e246adbb6 100644 --- a/google/services/iap/iam_iap_web_backend_service_generated_test.go +++ b/google/services/iap/iam_iap_web_backend_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapWebBackendServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapWebBackendServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapWebBackendServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMMemberStateID("google_iap_web_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapWebBackendServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMPolicyStateID("google_iap_web_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapWebBackendServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMPolicyStateID("google_iap_web_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapWebBackendServiceIamBindingGenerated_withCondition(t *testing.T) }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapWebBackendServiceIamBindingGenerated_withAndWithoutCondition(t *t }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_backend_service_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMBindingStateID("google_iap_web_backend_service_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapWebBackendServiceIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMMemberStateID("google_iap_web_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapWebBackendServiceIamMemberGenerated_withAndWithoutCondition(t *te }, { ResourceName: "google_iap_web_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMMemberStateID("google_iap_web_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_backend_service_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMMemberStateID("google_iap_web_backend_service_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_backend_service_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebBackendServiceIAMMemberStateID("google_iap_web_backend_service_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapWebBackendServiceIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebBackendServiceIAMPolicyStateID("google_iap_web_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -663,3 +664,53 @@ resource "google_iap_web_backend_service_iam_policy" "foo" { } `, context) } +func generateIapWebBackendServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + web_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute/services/%s", project, web_backend_service), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebBackendServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + web_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute/services/%s", project, web_backend_service), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebBackendServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + web_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute/services/%s", project, web_backend_service), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_cloud_run_service_generated_test.go b/google/services/iap/iam_iap_web_cloud_run_service_generated_test.go index bfb8ac7cbac..5185ae483a4 100644 --- a/google/services/iap/iam_iap_web_cloud_run_service_generated_test.go +++ b/google/services/iap/iam_iap_web_cloud_run_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapWebCloudRunServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapWebCloudRunServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapWebCloudRunServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_cloud_run_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMMemberStateID("google_iap_web_cloud_run_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapWebCloudRunServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_cloud_run_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMPolicyStateID("google_iap_web_cloud_run_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapWebCloudRunServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_cloud_run_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMPolicyStateID("google_iap_web_cloud_run_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapWebCloudRunServiceIamBindingGenerated_withCondition(t *testing.T) }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapWebCloudRunServiceIamBindingGenerated_withAndWithoutCondition(t * }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_cloud_run_service_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMBindingStateID("google_iap_web_cloud_run_service_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapWebCloudRunServiceIamMemberGenerated_withCondition(t *testing.T) }, { ResourceName: "google_iap_web_cloud_run_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMMemberStateID("google_iap_web_cloud_run_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapWebCloudRunServiceIamMemberGenerated_withAndWithoutCondition(t *t }, { ResourceName: "google_iap_web_cloud_run_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMMemberStateID("google_iap_web_cloud_run_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_cloud_run_service_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMMemberStateID("google_iap_web_cloud_run_service_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_cloud_run_service_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMMemberStateID("google_iap_web_cloud_run_service_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapWebCloudRunServiceIamPolicyGenerated_withCondition(t *testing.T) }, { ResourceName: "google_iap_web_cloud_run_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-cloud-run-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebCloudRunServiceIAMPolicyStateID("google_iap_web_cloud_run_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -728,3 +729,56 @@ resource "google_iap_web_cloud_run_service_iam_policy" "foo" { } `, context) } +func generateIapWebCloudRunServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_run_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_run_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", project, location, cloud_run_service_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebCloudRunServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_run_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_run_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", project, location, cloud_run_service_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebCloudRunServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + cloud_run_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["cloud_run_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/cloud_run-%s/services/%s", project, location, cloud_run_service_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_forwarding_rule_service_generated_test.go b/google/services/iap/iam_iap_web_forwarding_rule_service_generated_test.go index 6cad881e19d..4ee0bead754 100644 --- a/google/services/iap/iam_iap_web_forwarding_rule_service_generated_test.go +++ b/google/services/iap/iam_iap_web_forwarding_rule_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapWebForwardingRuleServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapWebForwardingRuleServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapWebForwardingRuleServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMMemberStateID("google_iap_web_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapWebForwardingRuleServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMPolicyStateID("google_iap_web_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapWebForwardingRuleServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMPolicyStateID("google_iap_web_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapWebForwardingRuleServiceIamBindingGenerated_withCondition(t *test }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapWebForwardingRuleServiceIamBindingGenerated_withAndWithoutConditi }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMBindingStateID("google_iap_web_forwarding_rule_service_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapWebForwardingRuleServiceIamMemberGenerated_withCondition(t *testi }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMMemberStateID("google_iap_web_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapWebForwardingRuleServiceIamMemberGenerated_withAndWithoutConditio }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMMemberStateID("google_iap_web_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMMemberStateID("google_iap_web_forwarding_rule_service_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMMemberStateID("google_iap_web_forwarding_rule_service_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapWebForwardingRuleServiceIamPolicyGenerated_withCondition(t *testi }, { ResourceName: "google_iap_web_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebForwardingRuleServiceIAMPolicyStateID("google_iap_web_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -923,3 +924,53 @@ resource "google_iap_web_forwarding_rule_service_iam_policy" "foo" { } `, context) } +func generateIapWebForwardingRuleServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + forwarding_rule_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", project, forwarding_rule_service_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebForwardingRuleServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + forwarding_rule_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", project, forwarding_rule_service_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebForwardingRuleServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + forwarding_rule_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule/services/%s", project, forwarding_rule_service_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_generated_test.go b/google/services/iap/iam_iap_web_generated_test.go index b126f5b93da..decec1af815 100644 --- a/google/services/iap/iam_iap_web_generated_test.go +++ b/google/services/iap/iam_iap_web_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -66,7 +67,7 @@ func TestAccIapWebIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -76,7 +77,7 @@ func TestAccIapWebIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -113,7 +114,7 @@ func TestAccIapWebIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMMemberStateID("google_iap_web_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -150,7 +151,7 @@ func TestAccIapWebIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMPolicyStateID("google_iap_web_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -159,7 +160,7 @@ func TestAccIapWebIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMPolicyStateID("google_iap_web_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -195,7 +196,7 @@ func TestAccIapWebIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -233,19 +234,19 @@ func TestAccIapWebIamBindingGenerated_withAndWithoutCondition(t *testing.T) { }, { ResourceName: "google_iap_web_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebIAMBindingStateID("google_iap_web_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -281,7 +282,7 @@ func TestAccIapWebIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebIAMMemberStateID("google_iap_web_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -319,19 +320,19 @@ func TestAccIapWebIamMemberGenerated_withAndWithoutCondition(t *testing.T) { }, { ResourceName: "google_iap_web_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMMemberStateID("google_iap_web_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebIAMMemberStateID("google_iap_web_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebIAMMemberStateID("google_iap_web_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -377,7 +378,7 @@ func TestAccIapWebIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebIAMPolicyStateID("google_iap_web_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -786,3 +787,50 @@ resource "google_iap_web_iam_policy" "foo" { } `, context) } +func generateIapWebIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web", project), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web", project), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web", project), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_region_backend_service_generated_test.go b/google/services/iap/iam_iap_web_region_backend_service_generated_test.go index 9e7e977ce89..55fb364b539 100644 --- a/google/services/iap/iam_iap_web_region_backend_service_generated_test.go +++ b/google/services/iap/iam_iap_web_region_backend_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapWebRegionBackendServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapWebRegionBackendServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapWebRegionBackendServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMMemberStateID("google_iap_web_region_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapWebRegionBackendServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMPolicyStateID("google_iap_web_region_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapWebRegionBackendServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMPolicyStateID("google_iap_web_region_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapWebRegionBackendServiceIamBindingGenerated_withCondition(t *testi }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapWebRegionBackendServiceIamBindingGenerated_withAndWithoutConditio }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_backend_service_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMBindingStateID("google_iap_web_region_backend_service_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapWebRegionBackendServiceIamMemberGenerated_withCondition(t *testin }, { ResourceName: "google_iap_web_region_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMMemberStateID("google_iap_web_region_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapWebRegionBackendServiceIamMemberGenerated_withAndWithoutCondition }, { ResourceName: "google_iap_web_region_backend_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMMemberStateID("google_iap_web_region_backend_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_backend_service_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMMemberStateID("google_iap_web_region_backend_service_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_backend_service_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMMemberStateID("google_iap_web_region_backend_service_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapWebRegionBackendServiceIamPolicyGenerated_withCondition(t *testin }, { ResourceName: "google_iap_web_region_backend_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-region-backend-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionBackendServiceIAMPolicyStateID("google_iap_web_region_backend_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -738,3 +739,56 @@ resource "google_iap_web_region_backend_service_iam_policy" "foo" { } `, context) } +func generateIapWebRegionBackendServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + web_region_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_region_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", project, region, web_region_backend_service), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebRegionBackendServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + web_region_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_region_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", project, region, web_region_backend_service), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebRegionBackendServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + web_region_backend_service := tpgresource.GetResourceNameFromSelfLink(rawState["web_region_backend_service"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute-%s/services/%s", project, region, web_region_backend_service), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_region_forwarding_rule_service_generated_test.go b/google/services/iap/iam_iap_web_region_forwarding_rule_service_generated_test.go index fb1f751e45f..cad4acf4737 100644 --- a/google/services/iap/iam_iap_web_region_forwarding_rule_service_generated_test.go +++ b/google/services/iap/iam_iap_web_region_forwarding_rule_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMMemberStateID("google_iap_web_region_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMPolicyStateID("google_iap_web_region_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMPolicyStateID("google_iap_web_region_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamBindingGenerated_withCondition(t }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccIapWebRegionForwardingRuleServiceIamBindingGenerated_withAndWithoutC }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMBindingStateID("google_iap_web_region_forwarding_rule_service_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamMemberGenerated_withCondition(t }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMMemberStateID("google_iap_web_region_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccIapWebRegionForwardingRuleServiceIamMemberGenerated_withAndWithoutCo }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMMemberStateID("google_iap_web_region_forwarding_rule_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMMemberStateID("google_iap_web_region_forwarding_rule_service_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMMemberStateID("google_iap_web_region_forwarding_rule_service_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccIapWebRegionForwardingRuleServiceIamPolicyGenerated_withCondition(t }, { ResourceName: "google_iap_web_region_forwarding_rule_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-forwarding-rule-region-service%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebRegionForwardingRuleServiceIAMPolicyStateID("google_iap_web_region_forwarding_rule_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -1058,3 +1059,56 @@ resource "google_iap_web_region_forwarding_rule_service_iam_policy" "foo" { } `, context) } +func generateIapWebRegionForwardingRuleServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + forwarding_rule_region_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_region_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", project, region, forwarding_rule_region_service_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebRegionForwardingRuleServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + forwarding_rule_region_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_region_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", project, region, forwarding_rule_region_service_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebRegionForwardingRuleServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + region := tpgresource.GetResourceNameFromSelfLink(rawState["region"]) + forwarding_rule_region_service_name := tpgresource.GetResourceNameFromSelfLink(rawState["forwarding_rule_region_service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/forwarding_rule-%s/services/%s", project, region, forwarding_rule_region_service_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_type_app_engine_generated_test.go b/google/services/iap/iam_iap_web_type_app_engine_generated_test.go index 0f81d388dfd..a98c3990daa 100644 --- a/google/services/iap/iam_iap_web_type_app_engine_generated_test.go +++ b/google/services/iap/iam_iap_web_type_app_engine_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -68,7 +69,7 @@ func TestAccIapWebTypeAppEngineIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -78,7 +79,7 @@ func TestAccIapWebTypeAppEngineIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccIapWebTypeAppEngineIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMMemberStateID("google_iap_web_type_app_engine_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -156,7 +157,7 @@ func TestAccIapWebTypeAppEngineIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMPolicyStateID("google_iap_web_type_app_engine_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -165,7 +166,7 @@ func TestAccIapWebTypeAppEngineIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMPolicyStateID("google_iap_web_type_app_engine_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,7 +204,7 @@ func TestAccIapWebTypeAppEngineIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor %s", context["project_id"], context["project_id"], context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -243,19 +244,19 @@ func TestAccIapWebTypeAppEngineIamBindingGenerated_withAndWithoutCondition(t *te }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor %s", context["project_id"], context["project_id"], context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_app_engine_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor %s", context["project_id"], context["project_id"], context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMBindingStateID("google_iap_web_type_app_engine_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -293,7 +294,7 @@ func TestAccIapWebTypeAppEngineIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", context["project_id"], context["project_id"], context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMMemberStateID("google_iap_web_type_app_engine_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -333,19 +334,19 @@ func TestAccIapWebTypeAppEngineIamMemberGenerated_withAndWithoutCondition(t *tes }, { ResourceName: "google_iap_web_type_app_engine_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMMemberStateID("google_iap_web_type_app_engine_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_app_engine_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", context["project_id"], context["project_id"], context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMMemberStateID("google_iap_web_type_app_engine_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_app_engine_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", context["project_id"], context["project_id"], context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMMemberStateID("google_iap_web_type_app_engine_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -393,7 +394,7 @@ func TestAccIapWebTypeAppEngineIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_app_engine_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/appengine-%s", context["project_id"], context["project_id"]), + ImportStateIdFunc: generateIapWebTypeAppEngineIAMPolicyStateID("google_iap_web_type_app_engine_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -887,3 +888,53 @@ resource "google_iap_web_type_app_engine_iam_policy" "foo" { } `, context) } +func generateIapWebTypeAppEngineIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s", project, appId), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebTypeAppEngineIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s", project, appId), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebTypeAppEngineIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + appId := tpgresource.GetResourceNameFromSelfLink(rawState["app_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/appengine-%s", project, appId), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/iap/iam_iap_web_type_compute_generated_test.go b/google/services/iap/iam_iap_web_type_compute_generated_test.go index 533aeaa8393..ef60af06fad 100644 --- a/google/services/iap/iam_iap_web_type_compute_generated_test.go +++ b/google/services/iap/iam_iap_web_type_compute_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -66,7 +67,7 @@ func TestAccIapWebTypeComputeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -76,7 +77,7 @@ func TestAccIapWebTypeComputeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -113,7 +114,7 @@ func TestAccIapWebTypeComputeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMMemberStateID("google_iap_web_type_compute_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -150,7 +151,7 @@ func TestAccIapWebTypeComputeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMPolicyStateID("google_iap_web_type_compute_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -159,7 +160,7 @@ func TestAccIapWebTypeComputeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMPolicyStateID("google_iap_web_type_compute_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -195,7 +196,7 @@ func TestAccIapWebTypeComputeIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -233,19 +234,19 @@ func TestAccIapWebTypeComputeIamBindingGenerated_withAndWithoutCondition(t *test }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_compute_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMBindingStateID("google_iap_web_type_compute_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -281,7 +282,7 @@ func TestAccIapWebTypeComputeIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMMemberStateID("google_iap_web_type_compute_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -319,19 +320,19 @@ func TestAccIapWebTypeComputeIamMemberGenerated_withAndWithoutCondition(t *testi }, { ResourceName: "google_iap_web_type_compute_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor user:admin@hashicorptest.com", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMMemberStateID("google_iap_web_type_compute_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_compute_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMMemberStateID("google_iap_web_type_compute_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_iap_web_type_compute_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute roles/iap.httpsResourceAccessor user:admin@hashicorptest.com %s", fmt.Sprintf("tf-test%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateIapWebTypeComputeIAMMemberStateID("google_iap_web_type_compute_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -377,7 +378,7 @@ func TestAccIapWebTypeComputeIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_iap_web_type_compute_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/iap_web/compute", fmt.Sprintf("tf-test%s", context["random_suffix"])), + ImportStateIdFunc: generateIapWebTypeComputeIAMPolicyStateID("google_iap_web_type_compute_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -786,3 +787,50 @@ resource "google_iap_web_type_compute_iam_policy" "foo" { } `, context) } +func generateIapWebTypeComputeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute", project), "", "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebTypeComputeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute", project), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateIapWebTypeComputeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/iap_web/compute", project), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/logging/iam_logging_log_view_generated_test.go b/google/services/logging/iam_logging_log_view_generated_test.go index 04b61aecb58..23fa2bb6d27 100644 --- a/google/services/logging/iam_logging_log_view_generated_test.go +++ b/google/services/logging/iam_logging_log_view_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -645,3 +646,59 @@ resource "google_logging_log_view_iam_policy" "foo" { } `, context) } +func generateLoggingLogViewIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + parent := rawState["parent"] + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + bucket := tpgresource.GetResourceNameFromSelfLink(rawState["bucket"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/locations/%s/buckets/%s/views/%s", parent, location, bucket, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateLoggingLogViewIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + parent := rawState["parent"] + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + bucket := tpgresource.GetResourceNameFromSelfLink(rawState["bucket"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/locations/%s/buckets/%s/views/%s", parent, location, bucket, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateLoggingLogViewIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + parent := rawState["parent"] + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + bucket := tpgresource.GetResourceNameFromSelfLink(rawState["bucket"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("%s/locations/%s/buckets/%s/views/%s", parent, location, bucket, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/networksecurity/iam_network_security_address_group_generated_test.go b/google/services/networksecurity/iam_network_security_address_group_generated_test.go index 07d2b748f5a..90df6be90da 100644 --- a/google/services/networksecurity/iam_network_security_address_group_generated_test.go +++ b/google/services/networksecurity/iam_network_security_address_group_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -228,3 +229,57 @@ name = google_network_security_address_group.default.name } `, context) } + +func generateNetworkSecurityProjectAddressGroupIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/addressGroups/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateNetworkSecurityProjectAddressGroupIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/addressGroups/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateNetworkSecurityProjectAddressGroupIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/addressGroups/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/notebooks/iam_notebooks_instance_generated_test.go b/google/services/notebooks/iam_notebooks_instance_generated_test.go index e89c8f97d55..d46dddcdce2 100644 --- a/google/services/notebooks/iam_notebooks_instance_generated_test.go +++ b/google/services/notebooks/iam_notebooks_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccNotebooksInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-notebooks-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksInstanceIAMBindingStateID("google_notebooks_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccNotebooksInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-notebooks-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksInstanceIAMBindingStateID("google_notebooks_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccNotebooksInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-notebooks-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksInstanceIAMMemberStateID("google_notebooks_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccNotebooksInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-notebooks-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksInstanceIAMPolicyStateID("google_notebooks_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccNotebooksInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-notebooks-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksInstanceIAMPolicyStateID("google_notebooks_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -260,3 +261,57 @@ resource "google_notebooks_instance_iam_binding" "foo" { } `, context) } + +func generateNotebooksInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateNotebooksInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateNotebooksInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_name := tpgresource.GetResourceNameFromSelfLink(rawState["instance_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/notebooks/iam_notebooks_runtime_generated_test.go b/google/services/notebooks/iam_notebooks_runtime_generated_test.go index d0b7d4687da..48d76299727 100644 --- a/google/services/notebooks/iam_notebooks_runtime_generated_test.go +++ b/google/services/notebooks/iam_notebooks_runtime_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccNotebooksRuntimeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_runtime_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/runtimes/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-central1", fmt.Sprintf("tf-test-notebooks-runtime%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksRuntimeIAMBindingStateID("google_notebooks_runtime_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccNotebooksRuntimeIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_runtime_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/runtimes/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-central1", fmt.Sprintf("tf-test-notebooks-runtime%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksRuntimeIAMBindingStateID("google_notebooks_runtime_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccNotebooksRuntimeIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_runtime_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/runtimes/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "us-central1", fmt.Sprintf("tf-test-notebooks-runtime%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksRuntimeIAMMemberStateID("google_notebooks_runtime_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccNotebooksRuntimeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_runtime_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/runtimes/%s", envvar.GetTestProjectFromEnv(), "us-central1", fmt.Sprintf("tf-test-notebooks-runtime%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksRuntimeIAMPolicyStateID("google_notebooks_runtime_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccNotebooksRuntimeIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_notebooks_runtime_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/runtimes/%s", envvar.GetTestProjectFromEnv(), "us-central1", fmt.Sprintf("tf-test-notebooks-runtime%s", context["random_suffix"])), + ImportStateIdFunc: generateNotebooksRuntimeIAMPolicyStateID("google_notebooks_runtime_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -310,3 +311,57 @@ resource "google_notebooks_runtime_iam_binding" "foo" { } `, context) } + +func generateNotebooksRuntimeIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_name := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/runtimes/%s", project, location, runtime_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateNotebooksRuntimeIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_name := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/runtimes/%s", project, location, runtime_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateNotebooksRuntimeIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + runtime_name := tpgresource.GetResourceNameFromSelfLink(rawState["runtime_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/runtimes/%s", project, location, runtime_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/privateca/iam_privateca_ca_pool_generated_test.go b/google/services/privateca/iam_privateca_ca_pool_generated_test.go index a2f2044e923..cd3692f5c70 100644 --- a/google/services/privateca/iam_privateca_ca_pool_generated_test.go +++ b/google/services/privateca/iam_privateca_ca_pool_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccPrivatecaCaPoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccPrivatecaCaPoolIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccPrivatecaCaPoolIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMMemberStateID("google_privateca_ca_pool_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccPrivatecaCaPoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMPolicyStateID("google_privateca_ca_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccPrivatecaCaPoolIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMPolicyStateID("google_privateca_ca_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccPrivatecaCaPoolIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccPrivatecaCaPoolIamBindingGenerated_withAndWithoutCondition(t *testin }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_ca_pool_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMBindingStateID("google_privateca_ca_pool_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccPrivatecaCaPoolIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMMemberStateID("google_privateca_ca_pool_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccPrivatecaCaPoolIamMemberGenerated_withAndWithoutCondition(t *testing }, { ResourceName: "google_privateca_ca_pool_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMMemberStateID("google_privateca_ca_pool_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_ca_pool_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMMemberStateID("google_privateca_ca_pool_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_ca_pool_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s roles/privateca.certificateManager user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generatePrivatecaCaPoolIAMMemberStateID("google_privateca_ca_pool_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccPrivatecaCaPoolIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_privateca_ca_pool_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/caPools/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-pool%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCaPoolIAMPolicyStateID("google_privateca_ca_pool_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -658,3 +659,56 @@ resource "google_privateca_ca_pool_iam_policy" "foo" { } `, context) } +func generatePrivatecaCaPoolIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + ca_pool := tpgresource.GetResourceNameFromSelfLink(rawState["ca_pool"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/caPools/%s", project, location, ca_pool), "", "", rawState["condition.0.title"]), nil + } +} + +func generatePrivatecaCaPoolIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + ca_pool := tpgresource.GetResourceNameFromSelfLink(rawState["ca_pool"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/caPools/%s", project, location, ca_pool), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generatePrivatecaCaPoolIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + ca_pool := tpgresource.GetResourceNameFromSelfLink(rawState["ca_pool"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/caPools/%s", project, location, ca_pool), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/privateca/iam_privateca_certificate_template_generated_test.go b/google/services/privateca/iam_privateca_certificate_template_generated_test.go index 2645cef6251..0fbc3d5c844 100644 --- a/google/services/privateca/iam_privateca_certificate_template_generated_test.go +++ b/google/services/privateca/iam_privateca_certificate_template_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccPrivatecaCertificateTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccPrivatecaCertificateTemplateIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccPrivatecaCertificateTemplateIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_privateca_certificate_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMMemberStateID("google_privateca_certificate_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccPrivatecaCertificateTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_privateca_certificate_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMPolicyStateID("google_privateca_certificate_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccPrivatecaCertificateTemplateIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_privateca_certificate_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMPolicyStateID("google_privateca_certificate_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccPrivatecaCertificateTemplateIamBindingGenerated_withCondition(t *tes }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccPrivatecaCertificateTemplateIamBindingGenerated_withAndWithoutCondit }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_certificate_template_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMBindingStateID("google_privateca_certificate_template_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccPrivatecaCertificateTemplateIamMemberGenerated_withCondition(t *test }, { ResourceName: "google_privateca_certificate_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMMemberStateID("google_privateca_certificate_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccPrivatecaCertificateTemplateIamMemberGenerated_withAndWithoutConditi }, { ResourceName: "google_privateca_certificate_template_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMMemberStateID("google_privateca_certificate_template_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_certificate_template_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMMemberStateID("google_privateca_certificate_template_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_privateca_certificate_template_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMMemberStateID("google_privateca_certificate_template_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccPrivatecaCertificateTemplateIamPolicyGenerated_withCondition(t *test }, { ResourceName: "google_privateca_certificate_template_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportStateIdFunc: generatePrivatecaCertificateTemplateIAMPolicyStateID("google_privateca_certificate_template_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -1258,3 +1259,56 @@ resource "google_privateca_certificate_template_iam_policy" "foo" { } `, context) } +func generatePrivatecaCertificateTemplateIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + certificate_template := tpgresource.GetResourceNameFromSelfLink(rawState["certificate_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", project, location, certificate_template), "", "", rawState["condition.0.title"]), nil + } +} + +func generatePrivatecaCertificateTemplateIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + certificate_template := tpgresource.GetResourceNameFromSelfLink(rawState["certificate_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", project, location, certificate_template), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generatePrivatecaCertificateTemplateIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + certificate_template := tpgresource.GetResourceNameFromSelfLink(rawState["certificate_template"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", project, location, certificate_template), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/pubsub/iam_pubsub_schema_generated_test.go b/google/services/pubsub/iam_pubsub_schema_generated_test.go index 7fb6b823676..79b90941a27 100644 --- a/google/services/pubsub/iam_pubsub_schema_generated_test.go +++ b/google/services/pubsub/iam_pubsub_schema_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccPubsubSchemaIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_schema_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/schemas/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-schema%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubSchemaIAMBindingStateID("google_pubsub_schema_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccPubsubSchemaIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_schema_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/schemas/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-schema%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubSchemaIAMBindingStateID("google_pubsub_schema_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccPubsubSchemaIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_schema_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/schemas/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-schema%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubSchemaIAMMemberStateID("google_pubsub_schema_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccPubsubSchemaIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_schema_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/schemas/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-schema%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubSchemaIAMPolicyStateID("google_pubsub_schema_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccPubsubSchemaIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_schema_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/schemas/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-schema%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubSchemaIAMPolicyStateID("google_pubsub_schema_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -234,3 +235,54 @@ resource "google_pubsub_schema_iam_binding" "foo" { } `, context) } + +func generatePubsubSchemaIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + schema := tpgresource.GetResourceNameFromSelfLink(rawState["schema"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/schemas/%s", project, schema), "", "", rawState["condition.0.title"]), nil + } +} + +func generatePubsubSchemaIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + schema := tpgresource.GetResourceNameFromSelfLink(rawState["schema"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/schemas/%s", project, schema), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generatePubsubSchemaIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + schema := tpgresource.GetResourceNameFromSelfLink(rawState["schema"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/schemas/%s", project, schema), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/pubsub/iam_pubsub_topic_generated_test.go b/google/services/pubsub/iam_pubsub_topic_generated_test.go index 82cf4d6d40b..2e269108140 100644 --- a/google/services/pubsub/iam_pubsub_topic_generated_test.go +++ b/google/services/pubsub/iam_pubsub_topic_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccPubsubTopicIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_topic_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/topics/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-topic%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubTopicIAMBindingStateID("google_pubsub_topic_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccPubsubTopicIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_topic_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/topics/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-topic%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubTopicIAMBindingStateID("google_pubsub_topic_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccPubsubTopicIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_topic_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/topics/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-topic%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubTopicIAMMemberStateID("google_pubsub_topic_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccPubsubTopicIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_topic_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/topics/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-topic%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubTopicIAMPolicyStateID("google_pubsub_topic_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccPubsubTopicIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_pubsub_topic_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/topics/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-example-topic%s", context["random_suffix"])), + ImportStateIdFunc: generatePubsubTopicIAMPolicyStateID("google_pubsub_topic_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -254,3 +255,54 @@ resource "google_pubsub_topic_iam_binding" "foo" { } `, context) } + +func generatePubsubTopicIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + topic := tpgresource.GetResourceNameFromSelfLink(rawState["topic"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/topics/%s", project, topic), "", "", rawState["condition.0.title"]), nil + } +} + +func generatePubsubTopicIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + topic := tpgresource.GetResourceNameFromSelfLink(rawState["topic"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/topics/%s", project, topic), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generatePubsubTopicIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + topic := tpgresource.GetResourceNameFromSelfLink(rawState["topic"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/topics/%s", project, topic), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/secretmanager/iam_secret_manager_secret_generated_test.go b/google/services/secretmanager/iam_secret_manager_secret_generated_test.go index 927e1242518..e03f3a9811a 100644 --- a/google/services/secretmanager/iam_secret_manager_secret_generated_test.go +++ b/google/services/secretmanager/iam_secret_manager_secret_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccSecretManagerSecretIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccSecretManagerSecretIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccSecretManagerSecretIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMMemberStateID("google_secret_manager_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccSecretManagerSecretIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMPolicyStateID("google_secret_manager_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccSecretManagerSecretIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMPolicyStateID("google_secret_manager_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccSecretManagerSecretIamBindingGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccSecretManagerSecretIamBindingGenerated_withAndWithoutCondition(t *te }, { ResourceName: "google_secret_manager_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_secret_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_secret_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateSecretManagerSecretIAMBindingStateID("google_secret_manager_secret_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccSecretManagerSecretIamMemberGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerSecretIAMMemberStateID("google_secret_manager_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccSecretManagerSecretIamMemberGenerated_withAndWithoutCondition(t *tes }, { ResourceName: "google_secret_manager_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMMemberStateID("google_secret_manager_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_secret_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerSecretIAMMemberStateID("google_secret_manager_secret_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_secret_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateSecretManagerSecretIAMMemberStateID("google_secret_manager_secret_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccSecretManagerSecretIamPolicyGenerated_withCondition(t *testing.T) { }, { ResourceName: "google_secret_manager_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/secrets/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerSecretIAMPolicyStateID("google_secret_manager_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -743,3 +744,53 @@ resource "google_secret_manager_secret_iam_policy" "foo" { } `, context) } +func generateSecretManagerSecretIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/secrets/%s", project, secret_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateSecretManagerSecretIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/secrets/%s", project, secret_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateSecretManagerSecretIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/secrets/%s", project, secret_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/secretmanagerregional/iam_secret_manager_regional_secret_generated_test.go b/google/services/secretmanagerregional/iam_secret_manager_regional_secret_generated_test.go index da63854fcee..bdd49a78a0a 100644 --- a/google/services/secretmanagerregional/iam_secret_manager_regional_secret_generated_test.go +++ b/google/services/secretmanagerregional/iam_secret_manager_regional_secret_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -60,7 +61,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamBindingGenerated(t *testing.T) }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -70,7 +71,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamBindingGenerated(t *testing.T) }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -101,7 +102,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamMemberGenerated(t *testing.T) }, { ResourceName: "google_secret_manager_regional_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMMemberStateID("google_secret_manager_regional_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamPolicyGenerated(t *testing.T) }, { ResourceName: "google_secret_manager_regional_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMPolicyStateID("google_secret_manager_regional_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -141,7 +142,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamPolicyGenerated(t *testing.T) }, { ResourceName: "google_secret_manager_regional_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMPolicyStateID("google_secret_manager_regional_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -171,7 +172,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamBindingGenerated_withCondition }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -203,19 +204,19 @@ func TestAccSecretManagerRegionalRegionalSecretIamBindingGenerated_withAndWithou }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_regional_secret_iam_binding.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMBindingStateID("google_secret_manager_regional_secret_iam_binding.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -245,7 +246,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamMemberGenerated_withCondition( }, { ResourceName: "google_secret_manager_regional_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMMemberStateID("google_secret_manager_regional_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -277,19 +278,19 @@ func TestAccSecretManagerRegionalRegionalSecretIamMemberGenerated_withAndWithout }, { ResourceName: "google_secret_manager_regional_secret_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMMemberStateID("google_secret_manager_regional_secret_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_regional_secret_iam_member.foo2", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMMemberStateID("google_secret_manager_regional_secret_iam_member.foo2"), ImportState: true, ImportStateVerify: true, }, { ResourceName: "google_secret_manager_regional_secret_iam_member.foo3", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s roles/secretmanager.secretAccessor user:admin@hashicorptest.com %s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"]), context["condition_title_no_desc"]), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMMemberStateID("google_secret_manager_regional_secret_iam_member.foo3"), ImportState: true, ImportStateVerify: true, }, @@ -329,7 +330,7 @@ func TestAccSecretManagerRegionalRegionalSecretIamPolicyGenerated_withCondition( }, { ResourceName: "google_secret_manager_regional_secret_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/secrets/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-tf-reg-secret%s", context["random_suffix"])), + ImportStateIdFunc: generateSecretManagerRegionalRegionalSecretIAMPolicyStateID("google_secret_manager_regional_secret_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -718,3 +719,56 @@ resource "google_secret_manager_regional_secret_iam_policy" "foo" { } `, context) } +func generateSecretManagerRegionalRegionalSecretIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/secrets/%s", project, location, secret_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateSecretManagerRegionalRegionalSecretIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/secrets/%s", project, location, secret_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateSecretManagerRegionalRegionalSecretIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + secret_id := tpgresource.GetResourceNameFromSelfLink(rawState["secret_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/secrets/%s", project, location, secret_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/securesourcemanager/iam_secure_source_manager_instance_generated_test.go b/google/services/securesourcemanager/iam_secure_source_manager_instance_generated_test.go index 9bc44c774e9..e42b48d3a98 100644 --- a/google/services/securesourcemanager/iam_secure_source_manager_instance_generated_test.go +++ b/google/services/securesourcemanager/iam_secure_source_manager_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -57,7 +58,7 @@ func TestAccSecureSourceManagerInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/securesourcemanager.instanceManager", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerInstanceIAMBindingStateID("google_secure_source_manager_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -67,7 +68,7 @@ func TestAccSecureSourceManagerInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/securesourcemanager.instanceManager", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerInstanceIAMBindingStateID("google_secure_source_manager_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -95,7 +96,7 @@ func TestAccSecureSourceManagerInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/securesourcemanager.instanceManager user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerInstanceIAMMemberStateID("google_secure_source_manager_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccSecureSourceManagerInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerInstanceIAMPolicyStateID("google_secure_source_manager_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -135,7 +136,7 @@ func TestAccSecureSourceManagerInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerInstanceIAMPolicyStateID("google_secure_source_manager_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -278,3 +279,57 @@ resource "google_secure_source_manager_instance_iam_binding" "foo" { } `, context) } + +func generateSecureSourceManagerInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_id := tpgresource.GetResourceNameFromSelfLink(rawState["instance_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateSecureSourceManagerInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_id := tpgresource.GetResourceNameFromSelfLink(rawState["instance_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateSecureSourceManagerInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + instance_id := tpgresource.GetResourceNameFromSelfLink(rawState["instance_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/securesourcemanager/iam_secure_source_manager_repository_generated_test.go b/google/services/securesourcemanager/iam_secure_source_manager_repository_generated_test.go index 9bf5cad9694..c9dc7157513 100644 --- a/google/services/securesourcemanager/iam_secure_source_manager_repository_generated_test.go +++ b/google/services/securesourcemanager/iam_secure_source_manager_repository_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccSecureSourceManagerRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/securesourcemanager.repoAdmin", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerRepositoryIAMBindingStateID("google_secure_source_manager_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccSecureSourceManagerRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/securesourcemanager.repoAdmin", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerRepositoryIAMBindingStateID("google_secure_source_manager_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccSecureSourceManagerRepositoryIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_repository_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/securesourcemanager.repoAdmin user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerRepositoryIAMMemberStateID("google_secure_source_manager_repository_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccSecureSourceManagerRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerRepositoryIAMPolicyStateID("google_secure_source_manager_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccSecureSourceManagerRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_secure_source_manager_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-my-repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSecureSourceManagerRepositoryIAMPolicyStateID("google_secure_source_manager_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -298,3 +299,57 @@ resource "google_secure_source_manager_repository_iam_binding" "foo" { } `, context) } + +func generateSecureSourceManagerRepositoryIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository_id := tpgresource.GetResourceNameFromSelfLink(rawState["repository_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateSecureSourceManagerRepositoryIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository_id := tpgresource.GetResourceNameFromSelfLink(rawState["repository_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateSecureSourceManagerRepositoryIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + repository_id := tpgresource.GetResourceNameFromSelfLink(rawState["repository_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/servicedirectory/iam_service_directory_namespace_generated_test.go b/google/services/servicedirectory/iam_service_directory_namespace_generated_test.go index fccc6c35a47..1ac13609e3e 100644 --- a/google/services/servicedirectory/iam_service_directory_namespace_generated_test.go +++ b/google/services/servicedirectory/iam_service_directory_namespace_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -218,3 +219,57 @@ resource "google_service_directory_namespace_iam_binding" "foo" { } `, context) } + +func generateServiceDirectoryNamespaceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", project, location, namespace_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateServiceDirectoryNamespaceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", project, location, namespace_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateServiceDirectoryNamespaceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", project, location, namespace_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/servicedirectory/iam_service_directory_service_generated_test.go b/google/services/servicedirectory/iam_service_directory_service_generated_test.go index 23cf2cfe1b1..fee756bce88 100644 --- a/google/services/servicedirectory/iam_service_directory_service_generated_test.go +++ b/google/services/servicedirectory/iam_service_directory_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -243,3 +244,60 @@ resource "google_service_directory_service_iam_binding" "foo" { } `, context) } + +func generateServiceDirectoryServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s/services/%s", project, location, namespace_id, service_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateServiceDirectoryServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s/services/%s", project, location, namespace_id, service_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateServiceDirectoryServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + namespace_id := tpgresource.GetResourceNameFromSelfLink(rawState["namespace_id"]) + service_id := tpgresource.GetResourceNameFromSelfLink(rawState["service_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/namespaces/%s/services/%s", project, location, namespace_id, service_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/servicemanagement/iam_endpoints_service_consumers_generated_test.go b/google/services/servicemanagement/iam_endpoints_service_consumers_generated_test.go index cbebe1cd09f..b4de8ffaf2f 100644 --- a/google/services/servicemanagement/iam_endpoints_service_consumers_generated_test.go +++ b/google/services/servicemanagement/iam_endpoints_service_consumers_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -57,7 +58,7 @@ func TestAccServiceManagementServiceConsumersIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_consumers_iam_binding.foo", - ImportStateId: fmt.Sprintf("services/%s/consumers/%s roles/servicemanagement.serviceController", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"]), context["project_name"]), + ImportStateIdFunc: generateServiceManagementServiceConsumersIAMBindingStateID("google_endpoints_service_consumers_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -67,7 +68,7 @@ func TestAccServiceManagementServiceConsumersIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_consumers_iam_binding.foo", - ImportStateId: fmt.Sprintf("services/%s/consumers/%s roles/servicemanagement.serviceController", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"]), context["project_name"]), + ImportStateIdFunc: generateServiceManagementServiceConsumersIAMBindingStateID("google_endpoints_service_consumers_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -95,7 +96,7 @@ func TestAccServiceManagementServiceConsumersIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_consumers_iam_member.foo", - ImportStateId: fmt.Sprintf("services/%s/consumers/%s roles/servicemanagement.serviceController user:admin@hashicorptest.com", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"]), context["project_name"]), + ImportStateIdFunc: generateServiceManagementServiceConsumersIAMMemberStateID("google_endpoints_service_consumers_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -123,7 +124,7 @@ func TestAccServiceManagementServiceConsumersIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_consumers_iam_policy.foo", - ImportStateId: fmt.Sprintf("services/%s/consumers/%s", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"]), context["project_name"]), + ImportStateIdFunc: generateServiceManagementServiceConsumersIAMPolicyStateID("google_endpoints_service_consumers_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -132,7 +133,7 @@ func TestAccServiceManagementServiceConsumersIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_consumers_iam_policy.foo", - ImportStateId: fmt.Sprintf("services/%s/consumers/%s", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"]), context["project_name"]), + ImportStateIdFunc: generateServiceManagementServiceConsumersIAMPolicyStateID("google_endpoints_service_consumers_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -285,3 +286,54 @@ resource "google_endpoints_service_consumers_iam_binding" "foo" { } `, context) } + +func generateServiceManagementServiceConsumersIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + consumer_project := tpgresource.GetResourceNameFromSelfLink(rawState["consumer_project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s/consumers/%s", service_name, consumer_project), "", "", rawState["condition.0.title"]), nil + } +} + +func generateServiceManagementServiceConsumersIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + consumer_project := tpgresource.GetResourceNameFromSelfLink(rawState["consumer_project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s/consumers/%s", service_name, consumer_project), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateServiceManagementServiceConsumersIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + consumer_project := tpgresource.GetResourceNameFromSelfLink(rawState["consumer_project"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s/consumers/%s", service_name, consumer_project), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/servicemanagement/iam_endpoints_service_generated_test.go b/google/services/servicemanagement/iam_endpoints_service_generated_test.go index 994bc975555..3274a560f42 100644 --- a/google/services/servicemanagement/iam_endpoints_service_generated_test.go +++ b/google/services/servicemanagement/iam_endpoints_service_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -56,7 +57,7 @@ func TestAccServiceManagementServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("services/%s roles/viewer", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"])), + ImportStateIdFunc: generateServiceManagementServiceIAMBindingStateID("google_endpoints_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -66,7 +67,7 @@ func TestAccServiceManagementServiceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_iam_binding.foo", - ImportStateId: fmt.Sprintf("services/%s roles/viewer", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"])), + ImportStateIdFunc: generateServiceManagementServiceIAMBindingStateID("google_endpoints_service_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -93,7 +94,7 @@ func TestAccServiceManagementServiceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_iam_member.foo", - ImportStateId: fmt.Sprintf("services/%s roles/viewer user:admin@hashicorptest.com", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"])), + ImportStateIdFunc: generateServiceManagementServiceIAMMemberStateID("google_endpoints_service_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -120,7 +121,7 @@ func TestAccServiceManagementServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("services/%s", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"])), + ImportStateIdFunc: generateServiceManagementServiceIAMPolicyStateID("google_endpoints_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -129,7 +130,7 @@ func TestAccServiceManagementServiceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_endpoints_service_iam_policy.foo", - ImportStateId: fmt.Sprintf("services/%s", fmt.Sprintf("endpoint%s.endpoints.%s.cloud.goog", context["random_suffix"], context["project_name"])), + ImportStateIdFunc: generateServiceManagementServiceIAMPolicyStateID("google_endpoints_service_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -276,3 +277,51 @@ resource "google_endpoints_service_iam_binding" "foo" { } `, context) } + +func generateServiceManagementServiceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s", service_name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateServiceManagementServiceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s", service_name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateServiceManagementServiceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + service_name := tpgresource.GetResourceNameFromSelfLink(rawState["service_name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("services/%s", service_name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/sourcerepo/iam_sourcerepo_repository_generated_test.go b/google/services/sourcerepo/iam_sourcerepo_repository_generated_test.go index ddbe2a5bd02..ad034425af1 100644 --- a/google/services/sourcerepo/iam_sourcerepo_repository_generated_test.go +++ b/google/services/sourcerepo/iam_sourcerepo_repository_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccSourceRepoRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("my/repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSourceRepoRepositoryIAMBindingStateID("google_sourcerepo_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccSourceRepoRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("my/repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSourceRepoRepositoryIAMBindingStateID("google_sourcerepo_repository_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccSourceRepoRepositoryIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("my/repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSourceRepoRepositoryIAMMemberStateID("google_sourcerepo_repository_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccSourceRepoRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("my/repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSourceRepoRepositoryIAMPolicyStateID("google_sourcerepo_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccSourceRepoRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("my/repository%s", context["random_suffix"])), + ImportStateIdFunc: generateSourceRepoRepositoryIAMPolicyStateID("google_sourcerepo_repository_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -224,3 +225,54 @@ resource "google_sourcerepo_repository_iam_binding" "foo" { } `, context) } + +func generateSourceRepoRepositoryIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := rawState["name"] + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/repos/%s", project, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateSourceRepoRepositoryIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := rawState["name"] + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/repos/%s", project, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateSourceRepoRepositoryIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + name := rawState["name"] + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/repos/%s", project, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google/services/workbench/iam_workbench_instance_generated_test.go b/google/services/workbench/iam_workbench_instance_generated_test.go index 893440fd7d8..e32331b7805 100644 --- a/google/services/workbench/iam_workbench_instance_generated_test.go +++ b/google/services/workbench/iam_workbench_instance_generated_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" @@ -55,7 +56,7 @@ func TestAccWorkbenchInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_workbench_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-workbench-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateWorkbenchInstanceIAMBindingStateID("google_workbench_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -65,7 +66,7 @@ func TestAccWorkbenchInstanceIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_workbench_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-workbench-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateWorkbenchInstanceIAMBindingStateID("google_workbench_instance_iam_binding.foo"), ImportState: true, ImportStateVerify: true, }, @@ -91,7 +92,7 @@ func TestAccWorkbenchInstanceIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_workbench_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-workbench-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateWorkbenchInstanceIAMMemberStateID("google_workbench_instance_iam_member.foo"), ImportState: true, ImportStateVerify: true, }, @@ -117,7 +118,7 @@ func TestAccWorkbenchInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_workbench_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-workbench-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateWorkbenchInstanceIAMPolicyStateID("google_workbench_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -126,7 +127,7 @@ func TestAccWorkbenchInstanceIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_workbench_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/locations/%s/instances/%s", envvar.GetTestProjectFromEnv(), "us-west1-a", fmt.Sprintf("tf-test-workbench-instance%s", context["random_suffix"])), + ImportStateIdFunc: generateWorkbenchInstanceIAMPolicyStateID("google_workbench_instance_iam_policy.foo"), ImportState: true, ImportStateVerify: true, }, @@ -235,3 +236,57 @@ resource "google_workbench_instance_iam_binding" "foo" { } `, context) } + +func generateWorkbenchInstanceIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, name), "", "", rawState["condition.0.title"]), nil + } +} + +func generateWorkbenchInstanceIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, name), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateWorkbenchInstanceIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + name := tpgresource.GetResourceNameFromSelfLink(rawState["name"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, name), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/website/docs/r/data_fusion_instance_iam.html.markdown b/website/docs/r/data_fusion_instance_iam.html.markdown index 8220cca3196..be232ae95ea 100644 --- a/website/docs/r/data_fusion_instance_iam.html.markdown +++ b/website/docs/r/data_fusion_instance_iam.html.markdown @@ -128,9 +128,9 @@ exported: For all import syntaxes, the "resource in question" can take any of the following forms: -* projects/{{project}}/locations/{{location}}/instances/{{name}} -* {{project}}/{{location}}/{{name}} -* {{location}}/{{name}} +* projects/{{project}}/locations/{{region}}/instances/{{name}} +* {{project}}/{{region}}/{{name}} +* {{region}}/{{name}} * {{name}} Any variables not passed in the import command will be taken from the provider configuration. @@ -139,17 +139,17 @@ Cloud Data Fusion instance IAM resources can be imported using the resource iden IAM member imports use space-delimited identifiers: the resource in question, the role, and the member identity, e.g. ``` -$ terraform import google_data_fusion_instance_iam_member.editor "projects/{{project}}/locations/{{location}}/instances/{{instance}} roles/viewer user:jane@example.com" +$ terraform import google_data_fusion_instance_iam_member.editor "projects/{{project}}/locations/{{region}}/instances/{{instance}} roles/viewer user:jane@example.com" ``` IAM binding imports use space-delimited identifiers: the resource in question and the role, e.g. ``` -$ terraform import google_data_fusion_instance_iam_binding.editor "projects/{{project}}/locations/{{location}}/instances/{{instance}} roles/viewer" +$ terraform import google_data_fusion_instance_iam_binding.editor "projects/{{project}}/locations/{{region}}/instances/{{instance}} roles/viewer" ``` IAM policy imports use the identifier of the resource in question, e.g. ``` -$ terraform import google_data_fusion_instance_iam_policy.editor projects/{{project}}/locations/{{location}}/instances/{{instance}} +$ terraform import google_data_fusion_instance_iam_policy.editor projects/{{project}}/locations/{{region}}/instances/{{instance}} ``` -> **Custom Roles** If you're importing a IAM resource with a custom role, make sure to use the