|
| 1 | +package compute_test |
| 2 | +{{ if ne $.TargetVersionName `ga` -}} |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAccComputeServiceAttachment_tunnelingConfigUpdate(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + context := map[string]interface{}{ |
| 14 | + "random_suffix": acctest.RandString(t, 10), |
| 15 | + } |
| 16 | + |
| 17 | + acctest.VcrTest(t, resource.TestCase{ |
| 18 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 19 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), |
| 20 | + CheckDestroy: testAccCheckComputeServiceAttachmentDestroyProducer(t), |
| 21 | + Steps: []resource.TestStep{ |
| 22 | + { |
| 23 | + Config: testAccComputeServiceAttachment_tunnelingConfig(context, "REGIONAL", "IPV4"), |
| 24 | + }, |
| 25 | + { |
| 26 | + ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment", |
| 27 | + ImportState: true, |
| 28 | + ImportStateVerify: true, |
| 29 | + ImportStateVerifyIgnore: []string{"target_service", "region", "tunneling_config"}, |
| 30 | + }, |
| 31 | + { |
| 32 | + Config: testAccComputeServiceAttachment_tunnelingConfig(context, "GLOBAL", "IPV6"), |
| 33 | + }, |
| 34 | + { |
| 35 | + ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment", |
| 36 | + ImportState: true, |
| 37 | + ImportStateVerify: true, |
| 38 | + ImportStateVerifyIgnore: []string{"target_service", "region", "tunneling_config"}, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }) |
| 42 | +} |
| 43 | + |
| 44 | +func testAccComputeServiceAttachment_tunnelingConfig(context map[string]interface{}, routingMode, encapsulationProfile string) string { |
| 45 | + context["routing_mode"] = routingMode |
| 46 | + context["encapsulation_profile"] = encapsulationProfile |
| 47 | + |
| 48 | + return acctest.Nprintf(` |
| 49 | +resource "google_compute_service_attachment" "psc_ilb_service_attachment" { |
| 50 | + provider = google-beta |
| 51 | + |
| 52 | + name = "tf-test-my-psc-ilb%{random_suffix}" |
| 53 | + region = "us-west2" |
| 54 | + description = "A service attachment configured with tunneling" |
| 55 | + |
| 56 | + enable_proxy_protocol = false |
| 57 | + connection_preference = "ACCEPT_AUTOMATIC" |
| 58 | + nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id] |
| 59 | + target_service = google_compute_forwarding_rule.psc_ilb_target_service.id |
| 60 | + |
| 61 | + tunneling_config { |
| 62 | + routing_mode = "%{routing_mode}" |
| 63 | + encapsulation_profile = "%{encapsulation_profile}" |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +resource "google_compute_forwarding_rule" "psc_ilb_target_service" { |
| 68 | + provider = google-beta |
| 69 | + |
| 70 | + name = "tf-test-producer-forwarding-rule%{random_suffix}" |
| 71 | + region = "us-west2" |
| 72 | + |
| 73 | + load_balancing_scheme = "INTERNAL" |
| 74 | + backend_service = google_compute_region_backend_service.producer_service_backend.id |
| 75 | + all_ports = true |
| 76 | + network = google_compute_network.psc_ilb_network.name |
| 77 | + subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name |
| 78 | +} |
| 79 | + |
| 80 | +resource "google_compute_region_backend_service" "producer_service_backend" { |
| 81 | + provider = google-beta |
| 82 | + |
| 83 | + name = "tf-test-producer-service%{random_suffix}" |
| 84 | + region = "us-west2" |
| 85 | + |
| 86 | + health_checks = [google_compute_health_check.producer_service_health_check.id] |
| 87 | +} |
| 88 | + |
| 89 | +resource "google_compute_health_check" "producer_service_health_check" { |
| 90 | + provider = google-beta |
| 91 | + |
| 92 | + name = "tf-test-producer-service-health-check%{random_suffix}" |
| 93 | + |
| 94 | + check_interval_sec = 1 |
| 95 | + timeout_sec = 1 |
| 96 | + tcp_health_check { |
| 97 | + port = "80" |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +resource "google_compute_network" "psc_ilb_network" { |
| 102 | + provider = google-beta |
| 103 | + |
| 104 | + name = "tf-test-psc-ilb-network%{random_suffix}" |
| 105 | + auto_create_subnetworks = false |
| 106 | +} |
| 107 | + |
| 108 | +resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" { |
| 109 | + provider = google-beta |
| 110 | + |
| 111 | + name = "tf-test-psc-ilb-producer-subnetwork%{random_suffix}" |
| 112 | + region = "us-west2" |
| 113 | + |
| 114 | + network = google_compute_network.psc_ilb_network.id |
| 115 | + ip_cidr_range = "10.0.0.0/16" |
| 116 | +} |
| 117 | + |
| 118 | +resource "google_compute_subnetwork" "psc_ilb_nat" { |
| 119 | + provider = google-beta |
| 120 | + |
| 121 | + name = "tf-test-psc-ilb-nat%{random_suffix}" |
| 122 | + region = "us-west2" |
| 123 | + |
| 124 | + network = google_compute_network.psc_ilb_network.id |
| 125 | + purpose = "PRIVATE_SERVICE_CONNECT" |
| 126 | + ip_cidr_range = "10.1.0.0/16" |
| 127 | +} |
| 128 | +`, context) |
| 129 | +} |
| 130 | +{{- end }} |
0 commit comments