From cdfbca2bc6cf172f467a60b1d5cd290a69cbd1be Mon Sep 17 00:00:00 2001 From: Cedric Girard Date: Tue, 12 May 2020 12:17:38 +0200 Subject: [PATCH] lookup and validation --- project2/base.tf | 20 +++++++++++++++++++- project2/terraform.tfstate | 19 +++++++++++++++++-- project2/terraform.tfstate.backup | 19 +++++++++++++++++-- project2/terraform.tfvars | 2 +- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/project2/base.tf b/project2/base.tf index d0248f5..673f688 100644 --- a/project2/base.tf +++ b/project2/base.tf @@ -1,4 +1,15 @@ -variable "a" {} +terraform { + experiments = [ + variable_validation + ] +} + +variable "a" { + validation { + condition = can(regex("foo|aze|qsd", var.a)) + error_message = "Valid values are foo, aze, qsd." + } +} variable "b" { default = "test" } @@ -25,5 +36,12 @@ output "ov3" { value = "${var.c[2]}" } output "ov4" { + value = "${var.d}" +} +output "ov4_foo" { value = "${var.d.foo}" } + +output "ov4_lookup" { + value = "${lookup(var.d, var.a)}" +} diff --git a/project2/terraform.tfstate b/project2/terraform.tfstate index 1901a28..d74676b 100644 --- a/project2/terraform.tfstate +++ b/project2/terraform.tfstate @@ -1,11 +1,11 @@ { "version": 4, "terraform_version": "0.12.24", - "serial": 9, + "serial": 11, "lineage": "53b98038-185e-af43-6c6c-521354912695", "outputs": { "ov1": { - "value": "foobar", + "value": "foo", "type": "string" }, "ov2": { @@ -17,6 +17,21 @@ "type": "string" }, "ov4": { + "value": { + "aze": "rty", + "foo": "bar", + "qsd": "fgh" + }, + "type": [ + "map", + "string" + ] + }, + "ov4_foo": { + "value": "bar", + "type": "string" + }, + "ov4_lookup": { "value": "bar", "type": "string" } diff --git a/project2/terraform.tfstate.backup b/project2/terraform.tfstate.backup index cb4e782..88e5ed5 100644 --- a/project2/terraform.tfstate.backup +++ b/project2/terraform.tfstate.backup @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "0.12.24", - "serial": 8, + "serial": 10, "lineage": "53b98038-185e-af43-6c6c-521354912695", "outputs": { "ov1": { @@ -13,7 +13,22 @@ "type": "string" }, "ov3": { - "value": "fgh", + "value": "baz", + "type": "string" + }, + "ov4": { + "value": { + "aze": "rty", + "foo": "bar", + "qsd": "fgh" + }, + "type": [ + "map", + "string" + ] + }, + "ov4_foo": { + "value": "bar", "type": "string" } }, diff --git a/project2/terraform.tfvars b/project2/terraform.tfvars index e03a7a9..4abf0f3 100644 --- a/project2/terraform.tfvars +++ b/project2/terraform.tfvars @@ -1 +1 @@ -a = "foobar" +a = "foo"