| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** AUTO GENERATED CODE *** Type: MMv1 *** |
| // |
| // ---------------------------------------------------------------------------- |
| // |
| // This file is automatically generated by Magic Modules and manual |
| // changes will be clobbered when the file is regenerated. |
| // |
| // Please read more about how to change this file in |
| // .github/CONTRIBUTING.md. |
| // |
| // ---------------------------------------------------------------------------- |
| |
| package compute_test |
| |
| import ( |
| "fmt" |
| "strings" |
| "testing" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| ) |
| |
| func TestAccComputeInstanceIamBindingGenerated(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamBinding_basicGenerated(context), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| { |
| // Test Iam Binding update |
| Config: testAccComputeInstanceIamBinding_updateGenerated(context), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamMemberGenerated(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| // Test Iam Member creation (no update for member, no need to test) |
| Config: testAccComputeInstanceIamMember_basicGenerated(context), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamPolicyGenerated(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamPolicy_basicGenerated(context), |
| Check: resource.TestCheckResourceAttrSet("data.google_compute_instance_iam_policy.foo", "policy_data"), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| { |
| Config: testAccComputeInstanceIamPolicy_emptyBinding(context), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamBindingGenerated_withCondition(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamBinding_withConditionGenerated(context), |
| }, |
| { |
| 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"]), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamBindingGenerated_withAndWithoutCondition(t *testing.T) { |
| // Multiple fine-grained resources |
| acctest.SkipIfVcr(t) |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamBinding_withAndWithoutConditionGenerated(context), |
| }, |
| { |
| 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"])), |
| 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"]), |
| 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"]), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamMemberGenerated_withCondition(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamMember_withConditionGenerated(context), |
| }, |
| { |
| 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"]), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamMemberGenerated_withAndWithoutCondition(t *testing.T) { |
| // Multiple fine-grained resources |
| acctest.SkipIfVcr(t) |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamMember_withAndWithoutConditionGenerated(context), |
| }, |
| { |
| 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"])), |
| 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"]), |
| 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"]), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func TestAccComputeInstanceIamPolicyGenerated_withCondition(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| "role": "roles/compute.osLogin", |
| "condition_title": "expires_after_2019_12_31", |
| "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| "condition_desc": "Expiring at midnight of 2019-12-31", |
| "condition_title_no_desc": "expires_after_2019_12_31-no-description", |
| "condition_expr_no_desc": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, |
| } |
| |
| // Test should have 2 bindings: one with a description and one without. Any < chars are converted to a unicode character by the API. |
| expectedPolicyData := acctest.Nprintf(`{"bindings":[{"condition":{"description":"%{condition_desc}","expression":"%{condition_expr}","title":"%{condition_title}"},"members":["user:admin@hashicorptest.com"],"role":"%{role}"},{"condition":{"expression":"%{condition_expr}","title":"%{condition_title}-no-description"},"members":["user:admin@hashicorptest.com"],"role":"%{role}"}]}`, context) |
| expectedPolicyData = strings.Replace(expectedPolicyData, "<", "\\u003c", -1) |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccComputeInstanceIamPolicy_withConditionGenerated(context), |
| Check: resource.ComposeAggregateTestCheckFunc( |
| // TODO(SarahFrench) - uncomment once https://github.com/GoogleCloudPlatform/magic-modules/pull/6466 merged |
| // resource.TestCheckResourceAttr("data.google_iam_policy.foo", "policy_data", expectedPolicyData), |
| resource.TestCheckResourceAttr("google_compute_instance_iam_policy.foo", "policy_data", expectedPolicyData), |
| resource.TestCheckResourceAttrWith("data.google_iam_policy.foo", "policy_data", tpgresource.CheckGoogleIamPolicy), |
| ), |
| }, |
| { |
| 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"])), |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccComputeInstanceIamMember_basicGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_member" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| member = "user:admin@hashicorptest.com" |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamPolicy_basicGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| data "google_iam_policy" "foo" { |
| binding { |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| } |
| } |
| |
| resource "google_compute_instance_iam_policy" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| policy_data = data.google_iam_policy.foo.policy_data |
| } |
| |
| data "google_compute_instance_iam_policy" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| depends_on = [ |
| google_compute_instance_iam_policy.foo |
| ] |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamPolicy_emptyBinding(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| data "google_iam_policy" "foo" { |
| } |
| |
| resource "google_compute_instance_iam_policy" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| policy_data = data.google_iam_policy.foo.policy_data |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamBinding_basicGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamBinding_updateGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamBinding_withConditionGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| condition { |
| title = "%{condition_title}" |
| description = "%{condition_desc}" |
| expression = "%{condition_expr}" |
| } |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamBinding_withAndWithoutConditionGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo2" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| condition { |
| title = "%{condition_title}" |
| description = "%{condition_desc}" |
| expression = "%{condition_expr}" |
| } |
| } |
| |
| resource "google_compute_instance_iam_binding" "foo3" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| condition { |
| # Check that lack of description doesn't cause any issues |
| # Relates to issue : https://github.com/hashicorp/terraform-provider-google/issues/8701 |
| title = "%{condition_title_no_desc}" |
| expression = "%{condition_expr_no_desc}" |
| } |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamMember_withConditionGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_member" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| member = "user:admin@hashicorptest.com" |
| condition { |
| title = "%{condition_title}" |
| description = "%{condition_desc}" |
| expression = "%{condition_expr}" |
| } |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamMember_withAndWithoutConditionGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| resource "google_compute_instance_iam_member" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| member = "user:admin@hashicorptest.com" |
| } |
| |
| resource "google_compute_instance_iam_member" "foo2" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| member = "user:admin@hashicorptest.com" |
| condition { |
| title = "%{condition_title}" |
| description = "%{condition_desc}" |
| expression = "%{condition_expr}" |
| } |
| } |
| |
| resource "google_compute_instance_iam_member" "foo3" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| role = "%{role}" |
| member = "user:admin@hashicorptest.com" |
| condition { |
| # Check that lack of description doesn't cause any issues |
| # Relates to issue : https://github.com/hashicorp/terraform-provider-google/issues/8701 |
| title = "%{condition_title_no_desc}" |
| expression = "%{condition_expr_no_desc}" |
| } |
| } |
| `, context) |
| } |
| |
| func testAccComputeInstanceIamPolicy_withConditionGenerated(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_compute_instance" "default" { |
| name = "tf-test-my-instance%{random_suffix}" |
| zone = "" |
| machine_type = "e2-medium" |
| |
| boot_disk { |
| initialize_params { |
| image = "debian-cloud/debian-11" |
| } |
| } |
| |
| network_interface { |
| network = "default" |
| } |
| } |
| |
| data "google_iam_policy" "foo" { |
| binding { |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| condition { |
| # Check that lack of description doesn't cause any issues |
| # Relates to issue : https://github.com/hashicorp/terraform-provider-google/issues/8701 |
| title = "%{condition_title_no_desc}" |
| expression = "%{condition_expr_no_desc}" |
| } |
| } |
| binding { |
| role = "%{role}" |
| members = ["user:admin@hashicorptest.com"] |
| condition { |
| title = "%{condition_title}" |
| description = "%{condition_desc}" |
| expression = "%{condition_expr}" |
| } |
| } |
| } |
| |
| resource "google_compute_instance_iam_policy" "foo" { |
| project = google_compute_instance.default.project |
| zone = google_compute_instance.default.zone |
| instance_name = google_compute_instance.default.name |
| policy_data = data.google_iam_policy.foo.policy_data |
| } |
| `, context) |
| } |