From 4f4c5481e17d0a335f705c37b5df7e79a649f283 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 2 Oct 2020 18:35:33 +0000 Subject: [PATCH] feat: Add forwarding_path to google_dns_policy (#4045) Signed-off-by: Modular Magician --- .changelog/4045.txt | 3 +++ google-beta/resource_dns_policy.go | 27 ++++++++++++++++++- .../resource_dns_policy_generated_test.go | 3 ++- google-beta/resource_dns_policy_test.go | 12 ++++++--- website/docs/r/dns_policy.html.markdown | 10 ++++++- 5 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .changelog/4045.txt diff --git a/.changelog/4045.txt b/.changelog/4045.txt new file mode 100644 index 0000000000..5fe28a9d8b --- /dev/null +++ b/.changelog/4045.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +dns: added `forwarding_path` field to `google_dns_policy` resource +``` diff --git a/google-beta/resource_dns_policy.go b/google-beta/resource_dns_policy.go index 9065b83b2e..cc5b7caa59 100644 --- a/google-beta/resource_dns_policy.go +++ b/google-beta/resource_dns_policy.go @@ -23,6 +23,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func resourceDNSPolicy() *schema.Resource { @@ -131,6 +132,14 @@ func dnsPolicyAlternativeNameServerConfigTargetNameServersSchema() *schema.Resou Required: true, Description: `IPv4 address to forward to.`, }, + "forwarding_path": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"default", "private", ""}, false), + Description: `Forwarding path for this TargetNameServer. If unset or 'default' Cloud DNS will make forwarding +decision based on address ranges, i.e. RFC1918 addresses go to the VPC, Non-RFC1918 addresses go +to the Internet. When set to 'private', Cloud DNS will always send queries through VPC for this target Possible values: ["default", "private"]`, + }, }, } } @@ -470,7 +479,8 @@ func flattenDNSPolicyAlternativeNameServerConfigTargetNameServers(v interface{}, continue } transformed.Add(map[string]interface{}{ - "ipv4_address": flattenDNSPolicyAlternativeNameServerConfigTargetNameServersIpv4Address(original["ipv4Address"], d, config), + "ipv4_address": flattenDNSPolicyAlternativeNameServerConfigTargetNameServersIpv4Address(original["ipv4Address"], d, config), + "forwarding_path": flattenDNSPolicyAlternativeNameServerConfigTargetNameServersForwardingPath(original["forwardingPath"], d, config), }) } return transformed @@ -479,6 +489,10 @@ func flattenDNSPolicyAlternativeNameServerConfigTargetNameServersIpv4Address(v i return v } +func flattenDNSPolicyAlternativeNameServerConfigTargetNameServersForwardingPath(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func flattenDNSPolicyDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { return v } @@ -562,6 +576,13 @@ func expandDNSPolicyAlternativeNameServerConfigTargetNameServers(v interface{}, transformed["ipv4Address"] = transformedIpv4Address } + transformedForwardingPath, err := expandDNSPolicyAlternativeNameServerConfigTargetNameServersForwardingPath(original["forwarding_path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedForwardingPath); val.IsValid() && !isEmptyValue(val) { + transformed["forwardingPath"] = transformedForwardingPath + } + req = append(req, transformed) } return req, nil @@ -571,6 +592,10 @@ func expandDNSPolicyAlternativeNameServerConfigTargetNameServersIpv4Address(v in return v, nil } +func expandDNSPolicyAlternativeNameServerConfigTargetNameServersForwardingPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandDNSPolicyDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google-beta/resource_dns_policy_generated_test.go b/google-beta/resource_dns_policy_generated_test.go index f4d1e4d9b6..bba9c2f7df 100644 --- a/google-beta/resource_dns_policy_generated_test.go +++ b/google-beta/resource_dns_policy_generated_test.go @@ -60,7 +60,8 @@ resource "google_dns_policy" "example-policy" { alternative_name_server_config { target_name_servers { - ipv4_address = "172.16.1.10" + ipv4_address = "172.16.1.10" + forwarding_path = "private" } target_name_servers { ipv4_address = "172.16.1.20" diff --git a/google-beta/resource_dns_policy_test.go b/google-beta/resource_dns_policy_test.go index 18de1bcaa7..2c6ec12f7c 100644 --- a/google-beta/resource_dns_policy_test.go +++ b/google-beta/resource_dns_policy_test.go @@ -18,7 +18,7 @@ func TestAccDNSPolicy_update(t *testing.T) { CheckDestroy: testAccCheckDNSPolicyDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccDnsPolicy_privateUpdate(policySuffix, "true", "172.16.1.10", "network-1"), + Config: testAccDnsPolicy_privateUpdate(policySuffix, "true", "172.16.1.10", "172.16.1.30", "network-1"), }, { ResourceName: "google_dns_policy.example-policy", @@ -26,7 +26,7 @@ func TestAccDNSPolicy_update(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccDnsPolicy_privateUpdate(policySuffix, "false", "172.16.1.20", "network-2"), + Config: testAccDnsPolicy_privateUpdate(policySuffix, "false", "172.16.1.20", "172.16.1.40", "network-2"), }, { ResourceName: "google_dns_policy.example-policy", @@ -37,7 +37,7 @@ func TestAccDNSPolicy_update(t *testing.T) { }) } -func testAccDnsPolicy_privateUpdate(suffix, forwarding, nameserver, network string) string { +func testAccDnsPolicy_privateUpdate(suffix, forwarding, first_nameserver, second_nameserver, network string) string { return fmt.Sprintf(` resource "google_dns_policy" "example-policy" { name = "example-policy-%s" @@ -46,6 +46,10 @@ resource "google_dns_policy" "example-policy" { alternative_name_server_config { target_name_servers { ipv4_address = "%s" + } + target_name_servers { + ipv4_address = "%s" + forwarding_path = "private" } } @@ -63,5 +67,5 @@ resource "google_compute_network" "network-2" { name = "network-2-%s" auto_create_subnetworks = false } -`, suffix, forwarding, nameserver, network, suffix, suffix) +`, suffix, forwarding, first_nameserver, second_nameserver, network, suffix, suffix) } diff --git a/website/docs/r/dns_policy.html.markdown b/website/docs/r/dns_policy.html.markdown index a74f65bc1b..37a3bf3852 100644 --- a/website/docs/r/dns_policy.html.markdown +++ b/website/docs/r/dns_policy.html.markdown @@ -50,7 +50,8 @@ resource "google_dns_policy" "example-policy" { alternative_name_server_config { target_name_servers { - ipv4_address = "172.16.1.10" + ipv4_address = "172.16.1.10" + forwarding_path = "private" } target_name_servers { ipv4_address = "172.16.1.20" @@ -137,6 +138,13 @@ The `target_name_servers` block supports: (Required) IPv4 address to forward to. +* `forwarding_path` - + (Optional) + Forwarding path for this TargetNameServer. If unset or `default` Cloud DNS will make forwarding + decision based on address ranges, i.e. RFC1918 addresses go to the VPC, Non-RFC1918 addresses go + to the Internet. When set to `private`, Cloud DNS will always send queries through VPC for this target + Possible values are `default` and `private`. + The `networks` block supports: * `network_url` -