Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new resource "Router Nat Address" #8227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/11390.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:new-resource
`google_compute_router_nat_address`
```
```release-note:enhancement
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`
```
5 changes: 3 additions & 2 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 528
// Generated resources: 529
// Generated IAM resources: 291
// Total generated resources: 819
// Total generated resources: 820
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -763,6 +763,7 @@ var generatedResources = map[string]*schema.Resource{
"google_compute_route": compute.ResourceComputeRoute(),
"google_compute_router": compute.ResourceComputeRouter(),
"google_compute_router_nat": compute.ResourceComputeRouterNat(),
"google_compute_router_nat_address": compute.ResourceComputeRouterNatAddress(),
"google_compute_router_route_policy": compute.ResourceComputeRouterRoutePolicy(),
"google_compute_security_policy_rule": compute.ResourceComputeSecurityPolicyRule(),
"google_compute_service_attachment": compute.ResourceComputeServiceAttachment(),
Expand Down
66 changes: 66 additions & 0 deletions google-beta/services/compute/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ project-level default tier is used. Possible values: ["PREMIUM", "STANDARD"]`,
},
"drain_nat_ips": {
Type: schema.TypeSet,
Computed: true,
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.`,
Expand Down Expand Up @@ -303,6 +304,19 @@ Supported values include:
Description: `Timeout (in seconds) for ICMP connections. Defaults to 30s if not set.`,
Default: 30,
},
"initial_nat_ips": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Description: `Self-links of NAT IPs to be used as initial value for creation alongside a RouterNatAddress resource.
Conflicts with natIps and drainNatIps. Only valid if natIpAllocateOption is set to MANUAL_ONLY.`,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
},
Set: computeRouterNatIPsHash,
ConflictsWith: []string{"nat_ips", "drain_nat_ips"},
},
"log_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -346,6 +360,7 @@ Platform, or 'MANUAL_ONLY' for only user-allocated NAT IP addresses. Possible va
},
"nat_ips": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Description: `Self-links of NAT IPs. Only valid if natIpAllocateOption
is set to MANUAL_ONLY.
Expand Down Expand Up @@ -583,6 +598,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("nat_ip_allocate_option"); !tpgresource.IsEmptyValue(reflect.ValueOf(natIpAllocateOptionProp)) && (ok || !reflect.DeepEqual(v, natIpAllocateOptionProp)) {
obj["natIpAllocateOption"] = natIpAllocateOptionProp
}
initialNatIpsProp, err := expandNestedComputeRouterNatInitialNatIps(d.Get("initial_nat_ips"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("initial_nat_ips"); ok || !reflect.DeepEqual(v, initialNatIpsProp) {
obj["initialNatIps"] = initialNatIpsProp
}
natIpsProp, err := expandNestedComputeRouterNatNatIps(d.Get("nat_ips"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -692,6 +713,11 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
obj["autoNetworkTier"] = autoNetworkTierProp
}

obj, err = resourceComputeRouterNatEncoder(d, meta, obj)
if err != nil {
return err
}

lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
if err != nil {
return err
Expand Down Expand Up @@ -1023,6 +1049,11 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
obj["autoNetworkTier"] = autoNetworkTierProp
}

obj, err = resourceComputeRouterNatEncoder(d, meta, obj)
if err != nil {
return err
}

lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
if err != nil {
return err
Expand Down Expand Up @@ -1506,6 +1537,23 @@ func expandNestedComputeRouterNatNatIpAllocateOption(v interface{}, d tpgresourc
return v, nil
}

func expandNestedComputeRouterNatInitialNatIps(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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 initial_nat_ips: nil")
}
f, err := tpgresource.ParseRegionalFieldValue("addresses", raw.(string), "project", "region", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for initial_nat_ips: %s", err)
}
req = append(req, f.RelativeLink())
}
return req, nil
}

func expandNestedComputeRouterNatNatIps(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
v = v.(*schema.Set).List()
l := v.([]interface{})
Expand Down Expand Up @@ -1845,6 +1893,24 @@ func expandNestedComputeRouterNatAutoNetworkTier(v interface{}, d tpgresource.Te
return v, nil
}

func resourceComputeRouterNatEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// initial_nat_ips uses the same api_name as nat_ips
if tpgresource.IsEmptyValue(reflect.ValueOf(obj["initialNatIps"])) {
return obj, nil
}

newObj := make(map[string]interface{})
for key, value := range obj {
newObj[key] = value
}

newObj["natIps"] = obj["initialNatIps"]
delete(newObj, "initialNatIps")

log.Printf("[DEBUG] Replacing initialNatIps value \n oldObj: %+v \n newObj: %+v", obj, newObj)
return newObj, nil
}

func flattenNestedComputeRouterNat(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
var v interface{}
var ok bool
Expand Down
Loading