-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote google_dns_response_policy & google_dns_response_policy_rule …
…to GA (#8308) (#15146) Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
d2da516
commit 279303a
Showing
9 changed files
with
1,523 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:new-resource | ||
`google_dns_response_policy` (ga) | ||
``` | ||
```release-note:new-resource | ||
`google_dns_response_policy_rule` (ga) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func TestAccDNSResponsePolicy_dnsResponsePolicyBasicExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckDNSResponsePolicyDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDNSResponsePolicy_dnsResponsePolicyBasicExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_dns_response_policy.example-response-policy", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDNSResponsePolicy_dnsResponsePolicyBasicExample(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_compute_network" "network-1" { | ||
name = "tf-test-network-1%{random_suffix}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_network" "network-2" { | ||
name = "tf-test-network-2%{random_suffix}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "subnetwork-1" { | ||
name = google_compute_network.network-1.name | ||
network = google_compute_network.network-1.name | ||
ip_cidr_range = "10.0.36.0/24" | ||
region = "us-central1" | ||
private_ip_google_access = true | ||
secondary_ip_range { | ||
range_name = "pod" | ||
ip_cidr_range = "10.0.0.0/19" | ||
} | ||
secondary_ip_range { | ||
range_name = "svc" | ||
ip_cidr_range = "10.0.32.0/22" | ||
} | ||
} | ||
resource "google_container_cluster" "cluster-1" { | ||
name = "tf-test-cluster-1%{random_suffix}" | ||
location = "us-central1-c" | ||
initial_node_count = 1 | ||
networking_mode = "VPC_NATIVE" | ||
default_snat_status { | ||
disabled = true | ||
} | ||
network = google_compute_network.network-1.name | ||
subnetwork = google_compute_subnetwork.subnetwork-1.name | ||
private_cluster_config { | ||
enable_private_endpoint = true | ||
enable_private_nodes = true | ||
master_ipv4_cidr_block = "10.42.0.0/28" | ||
master_global_access_config { | ||
enabled = true | ||
} | ||
} | ||
master_authorized_networks_config { | ||
} | ||
ip_allocation_policy { | ||
cluster_secondary_range_name = google_compute_subnetwork.subnetwork-1.secondary_ip_range[0].range_name | ||
services_secondary_range_name = google_compute_subnetwork.subnetwork-1.secondary_ip_range[1].range_name | ||
} | ||
} | ||
resource "google_dns_response_policy" "example-response-policy" { | ||
response_policy_name = "tf-test-example-response-policy%{random_suffix}" | ||
networks { | ||
network_url = google_compute_network.network-1.id | ||
} | ||
networks { | ||
network_url = google_compute_network.network-2.id | ||
} | ||
gke_clusters { | ||
gke_cluster_name = google_container_cluster.cluster-1.id | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckDNSResponsePolicyDestroyProducer(t *testing.T) func(s *terraform.State) error { | ||
return func(s *terraform.State) error { | ||
for name, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_dns_response_policy" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := acctest.GoogleProviderConfig(t) | ||
|
||
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{DNSBasePath}}projects/{{project}}/responsePolicies/{{response_policy_name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
if config.BillingProject != "" { | ||
billingProject = config.BillingProject | ||
} | ||
|
||
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: config.UserAgent, | ||
}) | ||
if err == nil { | ||
return fmt.Errorf("DNSResponsePolicy still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
google/resource_dns_response_policy_rule_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func TestAccDNSResponsePolicyRule_dnsResponsePolicyRuleBasicExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckDNSResponsePolicyRuleDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDNSResponsePolicyRule_dnsResponsePolicyRuleBasicExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_dns_response_policy_rule.example-response-policy-rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"response_policy"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDNSResponsePolicyRule_dnsResponsePolicyRuleBasicExample(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_compute_network" "network-1" { | ||
name = "tf-test-network-1%{random_suffix}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_network" "network-2" { | ||
name = "tf-test-network-2%{random_suffix}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_dns_response_policy" "response-policy" { | ||
response_policy_name = "tf-test-example-response-policy%{random_suffix}" | ||
networks { | ||
network_url = google_compute_network.network-1.id | ||
} | ||
networks { | ||
network_url = google_compute_network.network-2.id | ||
} | ||
} | ||
resource "google_dns_response_policy_rule" "example-response-policy-rule" { | ||
response_policy = google_dns_response_policy.response-policy.response_policy_name | ||
rule_name = "tf-test-example-rule%{random_suffix}" | ||
dns_name = "dns.example.com." | ||
local_data { | ||
local_datas { | ||
name = "dns.example.com." | ||
type = "A" | ||
ttl = 300 | ||
rrdatas = ["192.0.2.91"] | ||
} | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckDNSResponsePolicyRuleDestroyProducer(t *testing.T) func(s *terraform.State) error { | ||
return func(s *terraform.State) error { | ||
for name, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_dns_response_policy_rule" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := acctest.GoogleProviderConfig(t) | ||
|
||
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{DNSBasePath}}projects/{{project}}/responsePolicies/{{response_policy}}/rules/{{rule_name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
if config.BillingProject != "" { | ||
billingProject = config.BillingProject | ||
} | ||
|
||
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: config.UserAgent, | ||
}) | ||
if err == nil { | ||
return fmt.Errorf("DNSResponsePolicyRule still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.