Skip to content

Commit

Permalink
Autogenerate compute router NAT (#4401)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and emilymye committed Sep 9, 2019
1 parent 6fcc05b commit 4f4cf19
Show file tree
Hide file tree
Showing 7 changed files with 976 additions and 418 deletions.
6 changes: 3 additions & 3 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ func Provider() terraform.ResourceProvider {
return provider
}

// Generated resources: 78
// Generated resources: 79
// Generated IAM resources: 18
// Total generated resources: 96
// Total generated resources: 97
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -464,6 +464,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_compute_region_disk": resourceComputeRegionDisk(),
"google_compute_route": resourceComputeRoute(),
"google_compute_router": resourceComputeRouter(),
"google_compute_router_nat": resourceComputeRouterNat(),
"google_compute_snapshot": resourceComputeSnapshot(),
"google_compute_ssl_certificate": resourceComputeSslCertificate(),
"google_compute_ssl_policy": resourceComputeSslPolicy(),
Expand Down Expand Up @@ -547,7 +548,6 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_compute_project_metadata_item": resourceComputeProjectMetadataItem(),
"google_compute_region_instance_group_manager": resourceComputeRegionInstanceGroupManager(),
"google_compute_router_interface": resourceComputeRouterInterface(),
"google_compute_router_nat": resourceComputeRouterNat(),
"google_compute_router_peer": resourceComputeRouterPeer(),
"google_compute_security_policy": resourceComputeSecurityPolicy(),
"google_compute_shared_vpc_host_project": resourceComputeSharedVpcHostProject(),
Expand Down
18 changes: 12 additions & 6 deletions google/resource_compute_backend_bucket_signed_url_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,21 @@ func flattenNestedComputeBackendBucketSignedUrlKey(d *schema.ResourceData, meta
return nil, fmt.Errorf("expected list or map for value cdnPolicy.signedUrlKeyNames. Actual value: %v", v)
}

expectedName, err := expandComputeBackendBucketSignedUrlKeyName(d.Get("name"), d, meta.(*Config))
_, item, err := resourceComputeBackendBucketSignedUrlKeyFindNestedObjectInList(d, meta, v.([]interface{}))
if err != nil {
return nil, err
}
return item, nil
}

func resourceComputeBackendBucketSignedUrlKeyFindNestedObjectInList(d *schema.ResourceData, meta interface{}, items []interface{}) (index int, item map[string]interface{}, err error) {
expectedName, err := expandComputeBackendBucketSignedUrlKeyName(d.Get("name"), d, meta.(*Config))
if err != nil {
return -1, nil, err
}

// Search list for this resource.
items := v.([]interface{})
for _, itemRaw := range items {
for idx, itemRaw := range items {
if itemRaw == nil {
continue
}
Expand All @@ -290,8 +297,7 @@ func flattenNestedComputeBackendBucketSignedUrlKey(d *schema.ResourceData, meta
continue
}
log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item)
return item, nil
return idx, item, nil
}

return nil, nil
return -1, nil, nil
}
18 changes: 12 additions & 6 deletions google/resource_compute_backend_service_signed_url_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,21 @@ func flattenNestedComputeBackendServiceSignedUrlKey(d *schema.ResourceData, meta
return nil, fmt.Errorf("expected list or map for value cdnPolicy.signedUrlKeyNames. Actual value: %v", v)
}

expectedName, err := expandComputeBackendServiceSignedUrlKeyName(d.Get("name"), d, meta.(*Config))
_, item, err := resourceComputeBackendServiceSignedUrlKeyFindNestedObjectInList(d, meta, v.([]interface{}))
if err != nil {
return nil, err
}
return item, nil
}

func resourceComputeBackendServiceSignedUrlKeyFindNestedObjectInList(d *schema.ResourceData, meta interface{}, items []interface{}) (index int, item map[string]interface{}, err error) {
expectedName, err := expandComputeBackendServiceSignedUrlKeyName(d.Get("name"), d, meta.(*Config))
if err != nil {
return -1, nil, err
}

// Search list for this resource.
items := v.([]interface{})
for _, itemRaw := range items {
for idx, itemRaw := range items {
if itemRaw == nil {
continue
}
Expand All @@ -290,8 +297,7 @@ func flattenNestedComputeBackendServiceSignedUrlKey(d *schema.ResourceData, meta
continue
}
log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item)
return item, nil
return idx, item, nil
}

return nil, nil
return -1, nil, nil
}
25 changes: 15 additions & 10 deletions google/resource_compute_network_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,29 @@ func flattenNestedComputeNetworkEndpoint(d *schema.ResourceData, meta interface{
return nil, fmt.Errorf("expected list or map for value items. Actual value: %v", v)
}

expectedInstance, err := expandComputeNetworkEndpointInstance(d.Get("instance"), d, meta.(*Config))
_, item, err := resourceComputeNetworkEndpointFindNestedObjectInList(d, meta, v.([]interface{}))
if err != nil {
return nil, err
}
return item, nil
}

func resourceComputeNetworkEndpointFindNestedObjectInList(d *schema.ResourceData, meta interface{}, items []interface{}) (index int, item map[string]interface{}, err error) {
expectedInstance, err := expandComputeNetworkEndpointInstance(d.Get("instance"), d, meta.(*Config))
if err != nil {
return -1, nil, err
}
expectedIpAddress, err := expandComputeNetworkEndpointIpAddress(d.Get("ip_address"), d, meta.(*Config))
if err != nil {
return nil, err
return -1, nil, err
}
expectedPort, err := expandComputeNetworkEndpointPort(d.Get("port"), d, meta.(*Config))
if err != nil {
return nil, err
return -1, nil, err
}

// Search list for this resource.
items := v.([]interface{})
for _, itemRaw := range items {
for idx, itemRaw := range items {
if itemRaw == nil {
continue
}
Expand All @@ -385,7 +392,7 @@ func flattenNestedComputeNetworkEndpoint(d *schema.ResourceData, meta interface{
// Decode list item before comparing.
item, err := resourceComputeNetworkEndpointDecoder(d, meta, item)
if err != nil {
return nil, err
return -1, nil, err
}

itemInstance := flattenComputeNetworkEndpointInstance(item["instance"], d)
Expand All @@ -404,12 +411,10 @@ func flattenNestedComputeNetworkEndpoint(d *schema.ResourceData, meta interface{
continue
}
log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item)
return item, nil
return idx, item, nil
}

return nil, nil
return -1, nil, nil
}

func resourceComputeNetworkEndpointDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
v, ok := res["networkEndpoint"]
if !ok || v == nil {
Expand Down
Loading

0 comments on commit 4f4cf19

Please sign in to comment.