Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote google_dns_response_policy & google_dns_response_policy_rule to GA #15146

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/8308.txt
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)
```
6 changes: 4 additions & 2 deletions google/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,9 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) {
})
}

// Generated resources: 298
// Generated resources: 300
// Generated IAM resources: 198
// Total generated resources: 496
// Total generated resources: 498
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1242,6 +1242,8 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dns_managed_zone_iam_member": tpgiamresource.ResourceIamMember(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
"google_dns_managed_zone_iam_policy": tpgiamresource.ResourceIamPolicy(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
"google_dns_policy": dns.ResourceDNSPolicy(),
"google_dns_response_policy": dns.ResourceDNSResponsePolicy(),
"google_dns_response_policy_rule": dns.ResourceDNSResponsePolicyRule(),
"google_document_ai_processor": documentai.ResourceDocumentAIProcessor(),
"google_document_ai_processor_default_version": documentai.ResourceDocumentAIProcessorDefaultVersion(),
"google_essential_contacts_contact": essentialcontacts.ResourceEssentialContactsContact(),
Expand Down
168 changes: 168 additions & 0 deletions google/resource_dns_response_policy_generated_test.go
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 google/resource_dns_response_policy_rule_generated_test.go
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
}
}
Loading