Skip to content

Commit

Permalink
remove compute API usage in third_party/validator/compute_instance.go
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
yukinying authored and modular-magician committed Aug 15, 2019
1 parent be9991d commit 4521753
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 8 additions & 10 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,34 +641,32 @@ func getDisk(diskUri string, d *schema.ResourceData, config *Config) (*compute.D
return disk, err
}

func expandComputeInstance(project string, zone *compute.Zone, d *schema.ResourceData, config *Config) (*computeBeta.Instance, error) {
func expandComputeInstance(project string, d *schema.ResourceData, config *Config) (*computeBeta.Instance, error) {
// Get the machine type
var machineTypeUrl string
if mt, ok := d.GetOk("machine_type"); ok {
log.Printf("[DEBUG] Loading machine type: %s", mt.(string))
machineType, err := config.clientCompute.MachineTypes.Get(
project, zone.Name, mt.(string)).Do()
machineType, err := ParseMachineTypesFieldValue(mt.(string), d, config)
if err != nil {
return nil, fmt.Errorf(
"Error loading machine type: %s",
err)
}
machineTypeUrl = machineType.SelfLink
machineTypeUrl = machineType.RelativeLink()
}

// Build up the list of disks

disks := []*computeBeta.AttachedDisk{}
if _, hasBootDisk := d.GetOk("boot_disk"); hasBootDisk {
bootDisk, err := expandBootDisk(d, config, zone, project)
bootDisk, err := expandBootDisk(d, config, project)
if err != nil {
return nil, err
}
disks = append(disks, bootDisk)
}

if _, hasScratchDisk := d.GetOk("scratch_disk"); hasScratchDisk {
scratchDisks, err := expandScratchDisks(d, config, zone, project)
scratchDisks, err := expandScratchDisks(d, config, project)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -749,7 +747,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error loading zone '%s': %s", z, err)
}

instance, err := expandComputeInstance(project, zone, d, config)
instance, err := expandComputeInstance(project, d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -1601,7 +1599,7 @@ func resourceComputeInstanceImportState(d *schema.ResourceData, meta interface{}
return []*schema.ResourceData{d}, nil
}

func expandBootDisk(d *schema.ResourceData, config *Config, zone *compute.Zone, project string) (*computeBeta.AttachedDisk, error) {
func expandBootDisk(d *schema.ResourceData, config *Config, project string) (*computeBeta.AttachedDisk, error) {
disk := &computeBeta.AttachedDisk{
AutoDelete: d.Get("boot_disk.0.auto_delete").(bool),
Boot: true,
Expand Down Expand Up @@ -1714,7 +1712,7 @@ func flattenBootDisk(d *schema.ResourceData, disk *computeBeta.AttachedDisk, con
return []map[string]interface{}{result}
}

func expandScratchDisks(d *schema.ResourceData, config *Config, zone *compute.Zone, project string) ([]*computeBeta.AttachedDisk, error) {
func expandScratchDisks(d *schema.ResourceData, config *Config, project string) ([]*computeBeta.AttachedDisk, error) {
diskType, err := readDiskType(config, d, "local-ssd")
if err != nil {
return nil, fmt.Errorf("Error loading disk type 'local-ssd': %s", err)
Expand Down
6 changes: 3 additions & 3 deletions google/resource_compute_instance_from_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte
return fmt.Errorf("Error loading zone '%s': %s", z, err)
}

instance, err := expandComputeInstance(project, zone, d, config)
instance, err := expandComputeInstance(project, d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte
func adjustInstanceFromTemplateDisks(d *schema.ResourceData, config *Config, it *computeBeta.InstanceTemplate, zone *compute.Zone, project string) ([]*computeBeta.AttachedDisk, error) {
disks := []*computeBeta.AttachedDisk{}
if _, hasBootDisk := d.GetOk("boot_disk"); hasBootDisk {
bootDisk, err := expandBootDisk(d, config, zone, project)
bootDisk, err := expandBootDisk(d, config, project)
if err != nil {
return nil, err
}
Expand All @@ -195,7 +195,7 @@ func adjustInstanceFromTemplateDisks(d *schema.ResourceData, config *Config, it
}

if _, hasScratchDisk := d.GetOk("scratch_disk"); hasScratchDisk {
scratchDisks, err := expandScratchDisks(d, config, zone, project)
scratchDisks, err := expandScratchDisks(d, config, project)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4521753

Please sign in to comment.