diff --git a/google/data_source_google_compute_instance.go b/google/data_source_google_compute_instance.go index c49faeafcdf..d76b864bb50 100644 --- a/google/data_source_google_compute_instance.go +++ b/google/data_source_google_compute_instance.go @@ -6,363 +6,18 @@ import ( ) func dataSourceGoogleComputeInstance() *schema.Resource { - return &schema.Resource{ - Read: dataSourceGoogleComputeInstanceRead, - - Schema: map[string]*schema.Schema{ - "boot_disk": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "auto_delete": &schema.Schema{ - Type: schema.TypeBool, - Computed: true, - }, - - "device_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - // TODO(rileykarson): Remove this field. - "disk_encryption_key_raw": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Sensitive: true, - Removed: "Field not in use.", - }, - - "disk_encryption_key_sha256": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "initialize_params": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "size": &schema.Schema{ - Type: schema.TypeInt, - Computed: true, - }, - - "type": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "image": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "source": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "machine_type": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "name": &schema.Schema{ - Type: schema.TypeString, - Required: true, - }, - - "network_interface": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "network": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "subnetwork": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "subnetwork_project": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "address": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - // TODO(rileykarson): Remove this field. - "network_ip": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Removed: "Do not use this field. Use `address` instead.", - }, - - "access_config": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nat_ip": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "network_tier": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - // TODO(rileykarson): Remove this field. - "assigned_nat_ip": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Removed: "Do not use this field. Use `nat_ip` instead.", - }, - - "public_ptr_domain_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "alias_ip_range": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip_cidr_range": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - "subnetwork_range_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - - "attached_disk": &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "source": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "device_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, + // Generate datasource schema from resource + dsSchema := datasourceSchemaFromResourceSchema(resourceComputeInstance().Schema) - "mode": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, + // Set 'Required' schema elements + addRequiredFieldsToSchema(dsSchema, "name") - // TODO(rileykarson): Remove this field. - "disk_encryption_key_raw": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Sensitive: true, - Removed: "Field not in use.", - }, + // Set 'Optional' schema elements + addOptionalFieldsToSchema(dsSchema, "project", "zone") - "disk_encryption_key_sha256": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "can_ip_forward": &schema.Schema{ - Type: schema.TypeBool, - Computed: true, - }, - - "description": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "deletion_protection": &schema.Schema{ - Type: schema.TypeBool, - Computed: true, - }, - - "guest_accelerator": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "count": &schema.Schema{ - Type: schema.TypeInt, - Computed: true, - }, - "type": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "labels": &schema.Schema{ - Type: schema.TypeMap, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - // "metadata_startup_script" lives under metadata - "metadata": &schema.Schema{ - Type: schema.TypeMap, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "min_cpu_platform": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "project": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - - "scheduling": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "on_host_maintenance": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "automatic_restart": &schema.Schema{ - Type: schema.TypeBool, - Computed: true, - }, - - "preemptible": &schema.Schema{ - Type: schema.TypeBool, - Computed: true, - }, - }, - }, - }, - - "scratch_disk": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "interface": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "service_account": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "email": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "scopes": &schema.Schema{ - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - StateFunc: func(v interface{}) string { - return canonicalizeServiceScope(v.(string)) - }, - }, - Set: stringScopeHashcode, - }, - }, - }, - }, - - "tags": &schema.Schema{ - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "zone": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - - "cpu_platform": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "instance_id": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "label_fingerprint": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "metadata_fingerprint": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "self_link": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "tags_fingerprint": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - }, + return &schema.Resource{ + Read: dataSourceGoogleComputeInstanceRead, + Schema: dsSchema, } } diff --git a/google/image_test.go b/google/image_test.go index 6eb9cfe0fd5..026d02e54c2 100644 --- a/google/image_test.go +++ b/google/image_test.go @@ -77,12 +77,12 @@ func testAccCheckComputeImageResolution(n string) resource.TestCheckFunc { "global/images/" + name: "global/images/" + name, "global/images/family/" + family: "global/images/family/" + family, - name: "global/images/" + name, - family: "global/images/family/" + family, - "family/" + family: "global/images/family/" + family, - project + "/" + name: "projects/" + project + "/global/images/" + name, - project + "/" + family: "projects/" + project + "/global/images/family/" + family, - link: link, + name: "global/images/" + name, + family: "global/images/family/" + family, + "family/" + family: "global/images/family/" + family, + project + "/" + name: "projects/" + project + "/global/images/" + name, + project + "/" + family: "projects/" + project + "/global/images/family/" + family, + link: link, } for input, expectation := range images { diff --git a/google/resource_compute_instance_migrate_test.go b/google/resource_compute_instance_migrate_test.go index e0c8c80f20b..871e22b0a86 100644 --- a/google/resource_compute_instance_migrate_test.go +++ b/google/resource_compute_instance_migrate_test.go @@ -156,7 +156,7 @@ func TestAccComputeInstanceMigrateState_bootDisk(t *testing.T) { "disk.0.device_name": "persistent-disk-0", "disk.0.disk_encryption_key_raw": "encrypt-key", "disk.0.disk_encryption_key_sha256": "encrypt-key-sha", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -223,7 +223,7 @@ func TestAccComputeInstanceMigrateState_v4FixBootDisk(t *testing.T) { "disk.0.device_name": "persistent-disk-0", "disk.0.disk_encryption_key_raw": "encrypt-key", "disk.0.disk_encryption_key_sha256": "encrypt-key-sha", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -305,7 +305,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) { "disk.0.device_name": "persistent-disk-1", "disk.0.disk_encryption_key_raw": "encrypt-key", "disk.0.disk_encryption_key_sha256": "encrypt-key-sha", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -385,7 +385,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T "disk.0.device_name": "persistent-disk-1", "disk.0.disk_encryption_key_raw": "encrypt-key", "disk.0.disk_encryption_key_sha256": "encrypt-key-sha", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -452,7 +452,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromEncryptionKey(t *testing "disk.0.image": "projects/debian-cloud/global/images/family/debian-9", "disk.0.disk_encryption_key_raw": "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=", "disk.0.disk_encryption_key_sha256": "esTuF7d4eatX4cnc4JsiEiaI+Rff78JgPhA/v1zxX9E=", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -520,7 +520,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromEncryptionKey(t *te "disk.0.image": "projects/debian-cloud/global/images/family/debian-9", "disk.0.disk_encryption_key_raw": "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=", "disk.0.disk_encryption_key_sha256": "esTuF7d4eatX4cnc4JsiEiaI+Rff78JgPhA/v1zxX9E=", - "zone": zone, + "zone": zone, } expected := map[string]string{ "boot_disk.#": "1", @@ -600,8 +600,8 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromAutoDeleteAndImage(t *te "attached_disk.0.device_name": "persistent-disk-2", "attached_disk.1.source": "https://www.googleapis.com/compute/v1/projects/" + config.Project + "/zones/" + zone + "/disks/" + instanceName + "-1", "attached_disk.1.device_name": "persistent-disk-1", - "zone": zone, - "create_timeout": "4", + "zone": zone, + "create_timeout": "4", } runInstanceMigrateTest(t, instanceName, "migrate disk to attached disk", 2 /* state version */, attributes, expected, config) @@ -672,7 +672,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromAutoDeleteAndImage( "attached_disk.0.device_name": "persistent-disk-2", "attached_disk.1.source": "https://www.googleapis.com/compute/v1/projects/" + config.Project + "/zones/" + zone + "/disks/" + instanceName + "-1", "attached_disk.1.device_name": "persistent-disk-1", - "zone": zone, + "zone": zone, } runInstanceMigrateTest(t, instanceName, "migrate disk to attached disk", 4 /* state version */, attributes, expected, config) @@ -735,8 +735,8 @@ func TestAccComputeInstanceMigrateState_scratchDisk(t *testing.T) { "boot_disk.#": "1", "scratch_disk.#": "1", "scratch_disk.0.interface": "SCSI", - "zone": zone, - "create_timeout": "4", + "zone": zone, + "create_timeout": "4", } runInstanceMigrateTest(t, instanceName, "migrate disk to scratch disk", 2 /* state version */, attributes, expected, config) @@ -799,7 +799,7 @@ func TestAccComputeInstanceMigrateState_v4FixScratchDisk(t *testing.T) { "boot_disk.#": "1", "scratch_disk.#": "1", "scratch_disk.0.interface": "SCSI", - "zone": zone, + "zone": zone, } runInstanceMigrateTest(t, instanceName, "migrate disk to scratch disk", 4 /* state version */, attributes, expected, config) diff --git a/google/resource_compute_network.go b/google/resource_compute_network.go index c615bc344b0..c30054e9901 100644 --- a/google/resource_compute_network.go +++ b/google/resource_compute_network.go @@ -95,7 +95,7 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro // Build the network parameter network := &compute.Network{ - Name: d.Get("name").(string), + Name: d.Get("name").(string), AutoCreateSubnetworks: autoCreateSubnetworks, Description: d.Get("description").(string), } diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 5770e92f3f9..aa8890fc36a 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -1225,7 +1225,7 @@ func flattenAuthorizedNetworks(entries []*sqladmin.AclEntry) interface{} { func flattenLocationPreference(locationPreference *sqladmin.LocationPreference) interface{} { data := map[string]interface{}{ "follow_gae_application": locationPreference.FollowGaeApplication, - "zone": locationPreference.Zone, + "zone": locationPreference.Zone, } return []map[string]interface{}{data} diff --git a/google/validation_test.go b/google/validation_test.go index 967ee5f7425..5a67a77db3e 100644 --- a/google/validation_test.go +++ b/google/validation_test.go @@ -247,15 +247,15 @@ func TestOrEmpty(t *testing.T) { ExpectValidationErrors bool }{ "accept empty value": { - Value: "", + Value: "", ExpectValidationErrors: false, }, "non empty value is accepted when valid": { - Value: "valid", + Value: "valid", ExpectValidationErrors: false, }, "non empty value is rejected if invalid": { - Value: "invalid", + Value: "invalid", ExpectValidationErrors: true, }, }