mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-03 01:01:06 +00:00
Make google_compute_instance metadata authoritative. (#2208)
This commit is contained in:
parent
902675c324
commit
8c42015451
@ -789,17 +789,11 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
||||
delete(md, "startup-script")
|
||||
}
|
||||
|
||||
// Delete any keys not explicitly set in our config file
|
||||
for k := range md {
|
||||
if _, ok := existingMetadata[k]; !ok {
|
||||
delete(md, k)
|
||||
}
|
||||
}
|
||||
|
||||
if err = d.Set("metadata", md); err != nil {
|
||||
return fmt.Errorf("Error setting metadata: %s", err)
|
||||
}
|
||||
|
||||
d.Set("metadata_fingerprint", instance.Metadata.Fingerprint)
|
||||
d.Set("can_ip_forward", instance.CanIpForward)
|
||||
d.Set("machine_type", GetResourceNameFromSelfLink(instance.MachineType))
|
||||
|
||||
@ -827,11 +821,6 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
||||
"host": sshIP,
|
||||
})
|
||||
|
||||
// Set the metadata fingerprint if there is one.
|
||||
if instance.Metadata != nil {
|
||||
d.Set("metadata_fingerprint", instance.Metadata.Fingerprint)
|
||||
}
|
||||
|
||||
// Set the tags fingerprint if there is one.
|
||||
if instance.Tags != nil {
|
||||
d.Set("tags_fingerprint", instance.Tags.Fingerprint)
|
||||
@ -966,43 +955,18 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
||||
// Enable partial mode for the resource since it is possible
|
||||
d.Partial(true)
|
||||
|
||||
// If the Metadata has changed, then update that.
|
||||
if d.HasChange("metadata") {
|
||||
o, n := d.GetChange("metadata")
|
||||
if script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists && script != "" {
|
||||
if _, ok := n.(map[string]interface{})["startup-script"]; ok {
|
||||
return fmt.Errorf("Only one of metadata.startup-script and metadata_startup_script may be defined")
|
||||
}
|
||||
|
||||
if err = d.Set("metadata", n); err != nil {
|
||||
return err
|
||||
}
|
||||
n.(map[string]interface{})["startup-script"] = script
|
||||
}
|
||||
|
||||
updateMD := func() error {
|
||||
// Reload the instance in the case of a fingerprint mismatch
|
||||
instance, err = getInstance(config, d)
|
||||
metadata, err := resourceInstanceMetadata(d)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error parsing metadata: %s", err)
|
||||
}
|
||||
|
||||
metadataV1 := &compute.Metadata{}
|
||||
if err := Convert(metadata, metadataV1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
md := instance.Metadata
|
||||
|
||||
BetaMetadataUpdate(o.(map[string]interface{}), n.(map[string]interface{}), md)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating metadata: %s", err)
|
||||
}
|
||||
|
||||
mdV1 := &compute.Metadata{}
|
||||
err = Convert(md, mdV1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
op, err := config.clientCompute.Instances.SetMetadata(
|
||||
project, zone, d.Id(), mdV1).Do()
|
||||
op, err := config.clientCompute.Instances.SetMetadata(project, zone, d.Id(), metadataV1).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating metadata: %s", err)
|
||||
}
|
||||
@ -1013,12 +977,6 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
||||
}
|
||||
|
||||
d.SetPartial("metadata")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
MetadataRetryWrapper(updateMD)
|
||||
|
||||
}
|
||||
|
||||
if d.HasChange("tags") {
|
||||
|
@ -100,7 +100,8 @@ The following arguments are supported:
|
||||
* `labels` - (Optional) A set of key/value label pairs to assign to the instance.
|
||||
|
||||
* `metadata` - (Optional) Metadata key/value pairs to make available from
|
||||
within the instance.
|
||||
within the instance. Ssh keys attached in the Cloud Console will be removed.
|
||||
Add them to your config in order to keep them attached to your instance.
|
||||
|
||||
* `metadata_startup_script` - (Optional) An alternative to using the
|
||||
startup-script metadata key, except this one forces the instance to be
|
||||
|
Loading…
Reference in New Issue
Block a user