Skip to content

Commit

Permalink
Autogenerate Subnetwork. (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
modular-magician authored and nat-henderson committed Jun 19, 2018
1 parent fbfdd47 commit 57a2e98
Show file tree
Hide file tree
Showing 19 changed files with 894 additions and 546 deletions.
1 change: 1 addition & 0 deletions google/provider_compute_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var GeneratedComputeResourcesMap = map[string]*schema.Resource{
"google_compute_https_health_check": resourceComputeHttpsHealthCheck(),
"google_compute_route": resourceComputeRoute(),
"google_compute_ssl_policy": resourceComputeSslPolicy(),
"google_compute_subnetwork": resourceComputeSubnetwork(),
"google_compute_target_http_proxy": resourceComputeTargetHttpProxy(),
"google_compute_target_https_proxy": resourceComputeTargetHttpsProxy(),
"google_compute_target_ssl_proxy": resourceComputeTargetSslProxy(),
Expand Down
26 changes: 16 additions & 10 deletions google/resource_compute_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package google
import (
"fmt"
"log"
"reflect"
"time"

"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -118,43 +119,48 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro
return err
}

obj := make(map[string]interface{})
addressProp, err := expandComputeAddressAddress(d.Get("address"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("address"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, addressProp)) {
obj["address"] = addressProp
}
addressTypeProp, err := expandComputeAddressAddressType(d.Get("address_type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("address_type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, addressTypeProp)) {
obj["addressType"] = addressTypeProp
}
descriptionProp, err := expandComputeAddressDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
nameProp, err := expandComputeAddressName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
networkTierProp, err := expandComputeAddressNetworkTier(d.Get("network_tier"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("network_tier"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, networkTierProp)) {
obj["networkTier"] = networkTierProp
}
subnetworkProp, err := expandComputeAddressSubnetwork(d.Get("subnetwork"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("subnetwork"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, subnetworkProp)) {
obj["subnetwork"] = subnetworkProp
}
regionProp, err := expandComputeAddressRegion(d.Get("region"), d, config)
if err != nil {
return err
}

obj := map[string]interface{}{
"address": addressProp,
"addressType": addressTypeProp,
"description": descriptionProp,
"name": nameProp,
"networkTier": networkTierProp,
"subnetwork": subnetworkProp,
"region": regionProp,
} else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, regionProp)) {
obj["region"] = regionProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses")
Expand Down
33 changes: 19 additions & 14 deletions google/resource_compute_backend_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package google
import (
"fmt"
"log"
"reflect"
"time"

"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -85,28 +86,30 @@ func resourceComputeBackendBucketCreate(d *schema.ResourceData, meta interface{}
return err
}

obj := make(map[string]interface{})
bucketNameProp, err := expandComputeBackendBucketBucketName(d.Get("bucket_name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("bucket_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bucketNameProp)) {
obj["bucketName"] = bucketNameProp
}
descriptionProp, err := expandComputeBackendBucketDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
enableCdnProp, err := expandComputeBackendBucketEnableCdn(d.Get("enable_cdn"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_cdn"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableCdnProp)) {
obj["enableCdn"] = enableCdnProp
}
nameProp, err := expandComputeBackendBucketName(d.Get("name"), d, config)
if err != nil {
return err
}

obj := map[string]interface{}{
"bucketName": bucketNameProp,
"description": descriptionProp,
"enableCdn": enableCdnProp,
"name": nameProp,
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets")
Expand Down Expand Up @@ -199,28 +202,30 @@ func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{}
return err
}

obj := make(map[string]interface{})
bucketNameProp, err := expandComputeBackendBucketBucketName(d.Get("bucket_name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("bucket_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bucketNameProp)) {
obj["bucketName"] = bucketNameProp
}
descriptionProp, err := expandComputeBackendBucketDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
enableCdnProp, err := expandComputeBackendBucketEnableCdn(d.Get("enable_cdn"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_cdn"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableCdnProp)) {
obj["enableCdn"] = enableCdnProp
}
nameProp, err := expandComputeBackendBucketName(d.Get("name"), d, config)
if err != nil {
return err
}

obj := map[string]interface{}{
"bucketName": bucketNameProp,
"description": descriptionProp,
"enableCdn": enableCdnProp,
"name": nameProp,
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets/{{name}}")
Expand Down
52 changes: 31 additions & 21 deletions google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package google
import (
"fmt"
"log"
"reflect"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -434,64 +435,74 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

obj := make(map[string]interface{})
descriptionProp, err := expandComputeDiskDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
labelsProp, err := expandComputeDiskLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
nameProp, err := expandComputeDiskName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
sizeGbProp, err := expandComputeDiskSize(d.Get("size"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("size"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sizeGbProp)) {
obj["sizeGb"] = sizeGbProp
}
sourceImageProp, err := expandComputeDiskImage(d.Get("image"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("image"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceImageProp)) {
obj["sourceImage"] = sourceImageProp
}
typeProp, err := expandComputeDiskType(d.Get("type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
zoneProp, err := expandComputeDiskZone(d.Get("zone"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("zone"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, zoneProp)) {
obj["zone"] = zoneProp
}
diskEncryptionKeyProp, err := expandComputeDiskDiskEncryptionKey(d.Get("disk_encryption_key"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("disk_encryption_key"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, diskEncryptionKeyProp)) {
obj["diskEncryptionKey"] = diskEncryptionKeyProp
}
sourceImageEncryptionKeyProp, err := expandComputeDiskSourceImageEncryptionKey(d.Get("source_image_encryption_key"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("source_image_encryption_key"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceImageEncryptionKeyProp)) {
obj["sourceImageEncryptionKey"] = sourceImageEncryptionKeyProp
}
sourceSnapshotProp, err := expandComputeDiskSnapshot(d.Get("snapshot"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("snapshot"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceSnapshotProp)) {
obj["sourceSnapshot"] = sourceSnapshotProp
}
sourceSnapshotEncryptionKeyProp, err := expandComputeDiskSourceSnapshotEncryptionKey(d.Get("source_snapshot_encryption_key"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("source_snapshot_encryption_key"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceSnapshotEncryptionKeyProp)) {
obj["sourceSnapshotEncryptionKey"] = sourceSnapshotEncryptionKeyProp
}

obj := map[string]interface{}{
"description": descriptionProp,
"labels": labelsProp,
"name": nameProp,
"sizeGb": sizeGbProp,
"sourceImage": sourceImageProp,
"type": typeProp,
"zone": zoneProp,
"diskEncryptionKey": diskEncryptionKeyProp,
"sourceImageEncryptionKey": sourceImageEncryptionKeyProp,
"sourceSnapshot": sourceSnapshotProp,
"sourceSnapshotEncryptionKey": sourceSnapshotEncryptionKeyProp,
}
obj, err = resourceComputeDiskEncoder(d, meta, obj)
if err != nil {
return err
Expand Down Expand Up @@ -631,24 +642,23 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
return err
}

var obj map[string]interface{}
var url string
var res map[string]interface{}
op := &compute.Operation{}

d.Partial(true)

if d.HasChange("label_fingerprint") || d.HasChange("labels") {
obj := make(map[string]interface{})
labelFingerprintProp := d.Get("label_fingerprint")
obj["labelFingerprint"] = labelFingerprintProp
labelsProp, err := expandComputeDiskLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}

obj = map[string]interface{}{
"labelFingerprint": labelFingerprintProp,
"labels": labelsProp,
}
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels")
if err != nil {
return err
Expand All @@ -675,14 +685,14 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("labels")
}
if d.HasChange("size") {
obj := make(map[string]interface{})
sizeGbProp, err := expandComputeDiskSize(d.Get("size"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("size"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sizeGbProp)) {
obj["sizeGb"] = sizeGbProp
}

obj = map[string]interface{}{
"sizeGb": sizeGbProp,
}
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/resize")
if err != nil {
return err
Expand Down
14 changes: 8 additions & 6 deletions google/resource_compute_global_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package google
import (
"fmt"
"log"
"reflect"
"time"

"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -87,23 +88,24 @@ func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{}
return err
}

obj := make(map[string]interface{})
descriptionProp, err := expandComputeGlobalAddressDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
nameProp, err := expandComputeGlobalAddressName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
ipVersionProp, err := expandComputeGlobalAddressIpVersion(d.Get("ip_version"), d, config)
if err != nil {
return err
}

obj := map[string]interface{}{
"description": descriptionProp,
"name": nameProp,
"ipVersion": ipVersionProp,
} else if v, ok := d.GetOkExists("ip_version"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipVersionProp)) {
obj["ipVersion"] = ipVersionProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses")
Expand Down
Loading

0 comments on commit 57a2e98

Please sign in to comment.