Skip to content

Commit

Permalink
Move shieldedvmconfig -> shieldedinstanceconfig due to rename. (#3822) (
Browse files Browse the repository at this point in the history
#6943)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 5, 2020
1 parent d0fa2ac commit 46eeb18
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .changelog/3822.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fix shielded instance config, which had been failing to apply due to a field rename on the GCP side.
```
6 changes: 3 additions & 3 deletions google/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,21 @@ func resourceInstanceTags(d TerraformResourceData) *computeBeta.Tags {
return tags
}

func expandShieldedVmConfigs(d TerraformResourceData) *computeBeta.ShieldedVmConfig {
func expandShieldedVmConfigs(d TerraformResourceData) *computeBeta.ShieldedInstanceConfig {
if _, ok := d.GetOk("shielded_instance_config"); !ok {
return nil
}

prefix := "shielded_instance_config.0"
return &computeBeta.ShieldedVmConfig{
return &computeBeta.ShieldedInstanceConfig{
EnableSecureBoot: d.Get(prefix + ".enable_secure_boot").(bool),
EnableVtpm: d.Get(prefix + ".enable_vtpm").(bool),
EnableIntegrityMonitoring: d.Get(prefix + ".enable_integrity_monitoring").(bool),
ForceSendFields: []string{"EnableSecureBoot", "EnableVtpm", "EnableIntegrityMonitoring"},
}
}

func flattenShieldedVmConfig(shieldedVmConfig *computeBeta.ShieldedVmConfig) []map[string]bool {
func flattenShieldedVmConfig(shieldedVmConfig *computeBeta.ShieldedInstanceConfig) []map[string]bool {
if shieldedVmConfig == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func dataSourceGoogleComputeInstanceRead(d *schema.ResourceData, meta interface{
return err
}

err = d.Set("shielded_instance_config", flattenShieldedVmConfig(instance.ShieldedVmConfig))
err = d.Set("shielded_instance_config", flattenShieldedVmConfig(instance.ShieldedInstanceConfig))
if err != nil {
return err
}
Expand Down
42 changes: 21 additions & 21 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,25 +789,25 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *Confi

// Create the instance information
return &computeBeta.Instance{
CanIpForward: d.Get("can_ip_forward").(bool),
Description: d.Get("description").(string),
Disks: disks,
MachineType: machineTypeUrl,
Metadata: metadata,
Name: d.Get("name").(string),
NetworkInterfaces: networkInterfaces,
Tags: resourceInstanceTags(d),
Labels: expandLabels(d),
ServiceAccounts: expandServiceAccounts(d.Get("service_account").([]interface{})),
GuestAccelerators: accels,
MinCpuPlatform: d.Get("min_cpu_platform").(string),
Scheduling: scheduling,
DeletionProtection: d.Get("deletion_protection").(bool),
Hostname: d.Get("hostname").(string),
ForceSendFields: []string{"CanIpForward", "DeletionProtection"},
ShieldedVmConfig: expandShieldedVmConfigs(d),
DisplayDevice: expandDisplayDevice(d),
ResourcePolicies: convertStringArr(d.Get("resource_policies").([]interface{})),
CanIpForward: d.Get("can_ip_forward").(bool),
Description: d.Get("description").(string),
Disks: disks,
MachineType: machineTypeUrl,
Metadata: metadata,
Name: d.Get("name").(string),
NetworkInterfaces: networkInterfaces,
Tags: resourceInstanceTags(d),
Labels: expandLabels(d),
ServiceAccounts: expandServiceAccounts(d.Get("service_account").([]interface{})),
GuestAccelerators: accels,
MinCpuPlatform: d.Get("min_cpu_platform").(string),
Scheduling: scheduling,
DeletionProtection: d.Get("deletion_protection").(bool),
Hostname: d.Get("hostname").(string),
ForceSendFields: []string{"CanIpForward", "DeletionProtection"},
ShieldedInstanceConfig: expandShieldedVmConfigs(d),
DisplayDevice: expandDisplayDevice(d),
ResourcePolicies: convertStringArr(d.Get("resource_policies").([]interface{})),
}, nil
}

Expand Down Expand Up @@ -1087,7 +1087,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
d.Set("scratch_disk", scratchDisks)
d.Set("scheduling", flattenScheduling(instance.Scheduling))
d.Set("guest_accelerator", flattenGuestAccelerators(instance.GuestAccelerators))
d.Set("shielded_instance_config", flattenShieldedVmConfig(instance.ShieldedVmConfig))
d.Set("shielded_instance_config", flattenShieldedVmConfig(instance.ShieldedInstanceConfig))
d.Set("enable_display", flattenEnableDisplay(instance.DisplayDevice))
d.Set("cpu_platform", instance.CpuPlatform)
d.Set("min_cpu_platform", instance.MinCpuPlatform)
Expand Down Expand Up @@ -1617,7 +1617,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if d.HasChange("shielded_instance_config") {
shieldedVmConfig := expandShieldedVmConfigs(d)

op, err := config.clientComputeBeta.Instances.UpdateShieldedVmConfig(project, zone, instance.Name, shieldedVmConfig).Do()
op, err := config.clientComputeBeta.Instances.UpdateShieldedInstanceConfig(project, zone, instance.Name, shieldedVmConfig).Do()
if err != nil {
return fmt.Errorf("Error updating shielded vm config: %s", err)
}
Expand Down
28 changes: 14 additions & 14 deletions google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,19 +812,19 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
}

instanceProperties := &computeBeta.InstanceProperties{
CanIpForward: d.Get("can_ip_forward").(bool),
Description: d.Get("instance_description").(string),
GuestAccelerators: expandInstanceTemplateGuestAccelerators(d, config),
MachineType: d.Get("machine_type").(string),
MinCpuPlatform: d.Get("min_cpu_platform").(string),
Disks: disks,
Metadata: metadata,
NetworkInterfaces: networks,
Scheduling: scheduling,
ServiceAccounts: expandServiceAccounts(d.Get("service_account").([]interface{})),
Tags: resourceInstanceTags(d),
ShieldedVmConfig: expandShieldedVmConfigs(d),
DisplayDevice: expandDisplayDevice(d),
CanIpForward: d.Get("can_ip_forward").(bool),
Description: d.Get("instance_description").(string),
GuestAccelerators: expandInstanceTemplateGuestAccelerators(d, config),
MachineType: d.Get("machine_type").(string),
MinCpuPlatform: d.Get("min_cpu_platform").(string),
Disks: disks,
Metadata: metadata,
NetworkInterfaces: networks,
Scheduling: scheduling,
ServiceAccounts: expandServiceAccounts(d.Get("service_account").([]interface{})),
Tags: resourceInstanceTags(d),
ShieldedInstanceConfig: expandShieldedVmConfigs(d),
DisplayDevice: expandDisplayDevice(d),
}

if _, ok := d.GetOk("labels"); ok {
Expand Down Expand Up @@ -1187,7 +1187,7 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
}
}
if instanceTemplate.Properties.ShieldedVmConfig != nil {
if err = d.Set("shielded_instance_config", flattenShieldedVmConfig(instanceTemplate.Properties.ShieldedVmConfig)); err != nil {
if err = d.Set("shielded_instance_config", flattenShieldedVmConfig(instanceTemplate.Properties.ShieldedInstanceConfig)); err != nil {
return fmt.Errorf("Error setting shielded_instance_config: %s", err)
}
}
Expand Down

0 comments on commit 46eeb18

Please sign in to comment.