mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-02 00:31:04 +00:00
Don't set metadata_startup_script in some cases. (#1081)
This commit is contained in:
parent
1966a791a6
commit
f7851162a4
@ -1,6 +1,7 @@
|
|||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -151,6 +152,9 @@ func resourceInstanceMetadata(d *schema.ResourceData) (*computeBeta.Metadata, er
|
|||||||
m := &computeBeta.Metadata{}
|
m := &computeBeta.Metadata{}
|
||||||
mdMap := d.Get("metadata").(map[string]interface{})
|
mdMap := d.Get("metadata").(map[string]interface{})
|
||||||
if v, ok := d.GetOk("metadata_startup_script"); ok && v.(string) != "" {
|
if v, ok := d.GetOk("metadata_startup_script"); ok && v.(string) != "" {
|
||||||
|
if ss, ok := mdMap["startup-script"]; ok && ss != "" {
|
||||||
|
return nil, errors.New("Cannot provide both metadata_startup_script and metadata.startup-script.")
|
||||||
|
}
|
||||||
mdMap["startup-script"] = v
|
mdMap["startup-script"] = v
|
||||||
}
|
}
|
||||||
if len(mdMap) > 0 {
|
if len(mdMap) > 0 {
|
||||||
|
@ -778,13 +778,19 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
md := flattenMetadataBeta(instance.Metadata)
|
md := flattenMetadataBeta(instance.Metadata)
|
||||||
|
existingMetadata := d.Get("metadata").(map[string]interface{})
|
||||||
|
|
||||||
|
// If the existing config specifies "metadata.startup-script" instead of "metadata_startup_script",
|
||||||
|
// we shouldn't move the remote metadata.startup-script to metadata_startup_script. Otherwise,
|
||||||
|
// we should.
|
||||||
|
if ss, ok := existingMetadata["startup-script"]; !ok || ss == "" {
|
||||||
d.Set("metadata_startup_script", md["startup-script"])
|
d.Set("metadata_startup_script", md["startup-script"])
|
||||||
// Note that here we delete startup-script from our metadata list. This is to prevent storing the startup-script
|
// Note that here we delete startup-script from our metadata list. This is to prevent storing the startup-script
|
||||||
// as a value in the metadata since the config specifically tracks it under 'metadata_startup_script'
|
// as a value in the metadata since the config specifically tracks it under 'metadata_startup_script'
|
||||||
delete(md, "startup-script")
|
delete(md, "startup-script")
|
||||||
|
} else if _, ok := d.GetOk("metadata_startup_script"); ok {
|
||||||
existingMetadata := d.Get("metadata").(map[string]interface{})
|
delete(md, "startup-script")
|
||||||
|
}
|
||||||
|
|
||||||
// Delete any keys not explicitly set in our config file
|
// Delete any keys not explicitly set in our config file
|
||||||
for k := range md {
|
for k := range md {
|
||||||
@ -928,11 +934,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 script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists && script != "" {
|
||||||
if _, ok := n.(map[string]interface{})["startup-script"]; ok {
|
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")
|
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
|
n.(map[string]interface{})["startup-script"] = script
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,10 +978,12 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.SetPartial("metadata")
|
d.SetPartial("metadata")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataRetryWrapper(updateMD)
|
MetadataRetryWrapper(updateMD)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("tags") {
|
if d.HasChange("tags") {
|
||||||
|
@ -1478,7 +1478,9 @@ resource "google_compute_instance" "foobar" {
|
|||||||
|
|
||||||
create_timeout = 5
|
create_timeout = 5
|
||||||
|
|
||||||
metadata_startup_script = "echo Hello"
|
metadata {
|
||||||
|
startup-script = "echo Hello"
|
||||||
|
}
|
||||||
|
|
||||||
labels {
|
labels {
|
||||||
my_key = "my_value"
|
my_key = "my_value"
|
||||||
|
Loading…
Reference in New Issue
Block a user