|
| 1 | +package networksecurity_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-plugin-testing/plancheck" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccNetworkSecurityInterceptDeployment_update(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + context := map[string]interface{}{ |
| 17 | + "random_suffix": acctest.RandString(t, 10), |
| 18 | + } |
| 19 | + |
| 20 | + acctest.VcrTest(t, resource.TestCase{ |
| 21 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 22 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), |
| 23 | + Steps: []resource.TestStep{ |
| 24 | + { |
| 25 | + Config: testAccNetworkSecurityInterceptDeployment_basic(context), |
| 26 | + }, |
| 27 | + { |
| 28 | + ResourceName: "google_network_security_intercept_deployment.default", |
| 29 | + ImportState: true, |
| 30 | + ImportStateVerify: true, |
| 31 | + ImportStateVerifyIgnore: []string{"labels", "terraform_labels"}, |
| 32 | + }, |
| 33 | + { |
| 34 | + Config: testAccNetworkSecurityInterceptDeployment_update(context), |
| 35 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 36 | + PreApply: []plancheck.PlanCheck{ |
| 37 | + plancheck.ExpectResourceAction("google_network_security_intercept_deployment.default", plancheck.ResourceActionUpdate), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + ResourceName: "google_network_security_intercept_deployment.default", |
| 43 | + ImportState: true, |
| 44 | + ImportStateVerify: true, |
| 45 | + ImportStateVerifyIgnore: []string{"update_time", "labels", "terraform_labels"}, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }) |
| 49 | +} |
| 50 | + |
| 51 | +func testAccNetworkSecurityInterceptDeployment_basic(context map[string]interface{}) string { |
| 52 | + return acctest.Nprintf(` |
| 53 | +resource "google_compute_network" "network" { |
| 54 | + provider = google-beta |
| 55 | + name = "tf-test-example-network%{random_suffix}" |
| 56 | + auto_create_subnetworks = false |
| 57 | +} |
| 58 | + |
| 59 | +resource "google_compute_subnetwork" "subnetwork" { |
| 60 | + provider = google-beta |
| 61 | + name = "tf-test-example-subnet%{random_suffix}" |
| 62 | + region = "us-central1" |
| 63 | + ip_cidr_range = "10.1.0.0/16" |
| 64 | + network = google_compute_network.network.name |
| 65 | +} |
| 66 | + |
| 67 | +resource "google_compute_region_health_check" "health_check" { |
| 68 | + provider = google-beta |
| 69 | + name = "tf-test-example-hc%{random_suffix}" |
| 70 | + region = "us-central1" |
| 71 | + http_health_check { |
| 72 | + port = 80 |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +resource "google_compute_region_backend_service" "backend_service" { |
| 77 | + provider = google-beta |
| 78 | + name = "tf-test-example-bs%{random_suffix}" |
| 79 | + region = "us-central1" |
| 80 | + health_checks = [google_compute_region_health_check.health_check.id] |
| 81 | + protocol = "UDP" |
| 82 | + load_balancing_scheme = "INTERNAL" |
| 83 | +} |
| 84 | + |
| 85 | +resource "google_compute_forwarding_rule" "forwarding_rule" { |
| 86 | + provider = google-beta |
| 87 | + name = "tf-test-example-fwr%{random_suffix}" |
| 88 | + region = "us-central1" |
| 89 | + network = google_compute_network.network.name |
| 90 | + subnetwork = google_compute_subnetwork.subnetwork.name |
| 91 | + backend_service = google_compute_region_backend_service.backend_service.id |
| 92 | + load_balancing_scheme = "INTERNAL" |
| 93 | + ports = [6081] |
| 94 | + ip_protocol = "UDP" |
| 95 | +} |
| 96 | + |
| 97 | +resource "google_network_security_intercept_deployment_group" "deployment_group" { |
| 98 | + provider = google-beta |
| 99 | + intercept_deployment_group_id = "tf-test-example-dg%{random_suffix}" |
| 100 | + location = "global" |
| 101 | + network = google_compute_network.network.id |
| 102 | +} |
| 103 | + |
| 104 | +resource "google_network_security_intercept_deployment" "default" { |
| 105 | + provider = google-beta |
| 106 | + intercept_deployment_id = "tf-test-example-deployment%{random_suffix}" |
| 107 | + location = "us-central1-a" |
| 108 | + forwarding_rule = google_compute_forwarding_rule.forwarding_rule.id |
| 109 | + intercept_deployment_group = google_network_security_intercept_deployment_group.deployment_group.id |
| 110 | + labels = { |
| 111 | + foo = "bar" |
| 112 | + } |
| 113 | +} |
| 114 | +`, context) |
| 115 | +} |
| 116 | + |
| 117 | +func testAccNetworkSecurityInterceptDeployment_update(context map[string]interface{}) string { |
| 118 | + return acctest.Nprintf(` |
| 119 | +resource "google_compute_network" "network" { |
| 120 | + provider = google-beta |
| 121 | + name = "tf-test-example-network%{random_suffix}" |
| 122 | + auto_create_subnetworks = false |
| 123 | +} |
| 124 | + |
| 125 | +resource "google_compute_subnetwork" "subnetwork" { |
| 126 | + provider = google-beta |
| 127 | + name = "tf-test-example-subnet%{random_suffix}" |
| 128 | + region = "us-central1" |
| 129 | + ip_cidr_range = "10.1.0.0/16" |
| 130 | + network = google_compute_network.network.name |
| 131 | +} |
| 132 | + |
| 133 | +resource "google_compute_region_health_check" "health_check" { |
| 134 | + provider = google-beta |
| 135 | + name = "tf-test-example-hc%{random_suffix}" |
| 136 | + region = "us-central1" |
| 137 | + http_health_check { |
| 138 | + port = 80 |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +resource "google_compute_region_backend_service" "backend_service" { |
| 143 | + provider = google-beta |
| 144 | + name = "tf-test-example-bs%{random_suffix}" |
| 145 | + region = "us-central1" |
| 146 | + health_checks = [google_compute_region_health_check.health_check.id] |
| 147 | + protocol = "UDP" |
| 148 | + load_balancing_scheme = "INTERNAL" |
| 149 | +} |
| 150 | + |
| 151 | +resource "google_compute_forwarding_rule" "forwarding_rule" { |
| 152 | + provider = google-beta |
| 153 | + name = "tf-test-example-fwr%{random_suffix}" |
| 154 | + region = "us-central1" |
| 155 | + network = google_compute_network.network.name |
| 156 | + subnetwork = google_compute_subnetwork.subnetwork.name |
| 157 | + backend_service = google_compute_region_backend_service.backend_service.id |
| 158 | + load_balancing_scheme = "INTERNAL" |
| 159 | + ports = [6081] |
| 160 | + ip_protocol = "UDP" |
| 161 | +} |
| 162 | + |
| 163 | +resource "google_network_security_intercept_deployment_group" "deployment_group" { |
| 164 | + provider = google-beta |
| 165 | + intercept_deployment_group_id = "tf-test-example-dg%{random_suffix}" |
| 166 | + location = "global" |
| 167 | + network = google_compute_network.network.id |
| 168 | +} |
| 169 | + |
| 170 | +resource "google_network_security_intercept_deployment" "default" { |
| 171 | + provider = google-beta |
| 172 | + intercept_deployment_id = "tf-test-example-deployment%{random_suffix}" |
| 173 | + location = "us-central1-a" |
| 174 | + forwarding_rule = google_compute_forwarding_rule.forwarding_rule.id |
| 175 | + intercept_deployment_group = google_network_security_intercept_deployment_group.deployment_group.id |
| 176 | + labels = { |
| 177 | + foo = "goo" |
| 178 | + } |
| 179 | +} |
| 180 | +`, context) |
| 181 | +} |
| 182 | + |
| 183 | +{{ end }} |
0 commit comments