|
1 |
| -url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}IapBasePath{{"}}"}}{{"{{"}}name{{"}}"}}:iapSettings") |
2 |
| -if err != nil { |
3 |
| - return err |
| 1 | +package iap_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 8 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccIapSettings_update(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + context := map[string]interface{}{ |
| 15 | + "org_id": envvar.GetTestOrgFromEnv(t), |
| 16 | + "billing_account": envvar.GetTestBillingAccountFromEnv(t), |
| 17 | + "random_suffix": acctest.RandString(t, 10), |
| 18 | + "role": "roles/iap.settingsAdmin", |
| 19 | + } |
| 20 | + |
| 21 | + acctest.VcrTest(t, resource.TestCase{ |
| 22 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 23 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 24 | + ExternalProviders: map[string]resource.ExternalProvider{ |
| 25 | + "time": {}, |
| 26 | + }, |
| 27 | + CheckDestroy: testAccCheckIapSettingsDestroyProducer(t), |
| 28 | + Steps: []resource.TestStep{ |
| 29 | + { |
| 30 | + Config: testAccIapSettings_basic(context), |
| 31 | + }, |
| 32 | + { |
| 33 | + ResourceName: "google_iap_settings.iap_settings", |
| 34 | + ImportState: true, |
| 35 | + ImportStateVerify: true, |
| 36 | + ImportStateVerifyIgnore: []string{"access_settings.0.workforce_identity_settings.0.oauth2.0.client_secret"}, |
| 37 | + }, |
| 38 | + { |
| 39 | + Config: testAccIapSettings_update(context), |
| 40 | + }, |
| 41 | + { |
| 42 | + ResourceName: "google_iap_settings.iap_settings", |
| 43 | + ImportState: true, |
| 44 | + ImportStateVerify: true, |
| 45 | + ImportStateVerifyIgnore: []string{"access_settings.0.workforce_identity_settings.0.oauth2.0.client_secret"}, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }) |
4 | 49 | }
|
5 | 50 |
|
6 |
| -project, err := tpgresource.GetProject(d, config) |
7 |
| -if err != nil { |
8 |
| - return fmt.Errorf("Error fetching project for Settings: %s", err) |
| 51 | +func testAccIapSettings_basic(context map[string]interface{}) string { |
| 52 | + return acctest.Nprintf(` |
| 53 | +data "google_project" "project" { |
9 | 54 | }
|
10 | 55 |
|
11 |
| -headers := make(http.Header) |
| 56 | +resource "google_compute_region_backend_service" "default" { |
| 57 | + name = "tf-test-iap-settings-tf%{random_suffix}" |
| 58 | + region = "us-central1" |
| 59 | + health_checks = [google_compute_health_check.default.id] |
| 60 | + connection_draining_timeout_sec = 10 |
| 61 | + session_affinity = "CLIENT_IP" |
| 62 | +} |
12 | 63 |
|
13 |
| -obj := make(map[string]interface{}) |
| 64 | +resource "google_compute_health_check" "default" { |
| 65 | + name = "tf-test-iap-bs-health-check%{random_suffix}" |
| 66 | + check_interval_sec = 1 |
| 67 | + timeout_sec = 1 |
| 68 | + tcp_health_check { |
| 69 | + port = "80" |
| 70 | + } |
| 71 | +} |
14 | 72 |
|
15 |
| -log.Printf("[DEBUG] Updating Settings %q: %#v", d.Id(), obj) |
| 73 | +resource "google_iap_settings" "iap_settings" { |
| 74 | + name = "projects/${data.google_project.project.number}/iap_web/compute-us-central1/services/${google_compute_region_backend_service.default.name}" |
| 75 | + access_settings { |
| 76 | + identity_sources = ["WORKFORCE_IDENTITY_FEDERATION"] |
| 77 | + allowed_domains_settings { |
| 78 | + domains = ["test.abc.com"] |
| 79 | + enable = true |
| 80 | + } |
| 81 | + cors_settings { |
| 82 | + allow_http_options = true |
| 83 | + } |
| 84 | + reauth_settings { |
| 85 | + method = "SECURE_KEY" |
| 86 | + max_age = "305s" |
| 87 | + policy_type = "MINIMUM" |
| 88 | + } |
| 89 | + gcip_settings { |
| 90 | + login_page_uri = "https://test.com/?apiKey=abc" |
| 91 | + } |
| 92 | + oauth_settings { |
| 93 | + login_hint = "test" |
| 94 | + } |
| 95 | + workforce_identity_settings { |
| 96 | + workforce_pools = ["wif-pool"] |
| 97 | + oauth2 { |
| 98 | + client_id = "test-client-id" |
| 99 | + client_secret = "test-client-secret" |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + application_settings { |
| 104 | + cookie_domain = "test.abc.com" |
| 105 | + csm_settings { |
| 106 | + rctoken_aud = "test-aud-set" |
| 107 | + } |
| 108 | + access_denied_page_settings { |
| 109 | + access_denied_page_uri = "test-uri" |
| 110 | + generate_troubleshooting_uri = true |
| 111 | + remediation_token_generation_enabled = false |
| 112 | + } |
| 113 | + attribute_propagation_settings { |
| 114 | + output_credentials = ["HEADER"] |
| 115 | + expression = "attributes.saml_attributes.filter(attribute, attribute.name in [\"test1\", \"test2\"])" |
| 116 | + enable = false |
| 117 | + } |
| 118 | + } |
| 119 | +} |
| 120 | +`, context) |
| 121 | +} |
16 | 122 |
|
17 |
| -res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
18 |
| - Config: config, |
19 |
| - Method: "PATCH", |
20 |
| - Project: project, |
21 |
| - RawURL: url, |
22 |
| - UserAgent: userAgent, |
23 |
| - Body: obj, |
24 |
| - Timeout: d.Timeout(schema.TimeoutUpdate), |
25 |
| - Headers: headers, |
26 |
| -}) |
| 123 | +func testAccIapSettings_update(context map[string]interface{}) string { |
| 124 | + return acctest.Nprintf(` |
| 125 | +resource "google_project" "my_project" { |
| 126 | + name = "tf-test-%{random_suffix}" |
| 127 | + project_id = "tf-test-%{random_suffix}" |
| 128 | + org_id = "%{org_id}" |
| 129 | + billing_account = "%{billing_account}" |
| 130 | + deletion_policy = "DELETE" |
| 131 | +} |
27 | 132 |
|
28 |
| -if err != nil { |
29 |
| - return fmt.Errorf("Error updating Settings %q: %s", d.Id(), err) |
30 |
| -} else { |
31 |
| - log.Printf("[DEBUG] Finished updating Settings %q: %#v", d.Id(), res) |
| 133 | +resource "time_sleep" "wait_60_seconds" { |
| 134 | + depends_on = [google_project.my_project] |
| 135 | +
|
| 136 | + create_duration = "60s" |
32 | 137 | }
|
33 | 138 |
|
34 |
| -return nil |
| 139 | +resource "google_project_service" "project_service" { |
| 140 | + project = google_project.my_project.project_id |
| 141 | + service = "iap.googleapis.com" |
| 142 | +
|
| 143 | + # Needed for CI tests for permissions to propagate, should not be needed for actual usage |
| 144 | + depends_on = [time_sleep.wait_60_seconds] |
| 145 | +} |
| 146 | +
|
| 147 | +resource "google_app_engine_application" "app" { |
| 148 | + project = google_project_service.project_service.project |
| 149 | + location_id = "us-central" |
| 150 | +} |
35 | 151 |
|
| 152 | +resource "google_iap_web_type_app_engine_iam_member" "foo" { |
| 153 | + project = google_app_engine_application.app.project |
| 154 | + app_id = google_app_engine_application.app.app_id |
| 155 | + role = "%{role}" |
| 156 | + |
| 157 | +} |
| 158 | +
|
| 159 | +resource "google_iap_settings" "iap_settings" { |
| 160 | + name = "projects/${google_project.my_project.project_id}/iap_web/appengine-${google_app_engine_application.app.app_id}" |
| 161 | + access_settings { |
| 162 | + allowed_domains_settings { |
| 163 | + domains = ["appengine.abc.com"] |
| 164 | + enable = true |
| 165 | + } |
| 166 | + cors_settings { |
| 167 | + allow_http_options = true |
| 168 | + } |
| 169 | + } |
| 170 | + application_settings { |
| 171 | + cookie_domain = "appengine.abc.com" |
| 172 | + attribute_propagation_settings { |
| 173 | + output_credentials = ["JWT"] |
| 174 | + expression = "attributes.saml_attributes.filter(attribute, attribute.name in [\"test1\", \"test2\"])" |
| 175 | + enable = false |
| 176 | + } |
| 177 | + } |
| 178 | + depends_on = [google_iap_web_type_app_engine_iam_member.foo] |
| 179 | +} |
| 180 | +`, context) |
| 181 | +} |
0 commit comments