Skip to content

Commit

Permalink
Move drain_nat_ips to GA from beta. (#3209) (#5821)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 4, 2020
1 parent fd0c36f commit 8909a0a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3209.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: moved `google_compute_router_nat`'s `drain_nat_ips` from beta to ga.
```
50 changes: 50 additions & 0 deletions google/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/compute_router_nat.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8909a0a

Please sign in to comment.