Skip to content

Commit 5e9eed8

Browse files
Added new resource "Router Nat Address" (#11390) (#8227)
[upstream:c7be32cb819c4471bc0d9d166ca736a48474ed03] Signed-off-by: Modular Magician <[email protected]>
1 parent cd98617 commit 5e9eed8

8 files changed

+1675
-2
lines changed

.changelog/11390.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:new-resource
2+
`google_compute_router_nat_address`
3+
```
4+
```release-note:enhancement
5+
compute: added 'initial_nat_ip' field to 'google_compute_router_nat' resource, to enable use of the fine-grained resource `google_compute_router_nat_address`
6+
```

google-beta/provider/provider_mmv1_resources.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
485485
}
486486

487487
// Resources
488-
// Generated resources: 528
488+
// Generated resources: 529
489489
// Generated IAM resources: 291
490-
// Total generated resources: 819
490+
// Total generated resources: 820
491491
var generatedResources = map[string]*schema.Resource{
492492
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
493493
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -763,6 +763,7 @@ var generatedResources = map[string]*schema.Resource{
763763
"google_compute_route": compute.ResourceComputeRoute(),
764764
"google_compute_router": compute.ResourceComputeRouter(),
765765
"google_compute_router_nat": compute.ResourceComputeRouterNat(),
766+
"google_compute_router_nat_address": compute.ResourceComputeRouterNatAddress(),
766767
"google_compute_router_route_policy": compute.ResourceComputeRouterRoutePolicy(),
767768
"google_compute_security_policy_rule": compute.ResourceComputeSecurityPolicyRule(),
768769
"google_compute_service_attachment": compute.ResourceComputeServiceAttachment(),

google-beta/services/compute/resource_compute_router_nat.go

+66
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ project-level default tier is used. Possible values: ["PREMIUM", "STANDARD"]`,
255255
},
256256
"drain_nat_ips": {
257257
Type: schema.TypeSet,
258+
Computed: true,
258259
Optional: true,
259260
Description: `A list of URLs of the IP resources to be drained. These IPs must be
260261
valid static external IPs that have been assigned to the NAT.`,
@@ -303,6 +304,19 @@ Supported values include:
303304
Description: `Timeout (in seconds) for ICMP connections. Defaults to 30s if not set.`,
304305
Default: 30,
305306
},
307+
"initial_nat_ips": {
308+
Type: schema.TypeSet,
309+
Optional: true,
310+
ForceNew: true,
311+
Description: `Self-links of NAT IPs to be used as initial value for creation alongside a RouterNatAddress resource.
312+
Conflicts with natIps and drainNatIps. Only valid if natIpAllocateOption is set to MANUAL_ONLY.`,
313+
Elem: &schema.Schema{
314+
Type: schema.TypeString,
315+
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
316+
},
317+
Set: computeRouterNatIPsHash,
318+
ConflictsWith: []string{"nat_ips", "drain_nat_ips"},
319+
},
306320
"log_config": {
307321
Type: schema.TypeList,
308322
Optional: true,
@@ -346,6 +360,7 @@ Platform, or 'MANUAL_ONLY' for only user-allocated NAT IP addresses. Possible va
346360
},
347361
"nat_ips": {
348362
Type: schema.TypeSet,
363+
Computed: true,
349364
Optional: true,
350365
Description: `Self-links of NAT IPs. Only valid if natIpAllocateOption
351366
is set to MANUAL_ONLY.
@@ -583,6 +598,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
583598
} else if v, ok := d.GetOkExists("nat_ip_allocate_option"); !tpgresource.IsEmptyValue(reflect.ValueOf(natIpAllocateOptionProp)) && (ok || !reflect.DeepEqual(v, natIpAllocateOptionProp)) {
584599
obj["natIpAllocateOption"] = natIpAllocateOptionProp
585600
}
601+
initialNatIpsProp, err := expandNestedComputeRouterNatInitialNatIps(d.Get("initial_nat_ips"), d, config)
602+
if err != nil {
603+
return err
604+
} else if v, ok := d.GetOkExists("initial_nat_ips"); ok || !reflect.DeepEqual(v, initialNatIpsProp) {
605+
obj["initialNatIps"] = initialNatIpsProp
606+
}
586607
natIpsProp, err := expandNestedComputeRouterNatNatIps(d.Get("nat_ips"), d, config)
587608
if err != nil {
588609
return err
@@ -692,6 +713,11 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
692713
obj["autoNetworkTier"] = autoNetworkTierProp
693714
}
694715

716+
obj, err = resourceComputeRouterNatEncoder(d, meta, obj)
717+
if err != nil {
718+
return err
719+
}
720+
695721
lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
696722
if err != nil {
697723
return err
@@ -1023,6 +1049,11 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
10231049
obj["autoNetworkTier"] = autoNetworkTierProp
10241050
}
10251051

1052+
obj, err = resourceComputeRouterNatEncoder(d, meta, obj)
1053+
if err != nil {
1054+
return err
1055+
}
1056+
10261057
lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
10271058
if err != nil {
10281059
return err
@@ -1506,6 +1537,23 @@ func expandNestedComputeRouterNatNatIpAllocateOption(v interface{}, d tpgresourc
15061537
return v, nil
15071538
}
15081539

1540+
func expandNestedComputeRouterNatInitialNatIps(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1541+
v = v.(*schema.Set).List()
1542+
l := v.([]interface{})
1543+
req := make([]interface{}, 0, len(l))
1544+
for _, raw := range l {
1545+
if raw == nil {
1546+
return nil, fmt.Errorf("Invalid value for initial_nat_ips: nil")
1547+
}
1548+
f, err := tpgresource.ParseRegionalFieldValue("addresses", raw.(string), "project", "region", "zone", d, config, true)
1549+
if err != nil {
1550+
return nil, fmt.Errorf("Invalid value for initial_nat_ips: %s", err)
1551+
}
1552+
req = append(req, f.RelativeLink())
1553+
}
1554+
return req, nil
1555+
}
1556+
15091557
func expandNestedComputeRouterNatNatIps(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
15101558
v = v.(*schema.Set).List()
15111559
l := v.([]interface{})
@@ -1845,6 +1893,24 @@ func expandNestedComputeRouterNatAutoNetworkTier(v interface{}, d tpgresource.Te
18451893
return v, nil
18461894
}
18471895

1896+
func resourceComputeRouterNatEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
1897+
// initial_nat_ips uses the same api_name as nat_ips
1898+
if tpgresource.IsEmptyValue(reflect.ValueOf(obj["initialNatIps"])) {
1899+
return obj, nil
1900+
}
1901+
1902+
newObj := make(map[string]interface{})
1903+
for key, value := range obj {
1904+
newObj[key] = value
1905+
}
1906+
1907+
newObj["natIps"] = obj["initialNatIps"]
1908+
delete(newObj, "initialNatIps")
1909+
1910+
log.Printf("[DEBUG] Replacing initialNatIps value \n oldObj: %+v \n newObj: %+v", obj, newObj)
1911+
return newObj, nil
1912+
}
1913+
18481914
func flattenNestedComputeRouterNat(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
18491915
var v interface{}
18501916
var ok bool

0 commit comments

Comments
 (0)