|
| 1 | +package osconfigv2_test |
| 2 | +{{- if ne $.TargetVersionName "ga" }} |
| 3 | + |
| 4 | +import ( |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 9 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccOSConfigV2PolicyOrchestrator_basic(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + acctest.BootstrapIamMembers(t, []acctest.IamMember{ |
| 16 | + { |
| 17 | + Member: "serviceAccount:service-{project_number}@gcp-sa-osconfig.iam.gserviceaccount.com", |
| 18 | + Role: "roles/osconfig.serviceAgent", |
| 19 | + }, |
| 20 | + { |
| 21 | + Member: "serviceAccount:service-{project_number}@gcp-sa-osconfig-rollout.iam.gserviceaccount.com", |
| 22 | + Role: "roles/osconfig.rolloutServiceAgent", |
| 23 | + }, |
| 24 | + { |
| 25 | + Member: "serviceAccount:service-{project_number}@gcp-sa-progrollout.iam.gserviceaccount.com", |
| 26 | + Role: "roles/progressiverollout.serviceAgent", |
| 27 | + }, |
| 28 | + }) |
| 29 | + |
| 30 | + context := map[string]interface{}{ |
| 31 | + "project": envvar.GetTestProjectFromEnv(), |
| 32 | + "project_number": envvar.GetTestProjectNumberFromEnv(), |
| 33 | + "random_suffix": acctest.RandString(t, 10), |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + acctest.VcrTest(t, resource.TestCase{ |
| 38 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 39 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), |
| 40 | + Steps: []resource.TestStep{ |
| 41 | + { |
| 42 | + Config: testAccOSConfigV2PolicyOrchestrator_basic(context), |
| 43 | + }, |
| 44 | + { |
| 45 | + ResourceName: "google_os_config_v2_policy_orchestrator.policy_orchestrator", |
| 46 | + ImportState: true, |
| 47 | + ImportStateVerify: true, |
| 48 | + ImportStateVerifyIgnore: []string{"labels", "policy_orchestrator_id", "terraform_labels"}, |
| 49 | + }, |
| 50 | + { |
| 51 | + Config: testAccOSConfigV2PolicyOrchestrator_update(context), |
| 52 | + }, |
| 53 | + { |
| 54 | + ResourceName: "google_os_config_v2_policy_orchestrator.policy_orchestrator", |
| 55 | + ImportState: true, |
| 56 | + ImportStateVerify: true, |
| 57 | + ImportStateVerifyIgnore: []string{"labels", "policy_orchestrator_id", "terraform_labels"}, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }) |
| 61 | +} |
| 62 | + |
| 63 | +func testAccOSConfigV2PolicyOrchestrator_basic(context map[string]interface{}) string { |
| 64 | + return acctest.Nprintf(` |
| 65 | +resource "google_os_config_v2_policy_orchestrator" "policy_orchestrator" { |
| 66 | + provider = google-beta |
| 67 | + policy_orchestrator_id = "tf-test-test-po%{random_suffix}" |
| 68 | + |
| 69 | + state = "ACTIVE" |
| 70 | + action = "UPSERT" |
| 71 | + |
| 72 | + orchestrated_resource { |
| 73 | + id = "tf-test-test-orchestrated-resource%{random_suffix}" |
| 74 | + os_policy_assignment_v1_payload { |
| 75 | + os_policies { |
| 76 | + id = "tf-test-test-os-policy%{random_suffix}" |
| 77 | + mode = "VALIDATION" |
| 78 | + resource_groups { |
| 79 | + resources { |
| 80 | + id = "resource-tf" |
| 81 | + file { |
| 82 | + content = "file-content-tf" |
| 83 | + path = "file-path-tf-1" |
| 84 | + state = "PRESENT" |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + instance_filter { |
| 90 | + inventories { |
| 91 | + os_short_name = "windows-10" |
| 92 | + } |
| 93 | + } |
| 94 | + rollout { |
| 95 | + disruption_budget { |
| 96 | + percent = 100 |
| 97 | + } |
| 98 | + min_wait_duration = "60s" |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + labels = { |
| 103 | + state = "active" |
| 104 | + } |
| 105 | +} |
| 106 | +`, context) |
| 107 | +} |
| 108 | + |
| 109 | +func testAccOSConfigV2PolicyOrchestrator_update(context map[string]interface{}) string { |
| 110 | + return acctest.Nprintf(` |
| 111 | +resource "google_os_config_v2_policy_orchestrator" "policy_orchestrator" { |
| 112 | + provider = google-beta |
| 113 | + policy_orchestrator_id = "tf-test-test-po%{random_suffix}" |
| 114 | + |
| 115 | + state = "STOPPED" |
| 116 | + action = "DELETE" |
| 117 | + description = "Updated description" |
| 118 | + |
| 119 | + orchestrated_resource { |
| 120 | + id = "tf-test-test-orchestrated-resource%{random_suffix}" |
| 121 | + os_policy_assignment_v1_payload { |
| 122 | + os_policies { |
| 123 | + id = "tf-test-test-os-policy%{random_suffix}" |
| 124 | + mode = "VALIDATION" |
| 125 | + resource_groups { |
| 126 | + resources { |
| 127 | + id = "resource-tf" |
| 128 | + file { |
| 129 | + content = "file-content-tf-2" |
| 130 | + path = "file-path-tf-2" |
| 131 | + state = "PRESENT" |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + instance_filter { |
| 137 | + inventories { |
| 138 | + os_short_name = "ubuntu" |
| 139 | + } |
| 140 | + } |
| 141 | + rollout { |
| 142 | + disruption_budget { |
| 143 | + percent = 50 |
| 144 | + } |
| 145 | + min_wait_duration = "120s" |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + labels = { |
| 150 | + state = "active" |
| 151 | + } |
| 152 | +} |
| 153 | +`, context) |
| 154 | +} |
| 155 | +{{ end }} |
0 commit comments