Skip to content

Commit

Permalink
Generate schema from the resource schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Sep 5, 2018
1 parent cd060c1 commit c0bb4b4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 377 deletions.
363 changes: 9 additions & 354 deletions google/data_source_google_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
12 changes: 6 additions & 6 deletions google/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit c0bb4b4

Please sign in to comment.