|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +// ---------------------------------------------------------------------------- |
| 5 | +// |
| 6 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 7 | +// |
| 8 | +// ---------------------------------------------------------------------------- |
| 9 | +// |
| 10 | +// This file is automatically generated by Magic Modules and manual |
| 11 | +// changes will be clobbered when the file is regenerated. |
| 12 | +// |
| 13 | +// Please read more about how to change this file in |
| 14 | +// .github/CONTRIBUTING.md. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | + |
| 18 | +package google |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "strings" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 26 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 27 | + |
| 28 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 29 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 30 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 31 | +) |
| 32 | + |
| 33 | +func TestAccDNSResponsePolicy_dnsResponsePolicyBasicExample(t *testing.T) { |
| 34 | + t.Parallel() |
| 35 | + |
| 36 | + context := map[string]interface{}{ |
| 37 | + "random_suffix": acctest.RandString(t, 10), |
| 38 | + } |
| 39 | + |
| 40 | + acctest.VcrTest(t, resource.TestCase{ |
| 41 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 42 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 43 | + CheckDestroy: testAccCheckDNSResponsePolicyDestroyProducer(t), |
| 44 | + Steps: []resource.TestStep{ |
| 45 | + { |
| 46 | + Config: testAccDNSResponsePolicy_dnsResponsePolicyBasicExample(context), |
| 47 | + }, |
| 48 | + { |
| 49 | + ResourceName: "google_dns_response_policy.example-response-policy", |
| 50 | + ImportState: true, |
| 51 | + ImportStateVerify: true, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }) |
| 55 | +} |
| 56 | + |
| 57 | +func testAccDNSResponsePolicy_dnsResponsePolicyBasicExample(context map[string]interface{}) string { |
| 58 | + return acctest.Nprintf(` |
| 59 | +resource "google_compute_network" "network-1" { |
| 60 | + name = "tf-test-network-1%{random_suffix}" |
| 61 | + auto_create_subnetworks = false |
| 62 | +} |
| 63 | +
|
| 64 | +resource "google_compute_network" "network-2" { |
| 65 | + name = "tf-test-network-2%{random_suffix}" |
| 66 | + auto_create_subnetworks = false |
| 67 | +} |
| 68 | +
|
| 69 | +resource "google_compute_subnetwork" "subnetwork-1" { |
| 70 | + name = google_compute_network.network-1.name |
| 71 | + network = google_compute_network.network-1.name |
| 72 | + ip_cidr_range = "10.0.36.0/24" |
| 73 | + region = "us-central1" |
| 74 | + private_ip_google_access = true |
| 75 | +
|
| 76 | + secondary_ip_range { |
| 77 | + range_name = "pod" |
| 78 | + ip_cidr_range = "10.0.0.0/19" |
| 79 | + } |
| 80 | +
|
| 81 | + secondary_ip_range { |
| 82 | + range_name = "svc" |
| 83 | + ip_cidr_range = "10.0.32.0/22" |
| 84 | + } |
| 85 | +} |
| 86 | +
|
| 87 | +resource "google_container_cluster" "cluster-1" { |
| 88 | + name = "tf-test-cluster-1%{random_suffix}" |
| 89 | + location = "us-central1-c" |
| 90 | + initial_node_count = 1 |
| 91 | +
|
| 92 | + networking_mode = "VPC_NATIVE" |
| 93 | + default_snat_status { |
| 94 | + disabled = true |
| 95 | + } |
| 96 | + network = google_compute_network.network-1.name |
| 97 | + subnetwork = google_compute_subnetwork.subnetwork-1.name |
| 98 | +
|
| 99 | + private_cluster_config { |
| 100 | + enable_private_endpoint = true |
| 101 | + enable_private_nodes = true |
| 102 | + master_ipv4_cidr_block = "10.42.0.0/28" |
| 103 | + master_global_access_config { |
| 104 | + enabled = true |
| 105 | + } |
| 106 | + } |
| 107 | + master_authorized_networks_config { |
| 108 | + } |
| 109 | + ip_allocation_policy { |
| 110 | + cluster_secondary_range_name = google_compute_subnetwork.subnetwork-1.secondary_ip_range[0].range_name |
| 111 | + services_secondary_range_name = google_compute_subnetwork.subnetwork-1.secondary_ip_range[1].range_name |
| 112 | + } |
| 113 | +} |
| 114 | +
|
| 115 | +resource "google_dns_response_policy" "example-response-policy" { |
| 116 | + response_policy_name = "tf-test-example-response-policy%{random_suffix}" |
| 117 | +
|
| 118 | + networks { |
| 119 | + network_url = google_compute_network.network-1.id |
| 120 | + } |
| 121 | + networks { |
| 122 | + network_url = google_compute_network.network-2.id |
| 123 | + } |
| 124 | + gke_clusters { |
| 125 | + gke_cluster_name = google_container_cluster.cluster-1.id |
| 126 | + } |
| 127 | +} |
| 128 | +`, context) |
| 129 | +} |
| 130 | + |
| 131 | +func testAccCheckDNSResponsePolicyDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| 132 | + return func(s *terraform.State) error { |
| 133 | + for name, rs := range s.RootModule().Resources { |
| 134 | + if rs.Type != "google_dns_response_policy" { |
| 135 | + continue |
| 136 | + } |
| 137 | + if strings.HasPrefix(name, "data.") { |
| 138 | + continue |
| 139 | + } |
| 140 | + |
| 141 | + config := acctest.GoogleProviderConfig(t) |
| 142 | + |
| 143 | + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{DNSBasePath}}projects/{{project}}/responsePolicies/{{response_policy_name}}") |
| 144 | + if err != nil { |
| 145 | + return err |
| 146 | + } |
| 147 | + |
| 148 | + billingProject := "" |
| 149 | + |
| 150 | + if config.BillingProject != "" { |
| 151 | + billingProject = config.BillingProject |
| 152 | + } |
| 153 | + |
| 154 | + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 155 | + Config: config, |
| 156 | + Method: "GET", |
| 157 | + Project: billingProject, |
| 158 | + RawURL: url, |
| 159 | + UserAgent: config.UserAgent, |
| 160 | + }) |
| 161 | + if err == nil { |
| 162 | + return fmt.Errorf("DNSResponsePolicy still exists at %s", url) |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + return nil |
| 167 | + } |
| 168 | +} |
0 commit comments