Merge pull request #3501 from lwander/f-gce-metadata-fix

Fixed GCE metadata acceptance test bug
This commit is contained in:
Paul Hinze 2015-10-14 12:48:53 -05:00
commit 2b89801c35
2 changed files with 18 additions and 2 deletions

View File

@ -515,10 +515,17 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
// Synch metadata // Synch metadata
md := instance.Metadata md := instance.Metadata
if err = d.Set("metadata", MetadataFormatSchema(md)); err != nil { _md := MetadataFormatSchema(md)
if script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists {
d.Set("metadata_startup_script", script)
delete(_md, "startup-script")
}
if err = d.Set("metadata", _md); err != nil {
return fmt.Errorf("Error setting metadata: %s", err) return fmt.Errorf("Error setting metadata: %s", err)
} }
d.Set("can_ip_forward", instance.CanIpForward) d.Set("can_ip_forward", instance.CanIpForward)
// Set the service accounts // Set the service accounts
@ -635,6 +642,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
} }
d.Set("self_link", instance.SelfLink) d.Set("self_link", instance.SelfLink)
d.SetId(instance.Name)
return nil return nil
} }
@ -655,6 +663,14 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
// If the Metadata has changed, then update that. // If the Metadata has changed, then update that.
if d.HasChange("metadata") { if d.HasChange("metadata") {
o, n := d.GetChange("metadata") o, n := d.GetChange("metadata")
if script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists {
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")
}
n.(map[string]interface{})["startup-script"] = script
}
updateMD := func() error { updateMD := func() error {
// Reload the instance in the case of a fingerprint mismatch // Reload the instance in the case of a fingerprint mismatch

View File

@ -32,7 +32,7 @@ func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
}) })
} }
func TestAccComputeInstance_basic(t *testing.T) { func TestAccComputeInstance_basic1(t *testing.T) {
var instance compute.Instance var instance compute.Instance
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{