From af99e22bf61ab43a2365540acda5bb3a44cd0c98 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 1 Apr 2019 09:53:34 -0700 Subject: [PATCH] Terraform: Cloud DNS logging (#573) /cc @drebes --- google-beta/resource_dns_policy.go | 30 ++++++++++++++++++- .../resource_dns_policy_generated_test.go | 2 ++ website/docs/r/dns_policy.html.markdown | 7 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/google-beta/resource_dns_policy.go b/google-beta/resource_dns_policy.go index 59e1b5d128..ac3e548c82 100644 --- a/google-beta/resource_dns_policy.go +++ b/google-beta/resource_dns_policy.go @@ -80,6 +80,10 @@ func resourceDnsPolicy() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "enable_logging": { + Type: schema.TypeBool, + Optional: true, + }, "networks": { Type: schema.TypeSet, Optional: true, @@ -148,6 +152,12 @@ func resourceDnsPolicyCreate(d *schema.ResourceData, meta interface{}) error { } else if v, ok := d.GetOkExists("enable_inbound_forwarding"); ok || !reflect.DeepEqual(v, enableInboundForwardingProp) { obj["enableInboundForwarding"] = enableInboundForwardingProp } + enableLoggingProp, err := expandDnsPolicyEnableLogging(d.Get("enable_logging"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_logging"); ok || !reflect.DeepEqual(v, enableLoggingProp) { + obj["enableLogging"] = enableLoggingProp + } nameProp, err := expandDnsPolicyName(d.Get("name"), d, config) if err != nil { return err @@ -214,6 +224,9 @@ func resourceDnsPolicyRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("enable_inbound_forwarding", flattenDnsPolicyEnableInboundForwarding(res["enableInboundForwarding"], d)); err != nil { return fmt.Errorf("Error reading Policy: %s", err) } + if err := d.Set("enable_logging", flattenDnsPolicyEnableLogging(res["enableLogging"], d)); err != nil { + return fmt.Errorf("Error reading Policy: %s", err) + } if err := d.Set("name", flattenDnsPolicyName(res["name"], d)); err != nil { return fmt.Errorf("Error reading Policy: %s", err) } @@ -229,7 +242,7 @@ func resourceDnsPolicyUpdate(d *schema.ResourceData, meta interface{}) error { d.Partial(true) - if d.HasChange("alternative_name_server_config") || d.HasChange("description") || d.HasChange("enable_inbound_forwarding") || d.HasChange("networks") { + if d.HasChange("alternative_name_server_config") || d.HasChange("description") || d.HasChange("enable_inbound_forwarding") || d.HasChange("enable_logging") || d.HasChange("networks") { obj := make(map[string]interface{}) alternativeNameServerConfigProp, err := expandDnsPolicyAlternativeNameServerConfig(d.Get("alternative_name_server_config"), d, config) if err != nil { @@ -249,6 +262,12 @@ func resourceDnsPolicyUpdate(d *schema.ResourceData, meta interface{}) error { } else if v, ok := d.GetOkExists("enable_inbound_forwarding"); ok || !reflect.DeepEqual(v, enableInboundForwardingProp) { obj["enableInboundForwarding"] = enableInboundForwardingProp } + enableLoggingProp, err := expandDnsPolicyEnableLogging(d.Get("enable_logging"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_logging"); ok || !reflect.DeepEqual(v, enableLoggingProp) { + obj["enableLogging"] = enableLoggingProp + } networksProp, err := expandDnsPolicyNetworks(d.Get("networks"), d, config) if err != nil { return err @@ -268,6 +287,7 @@ func resourceDnsPolicyUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("alternative_name_server_config") d.SetPartial("description") d.SetPartial("enable_inbound_forwarding") + d.SetPartial("enable_logging") d.SetPartial("networks") } @@ -377,6 +397,10 @@ func flattenDnsPolicyEnableInboundForwarding(v interface{}, d *schema.ResourceDa return v } +func flattenDnsPolicyEnableLogging(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenDnsPolicyName(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -465,6 +489,10 @@ func expandDnsPolicyEnableInboundForwarding(v interface{}, d TerraformResourceDa return v, nil } +func expandDnsPolicyEnableLogging(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandDnsPolicyName(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 065689e772..5c8f6d8fe1 100644 --- a/google-beta/resource_dns_policy_generated_test.go +++ b/google-beta/resource_dns_policy_generated_test.go @@ -51,6 +51,8 @@ resource "google_dns_policy" "example-policy" { name = "example-policy-%{random_suffix}" enable_inbound_forwarding = true + enable_logging = true + alternative_name_server_config { target_name_servers { ipv4_address = "172.16.1.10" diff --git a/website/docs/r/dns_policy.html.markdown b/website/docs/r/dns_policy.html.markdown index 4d677a411a..72cce60746 100644 --- a/website/docs/r/dns_policy.html.markdown +++ b/website/docs/r/dns_policy.html.markdown @@ -49,6 +49,8 @@ resource "google_dns_policy" "example-policy" { name = "example-policy" enable_inbound_forwarding = true + enable_logging = true + alternative_name_server_config { target_name_servers { ipv4_address = "172.16.1.10" @@ -116,6 +118,11 @@ The following arguments are supported: virtual IP address will be allocated from each of the sub-networks that are bound to this policy. +* `enable_logging` - + (Optional) + Controls whether logging is enabled for the networks bound to this policy. + Defaults to no logging if not set. + * `networks` - (Optional) List of network names specifying networks to which this policy is applied. Structure is documented below.