|
| 1 | +package apigee_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 10 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccApigeeControlPlaneAccess_update(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + context := map[string]interface{}{ |
| 17 | + "billing_account": envvar.GetTestBillingAccountFromEnv(t), |
| 18 | + "org_id": envvar.GetTestOrgFromEnv(t), |
| 19 | + "random_suffix": acctest.RandString(t, 10), |
| 20 | + } |
| 21 | + |
| 22 | + acctest.VcrTest(t, resource.TestCase{ |
| 23 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 24 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 25 | + Steps: []resource.TestStep{ |
| 26 | + { |
| 27 | + Config: testAccApigeeControlPlaneAccess_full(context), |
| 28 | + }, |
| 29 | + { |
| 30 | + ResourceName: "google_apigee_control_plane_access.apigee_control_plane_access", |
| 31 | + ImportState: true, |
| 32 | + ImportStateVerify: true, |
| 33 | + ImportStateVerifyIgnore: []string{"name"}, |
| 34 | + }, |
| 35 | + { |
| 36 | + Config: testAccApigeeControlPlaneAccess_update(context), |
| 37 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 38 | + PreApply: []plancheck.PlanCheck{ |
| 39 | + plancheck.ExpectResourceAction("google_apigee_control_plane_access.apigee_control_plane_access", plancheck.ResourceActionUpdate), |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + ResourceName: "google_apigee_control_plane_access.apigee_control_plane_access", |
| 45 | + ImportState: true, |
| 46 | + ImportStateVerify: true, |
| 47 | + ImportStateVerifyIgnore: []string{"name"}, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }) |
| 51 | +} |
| 52 | + |
| 53 | +func testAccApigeeControlPlaneAccess_full(context map[string]interface{}) string { |
| 54 | + return acctest.Nprintf(` |
| 55 | +resource "google_project" "project" { |
| 56 | + project_id = "tf-test-my-project%{random_suffix}" |
| 57 | + name = "tf-test-my-project%{random_suffix}" |
| 58 | + org_id = "%{org_id}" |
| 59 | + billing_account = "%{billing_account}" |
| 60 | + deletion_policy = "DELETE" |
| 61 | +} |
| 62 | +
|
| 63 | +resource "google_project_service" "apigee" { |
| 64 | + project = google_project.project.project_id |
| 65 | + service = "apigee.googleapis.com" |
| 66 | +} |
| 67 | +
|
| 68 | +resource "google_apigee_organization" "apigee_org" { |
| 69 | + analytics_region = "us-central1" |
| 70 | + project_id = google_project.project.project_id |
| 71 | +
|
| 72 | + runtime_type = "HYBRID" |
| 73 | + depends_on = [google_project_service.apigee] |
| 74 | +} |
| 75 | +
|
| 76 | +resource "google_service_account" "service_account" { |
| 77 | + account_id = "sa-%{random_suffix}" |
| 78 | + display_name = "Service Account" |
| 79 | +} |
| 80 | +
|
| 81 | +resource "google_apigee_control_plane_access" "apigee_control_plane_access" { |
| 82 | + name = google_apigee_organization.apigee_org.name |
| 83 | + synchronizer_identities = [ |
| 84 | + "serviceAccount:${google_service_account.service_account.email}", |
| 85 | + ] |
| 86 | + analytics_publisher_identities = [ |
| 87 | + "serviceAccount:${google_service_account.service_account.email}", |
| 88 | + ] |
| 89 | +} |
| 90 | +`, context) |
| 91 | +} |
| 92 | + |
| 93 | +func testAccApigeeControlPlaneAccess_update(context map[string]interface{}) string { |
| 94 | + return acctest.Nprintf(` |
| 95 | +resource "google_project" "project" { |
| 96 | + project_id = "tf-test-my-project%{random_suffix}" |
| 97 | + name = "tf-test-my-project%{random_suffix}" |
| 98 | + org_id = "%{org_id}" |
| 99 | + billing_account = "%{billing_account}" |
| 100 | + deletion_policy = "DELETE" |
| 101 | +} |
| 102 | +
|
| 103 | +resource "google_project_service" "apigee" { |
| 104 | + project = google_project.project.project_id |
| 105 | + service = "apigee.googleapis.com" |
| 106 | +} |
| 107 | +
|
| 108 | +resource "google_apigee_organization" "apigee_org" { |
| 109 | + analytics_region = "us-central1" |
| 110 | + project_id = google_project.project.project_id |
| 111 | +
|
| 112 | + runtime_type = "HYBRID" |
| 113 | + depends_on = [google_project_service.apigee] |
| 114 | +} |
| 115 | +
|
| 116 | +resource "google_apigee_control_plane_access" "apigee_control_plane_access" { |
| 117 | + name = google_apigee_organization.apigee_org.name |
| 118 | + synchronizer_identities = [] |
| 119 | + analytics_publisher_identities = [] |
| 120 | +} |
| 121 | +`, context) |
| 122 | +} |
0 commit comments