Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/google: instance template support for metadata_startup_script #8407

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion builtin/providers/google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ func resourceComputeInstanceTemplate() *schema.Resource {
},

"metadata": &schema.Schema{
Type: schema.TypeMap,
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: schema.TypeString,
ValidateFunc: validateInstanceMetadata,
},

"metadata_startup_script": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
Expand Down Expand Up @@ -694,6 +702,20 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error reading instance template: %s", err)
}

// Synch metadata
md := instanceTemplate.Properties.Metadata

_md := MetadataFormatSchema(d.Get("metadata").(map[string]interface{}), md)
delete(_md, "startup-script")

if script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists {
d.Set("metadata_startup_script", script)
}

if err = d.Set("metadata", _md); err != nil {
return fmt.Errorf("Error setting metadata: %s", err)
}

// Set the metadata fingerprint if there is one.
if instanceTemplate.Properties.Metadata != nil {
d.Set("metadata_fingerprint", instanceTemplate.Properties.Metadata.Fingerprint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ resource "google_compute_instance_template" "foobar" {
foo = "bar"
}

metadata_startup_script = "echo Hello"

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ resource "google_compute_instance_template" "foobar" {
foo = "bar"
}

metadata_startup_script = "echo hi > /test.txt"

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
Expand Down Expand Up @@ -133,6 +135,11 @@ The following arguments are supported:
* `metadata` - (Optional) Metadata key/value pairs to make available from
within instances created from this template.

* `metadata_startup_script` - (Optional) An alternative to using the
startup-script metadata key. This replaces the startup-script metadata key
on the created instance template and thus the two mechanisms are not allowed
to be used simultaneously.

* `network_interface` - (Required) Networks to attach to instances created from
this template. This can be specified multiple times for multiple networks.
Structure is documented below.
Expand Down