|
| 1 | +package eventarc_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 7 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccEventarcChannel_cryptoKeyUpdate(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + region := envvar.GetTestRegionFromEnv() |
| 16 | + context := map[string]interface{}{ |
| 17 | + "region": region, |
| 18 | + "project_name": envvar.GetTestProjectFromEnv(), |
| 19 | + "project_number": envvar.GetTestProjectNumberFromEnv(), |
| 20 | + "key1": acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", region, "tf-bootstrap-eventarc-channel-key1").CryptoKey.Name, |
| 21 | + "key2": acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", region, "tf-bootstrap-eventarc-channel-key2").CryptoKey.Name, |
| 22 | + "random_suffix": acctest.RandString(t, 10), |
| 23 | + } |
| 24 | + acctest.BootstrapIamMembers(t, []acctest.IamMember{ |
| 25 | + { |
| 26 | + Member: "serviceAccount:service-{project_number}@gcp-sa-eventarc.iam.gserviceaccount.com", |
| 27 | + Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter", |
| 28 | + }, |
| 29 | + }) |
| 30 | + |
| 31 | + acctest.VcrTest(t, resource.TestCase{ |
| 32 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 33 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 34 | + CheckDestroy: testAccCheckEventarcChannelDestroyProducer(t), |
| 35 | + Steps: []resource.TestStep{ |
| 36 | + { |
| 37 | + Config: testAccEventarcChannel_setCryptoKey(context), |
| 38 | + }, |
| 39 | + { |
| 40 | + ResourceName: "google_eventarc_channel.primary", |
| 41 | + ImportState: true, |
| 42 | + ImportStateVerify: true, |
| 43 | + }, |
| 44 | + { |
| 45 | + Config: testAccEventarcChannel_cryptoKeyUpdate(context), |
| 46 | + }, |
| 47 | + { |
| 48 | + ResourceName: "google_eventarc_channel.primary", |
| 49 | + ImportState: true, |
| 50 | + ImportStateVerify: true, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }) |
| 54 | +} |
| 55 | + |
| 56 | +func testAccEventarcChannel_setCryptoKey(context map[string]interface{}) string { |
| 57 | + return acctest.Nprintf(` |
| 58 | +resource "google_eventarc_channel" "primary" { |
| 59 | + location = "%{region}" |
| 60 | + name = "tf-test-name%{random_suffix}" |
| 61 | + crypto_key_name = "%{key1}" |
| 62 | + third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog" |
| 63 | +} |
| 64 | +`, context) |
| 65 | +} |
| 66 | + |
| 67 | +func testAccEventarcChannel_cryptoKeyUpdate(context map[string]interface{}) string { |
| 68 | + return acctest.Nprintf(` |
| 69 | +resource "google_eventarc_channel" "primary" { |
| 70 | + location = "%{region}" |
| 71 | + name = "tf-test-name%{random_suffix}" |
| 72 | + crypto_key_name = "%{key2}" |
| 73 | + third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog" |
| 74 | +} |
| 75 | +`, context) |
| 76 | +} |
| 77 | + |
| 78 | +func TestAccEventarcChannel_longForm(t *testing.T) { |
| 79 | + t.Parallel() |
| 80 | + |
| 81 | + context := map[string]interface{}{ |
| 82 | + "region": envvar.GetTestRegionFromEnv(), |
| 83 | + "project_name": envvar.GetTestProjectFromEnv(), |
| 84 | + "random_suffix": acctest.RandString(t, 10), |
| 85 | + } |
| 86 | + |
| 87 | + acctest.VcrTest(t, resource.TestCase{ |
| 88 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 89 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 90 | + CheckDestroy: testAccCheckEventarcChannelDestroyProducer(t), |
| 91 | + Steps: []resource.TestStep{ |
| 92 | + { |
| 93 | + Config: testAccEventarcChannel_longForm(context), |
| 94 | + }, |
| 95 | + { |
| 96 | + ResourceName: "google_eventarc_channel.primary", |
| 97 | + ImportState: true, |
| 98 | + ImportStateVerify: true, |
| 99 | + ImportStateVerifyIgnore: []string{"name", "location", "project"}, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }) |
| 103 | +} |
| 104 | + |
| 105 | +func testAccEventarcChannel_longForm(context map[string]interface{}) string { |
| 106 | + return acctest.Nprintf(` |
| 107 | +resource "google_eventarc_channel" "primary" { |
| 108 | + location = "long/form/%{region}" |
| 109 | + project = "projects/%{project_name}" |
| 110 | + name = "projects/%{project_name}/locations/%{region}/channels/tf-test-name%{random_suffix}" |
| 111 | + third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog" |
| 112 | +} |
| 113 | +`, context) |
| 114 | +} |
0 commit comments