From 240e5643b21e1d84f7cee678ab25ce7a66adf4a5 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 4 Mar 2020 00:56:22 +0000 Subject: [PATCH] Move drain_nat_ips to GA from beta. (#3209) Signed-off-by: Modular Magician --- .changelog/3209.txt | 3 ++ google/resource_compute_router_nat.go | 50 +++++++++++++++++++ .../docs/r/compute_router_nat.html.markdown | 5 ++ 3 files changed, 58 insertions(+) create mode 100644 .changelog/3209.txt diff --git a/.changelog/3209.txt b/.changelog/3209.txt new file mode 100644 index 00000000000..a834e240897 --- /dev/null +++ b/.changelog/3209.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: moved `google_compute_router_nat`'s `drain_nat_ips` from beta to ga. +``` diff --git a/google/resource_compute_router_nat.go b/google/resource_compute_router_nat.go index 590309f01e5..f84efcb8da6 100644 --- a/google/resource_compute_router_nat.go +++ b/google/resource_compute_router_nat.go @@ -161,6 +161,17 @@ contains ALL_SUBNETWORKS_ALL_IP_RANGES or ALL_SUBNETWORKS_ALL_PRIMARY_IP_RANGES, then there should not be any other RouterNat section in any Router for this network in this region.`, }, + "drain_nat_ips": { + Type: schema.TypeSet, + Optional: true, + Description: `A list of URLs of the IP resources to be drained. These IPs must be +valid static external IPs that have been assigned to the NAT.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + // Default schema.HashSchema is used. + }, "icmp_idle_timeout_sec": { Type: schema.TypeInt, Optional: true, @@ -311,6 +322,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er } else if v, ok := d.GetOkExists("nat_ips"); ok || !reflect.DeepEqual(v, natIpsProp) { obj["natIps"] = natIpsProp } + drainNatIpsProp, err := expandComputeRouterNatDrainNatIps(d.Get("drain_nat_ips"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("drain_nat_ips"); ok || !reflect.DeepEqual(v, drainNatIpsProp) { + obj["drainNatIps"] = drainNatIpsProp + } sourceSubnetworkIpRangesToNatProp, err := expandComputeRouterNatSourceSubnetworkIpRangesToNat(d.Get("source_subnetwork_ip_ranges_to_nat"), d, config) if err != nil { return err @@ -451,6 +468,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro if err := d.Set("nat_ips", flattenComputeRouterNatNatIps(res["natIps"], d, config)); err != nil { return fmt.Errorf("Error reading RouterNat: %s", err) } + if err := d.Set("drain_nat_ips", flattenComputeRouterNatDrainNatIps(res["drainNatIps"], d, config)); err != nil { + return fmt.Errorf("Error reading RouterNat: %s", err) + } if err := d.Set("source_subnetwork_ip_ranges_to_nat", flattenComputeRouterNatSourceSubnetworkIpRangesToNat(res["sourceSubnetworkIpRangesToNat"], d, config)); err != nil { return fmt.Errorf("Error reading RouterNat: %s", err) } @@ -500,6 +520,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er } else if v, ok := d.GetOkExists("nat_ips"); ok || !reflect.DeepEqual(v, natIpsProp) { obj["natIps"] = natIpsProp } + drainNatIpsProp, err := expandComputeRouterNatDrainNatIps(d.Get("drain_nat_ips"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("drain_nat_ips"); ok || !reflect.DeepEqual(v, drainNatIpsProp) { + obj["drainNatIps"] = drainNatIpsProp + } sourceSubnetworkIpRangesToNatProp, err := expandComputeRouterNatSourceSubnetworkIpRangesToNat(d.Get("source_subnetwork_ip_ranges_to_nat"), d, config) if err != nil { return err @@ -665,6 +691,13 @@ func flattenComputeRouterNatNatIps(v interface{}, d *schema.ResourceData, config return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) } +func flattenComputeRouterNatDrainNatIps(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) +} + func flattenComputeRouterNatSourceSubnetworkIpRangesToNat(v interface{}, d *schema.ResourceData, config *Config) interface{} { return v } @@ -824,6 +857,23 @@ func expandComputeRouterNatNatIps(v interface{}, d TerraformResourceData, config return req, nil } +func expandComputeRouterNatDrainNatIps(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + v = v.(*schema.Set).List() + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + return nil, fmt.Errorf("Invalid value for drain_nat_ips: nil") + } + f, err := parseRegionalFieldValue("addresses", raw.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for drain_nat_ips: %s", err) + } + req = append(req, f.RelativeLink()) + } + return req, nil +} + func expandComputeRouterNatSourceSubnetworkIpRangesToNat(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/compute_router_nat.html.markdown b/website/docs/r/compute_router_nat.html.markdown index c3ea2d2a71a..8bcf8db2fd7 100644 --- a/website/docs/r/compute_router_nat.html.markdown +++ b/website/docs/r/compute_router_nat.html.markdown @@ -154,6 +154,11 @@ The following arguments are supported: Self-links of NAT IPs. Only valid if natIpAllocateOption is set to MANUAL_ONLY. +* `drain_nat_ips` - + (Optional) + A list of URLs of the IP resources to be drained. These IPs must be + valid static external IPs that have been assigned to the NAT. + * `subnetwork` - (Optional) One or more subnetwork NAT configurations. Only used if