From 212ca1b08cd6ef9203298cc40c2bf38dc19b9486 Mon Sep 17 00:00:00 2001 From: Xin Gao Date: Tue, 30 Mar 2021 11:03:23 -0400 Subject: [PATCH] support metadata field in compute instance template (#860) * support metadata field in compute instance template Fixes #859 * use hcl --- docs/tfengine/schemas/resources.md | 6 ++++++ examples/tfengine/generated/team/project_apps/main.tf | 3 +++ examples/tfengine/modules/team.hcl | 3 +++ .../resources/compute_instance_templates/main.tf | 8 ++++++++ templates/tfengine/recipes/resources.hcl | 4 ++++ 5 files changed, 24 insertions(+) diff --git a/docs/tfengine/schemas/resources.md b/docs/tfengine/schemas/resources.md index 72aba4cf4..ef46bb83f 100755 --- a/docs/tfengine/schemas/resources.md +++ b/docs/tfengine/schemas/resources.md @@ -337,6 +337,12 @@ Labels to set on the instance template. Type: object +### compute_instance_templates.metadata + +Metadata to set on the instance template. + +Type: object + ### compute_instance_templates.name_prefix Name prefix of the instance template. diff --git a/examples/tfengine/generated/team/project_apps/main.tf b/examples/tfengine/generated/team/project_apps/main.tf index 895eb6b28..09032b576 100644 --- a/examples/tfengine/generated/team/project_apps/main.tf +++ b/examples/tfengine/generated/team/project_apps/main.tf @@ -144,6 +144,9 @@ module "instance_template" { env = "prod" type = "no-phi" } + metadata = { + enable-oslogin = "TRUE" + } depends_on = [ module.project ] diff --git a/examples/tfengine/modules/team.hcl b/examples/tfengine/modules/team.hcl index 6e71c6708..48e2c1862 100644 --- a/examples/tfengine/modules/team.hcl +++ b/examples/tfengine/modules/team.hcl @@ -195,6 +195,9 @@ template "project_apps" { labels = { type = "no-phi" } + metadata = { + enable-oslogin = "TRUE" + } tags = [ "service", ] diff --git a/templates/tfengine/components/resources/compute_instance_templates/main.tf b/templates/tfengine/components/resources/compute_instance_templates/main.tf index fd4d62500..b842dd42c 100644 --- a/templates/tfengine/components/resources/compute_instance_templates/main.tf +++ b/templates/tfengine/components/resources/compute_instance_templates/main.tf @@ -71,6 +71,14 @@ EOF {{end -}} } {{end -}} + + + {{if has . "metadata" -}} + metadata = { + {{hcl .metadata}} + } + {{end -}} + depends_on =[ module.project ] diff --git a/templates/tfengine/recipes/resources.hcl b/templates/tfengine/recipes/resources.hcl index ec011f2c0..67b411263 100644 --- a/templates/tfengine/recipes/resources.hcl +++ b/templates/tfengine/recipes/resources.hcl @@ -360,6 +360,10 @@ schema = { ".+" = { type = "string" } } } + metadata = { + description = "Metadata to set on the instance template." + type = "object" + } instances = { description = "[Module](https://github.com/terraform-google-modules/terraform-google-vm/tree/master/modules/compute_instance)" type = "array"