From 40fbdb0c28238f353d981e0faf6a7b014f7432fa Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 11:34:22 -0700 Subject: [PATCH 01/10] Deprecate and remove intermediate-variable --- README.md | 8 +- examples/intermediate-variable/README.md | 19 ----- examples/intermediate-variable/main.tf | 35 --------- examples/intermediate-variable/outputs.tf | 7 -- examples/intermediate-variable/vars.tf | 7 -- modules/intermediate-variable/README.md | 93 ----------------------- modules/intermediate-variable/outputs.tf | 7 -- modules/intermediate-variable/vars.tf | 9 --- test/intermediate_variable_test.go | 43 ----------- 9 files changed, 6 insertions(+), 222 deletions(-) delete mode 100644 examples/intermediate-variable/README.md delete mode 100644 examples/intermediate-variable/main.tf delete mode 100644 examples/intermediate-variable/outputs.tf delete mode 100644 examples/intermediate-variable/vars.tf delete mode 100644 modules/intermediate-variable/README.md delete mode 100644 modules/intermediate-variable/outputs.tf delete mode 100644 modules/intermediate-variable/vars.tf delete mode 100644 test/intermediate_variable_test.go diff --git a/README.md b/README.md index ab4023b..9144455 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ This repo provides a Gruntwork IaC Package and has the following folder structur The following modules are available: -* [intermediate-variable](/modules/intermediate-variable): A simple module that returns as output the exact variables - you pass to it as inputs. This gives you a way to store intermediate values that contain interpolations. * [join-path](/modules/join-path): This module can be used to join a list of given path parts into a single path that is platform/operating system aware. **(This module requires Python)** * [operating-system](/modules/operating-system): This module can be used to figure out what operating system is being @@ -30,6 +28,12 @@ The following modules are available: and runs them as an local-exec provisioner on a null_resource. PEX files are python executables that contain all the requirements necessary to run the script. **(This module requires Python)** +The following modules were deprecated and removed: + +* [intermediate-variable](/modules/intermediate-variable): This module has been superseded by [terraform local + values](https://www.terraform.io/docs/configuration/locals.html). To upgrade, switch usage of `intermediate-variable` + with `locals`. + Click on each module above to see its documentation. Head over to the [examples](/examples) folder for example usage. diff --git a/examples/intermediate-variable/README.md b/examples/intermediate-variable/README.md deleted file mode 100644 index 0673caa..0000000 --- a/examples/intermediate-variable/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Intermediate variable example - -This folder shows examples of how to use the [intermediate-variable module](/modules/intermediate-variable) -to store intermediate variables that contain interpolations. - - - - -## How do you run these examples? - -1. Install [Terraform](https://www.terraform.io/). -1. Open `vars.tf`, set the environment variables specified at the top of the file, and fill in any other variables that - don't have a default. -1. Run `terraform get`. -1. Run `terraform plan`. -1. If the plan looks good, run `terraform apply`. - - - diff --git a/examples/intermediate-variable/main.tf b/examples/intermediate-variable/main.tf deleted file mode 100644 index 03c870f..0000000 --- a/examples/intermediate-variable/main.tf +++ /dev/null @@ -1,35 +0,0 @@ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# SHOW HOW TO CREATE INTERMEDIATE "VARIABLES" THAT STORE MAP AND LIST VALUES -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# --------------------------------------------------------------------------------------------------------------------- -# STORE AN INTERMEDIATE MAP VARIABLE THAT CONTAINS INTERPOLATIONS -# --------------------------------------------------------------------------------------------------------------------- - -module "map_example" { - # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you - # to a specific version of the modules, such as the following example: - # source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/intermediate-variable?ref=v1.0.8" - source = "../../modules/intermediate-variable" - - map_value = { - foo = "${var.foo}" - bar = "${var.bar}" - } -} - -# --------------------------------------------------------------------------------------------------------------------- -# STORE AN INTERMEDIATE LIST VARIABLE THAT CONTAINS INTERPOLATIONS -# --------------------------------------------------------------------------------------------------------------------- - -module "list_example" { - # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you - # to a specific version of the modules, such as the following example: - # source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/intermediate-variable?ref=v1.0.8" - source = "../../modules/intermediate-variable" - - list_value = [ - "${var.foo}", - "${var.bar}", - ] -} diff --git a/examples/intermediate-variable/outputs.tf b/examples/intermediate-variable/outputs.tf deleted file mode 100644 index 594691d..0000000 --- a/examples/intermediate-variable/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "map_example" { - value = "${lookup(module.map_example.map_value, "foo")}" -} - -output "list_example" { - value = "${element(module.list_example.list_value, 0)}" -} diff --git a/examples/intermediate-variable/vars.tf b/examples/intermediate-variable/vars.tf deleted file mode 100644 index d67e7f5..0000000 --- a/examples/intermediate-variable/vars.tf +++ /dev/null @@ -1,7 +0,0 @@ -variable "foo" { - default = "foo" -} - -variable "bar" { - default = "bar" -} diff --git a/modules/intermediate-variable/README.md b/modules/intermediate-variable/README.md deleted file mode 100644 index 6472d7f..0000000 --- a/modules/intermediate-variable/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# Intermediate variable module - -A simple module that returns as output the exact variables you pass to it as inputs. This gives you a way to store -intermediate values that contain interpolations. - - - -## Quick start - -Check out the [intermediate-variable examples](/examples/intermediate-variable) for sample code. - - - - -## Motivation - -Occasionally, in Terraform, you need a way to store a derived or intermediate value. If that value is a static string, -you can do that with an input variable: - -```hcl -variable "hello" { - default = "Hello" -} -``` - -But if that value contains interpolation, you can no longer use an input variable, as the `default` value CANNOT -contain interpolations: - -```hcl -# This will NOT work! -variable "hello_world" { - default = "${var.hello}, World!" -} -``` - -If you run the code above, you'll get the error message "Variable 'hello_world': cannot contain interpolations." For -string values, you can work around this limitation using the `template_file` data source: - -```hcl -data "template_file" "hello_world" { - template = "${var.hello}, World!" -} -``` - -However, there is no way to use a `template_file` to store an intermediate variable that's a list or a map. For -example, imagine you are building a module with two input variables: - -```hcl -variable "foo" { - type = "list" -} -variable "bar" { - type = "list" -} -``` - -You want to concatenate these into a single list and use the list in several places throughout your module. With the -functionality built into Terraform, the only thing you can do is copy and paste the same call to `concat` multiple -times: - -```hcl -# In one place in your module: -x = ["${concat(var.foo, var.bar)}"] - -# In another place in your module: -y = ["${concat(var.foo, var.bar)}"] - -# And yet another place in your module: -z = ["${concat(var.foo, var.bar)}"] -``` - -This is obviously not DRY. With the intermediate-variable module, you can store this concatenated value in a list once, -and reuse the value all over the place: - -```hcl -# Store the value once in an intermediate variable -module "big_list" { - source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/intermediate-variable?ref=v1.0.8" - - list_value = ["${concat(var.foo, var.bar)}"] -} - -# And now you can reuse that variable throughout your code -x = ["${module.big_list.list_value}"] -y = ["${module.big_list.list_value}"] -z = ["${module.big_list.list_value}"] -``` - -Check out the [intermediate-variable examples](/examples/intermediate-variable) for working sample code. - - - - diff --git a/modules/intermediate-variable/outputs.tf b/modules/intermediate-variable/outputs.tf deleted file mode 100644 index e71c816..0000000 --- a/modules/intermediate-variable/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "map_value" { - value = "${var.map_value}" -} - -output "list_value" { - value = ["${var.list_value}"] -} diff --git a/modules/intermediate-variable/vars.tf b/modules/intermediate-variable/vars.tf deleted file mode 100644 index a9dffb1..0000000 --- a/modules/intermediate-variable/vars.tf +++ /dev/null @@ -1,9 +0,0 @@ -variable "map_value" { - type = "map" - default = {} -} - -variable "list_value" { - type = "list" - default = [] -} diff --git a/test/intermediate_variable_test.go b/test/intermediate_variable_test.go deleted file mode 100644 index 3e6e2d9..0000000 --- a/test/intermediate_variable_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package test - -import ( - "github.com/gruntwork-io/terratest/modules/random" - "github.com/gruntwork-io/terratest/modules/terraform" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestIntermediateVariable(t *testing.T) { - t.Parallel() - - terratestOptions := createBaseTerratestOptions(t, "../examples/intermediate-variable") - defer terraform.Destroy(t, terratestOptions) - - expectedFoo := random.UniqueId() - terratestOptions.Vars = map[string]interface{}{ - "foo": expectedFoo, - } - - terraform.InitAndApply(t, terratestOptions) - checkOutputs(t, expectedFoo, terratestOptions) -} - -func checkOutputs(t *testing.T, expectedFoo string, terratestOptions *terraform.Options) { - assertOutputEquals(t, "map_example", expectedFoo, terratestOptions) - assertOutputEquals(t, "list_example", expectedFoo, terratestOptions) -} - -func assertOutputEquals(t *testing.T, outputName string, expectedValue string, terratestOptions *terraform.Options) { - output := terraform.Output(t, terratestOptions, outputName) - assert.Equal(t, output, expectedValue) -} - -func createBaseTerratestOptions( - t *testing.T, - templatePath string, -) *terraform.Options { - terratestOptions := terraform.Options{ - TerraformDir: templatePath, - } - return &terratestOptions -} From 875ed66293948367693452eee74dd257ea837010 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 12:25:55 -0700 Subject: [PATCH 02/10] operating-system module is tf12 compatible --- examples/operating-system/main.tf | 4 + examples/operating-system/outputs.tf | 4 +- modules/operating-system/main.tf | 4 + modules/operating-system/outputs.tf | 4 +- test/Gopkg.lock | 477 ++++++++++++++++++++++++++- test/Gopkg.toml | 2 +- test/test_helpers.go | 28 ++ 7 files changed, 513 insertions(+), 10 deletions(-) create mode 100644 test/test_helpers.go diff --git a/examples/operating-system/main.tf b/examples/operating-system/main.tf index 81a8d58..54a19a3 100644 --- a/examples/operating-system/main.tf +++ b/examples/operating-system/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + module "os" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you # to a specific version of the modules, such as the following example: diff --git a/examples/operating-system/outputs.tf b/examples/operating-system/outputs.tf index 4bcb3fc..0627c1b 100644 --- a/examples/operating-system/outputs.tf +++ b/examples/operating-system/outputs.tf @@ -1,7 +1,7 @@ output "os_name" { - value = "${module.os.name}" + value = module.os.name } output "path_separator" { - value = "${module.os.path_separator}" + value = module.os.path_separator } diff --git a/modules/operating-system/main.tf b/modules/operating-system/main.tf index 3ac1681..0e0e34f 100644 --- a/modules/operating-system/main.tf +++ b/modules/operating-system/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + data "external" "os" { program = ["python", "-c", "import platform; print(\"{\\\"platform\\\": \\\"%s\\\"}\" % platform.system())"] } diff --git a/modules/operating-system/outputs.tf b/modules/operating-system/outputs.tf index b74081b..ea74685 100644 --- a/modules/operating-system/outputs.tf +++ b/modules/operating-system/outputs.tf @@ -1,7 +1,7 @@ output "name" { - value = "${data.external.os.result.platform}" + value = data.external.os.result.platform } output "path_separator" { - value = "${data.external.os.result.platform == "Windows" ? "\\" : "/"}" + value = data.external.os.result.platform == "Windows" ? "\\" : "/" } diff --git a/test/Gopkg.lock b/test/Gopkg.lock index 536eed9..2e7262f 100644 --- a/test/Gopkg.lock +++ b/test/Gopkg.lock @@ -1,6 +1,14 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + digest = "1:2ca532a6bc655663344004ba102436d29031018eab236247678db1d8978627bf" + name = "cloud.google.com/go" + packages = ["compute/metadata"] + pruneopts = "" + revision = "775730d6e48254a2430366162cf6298e5368833c" + version = "v0.39.0" + [[projects]] digest = "1:012fac888b7218cd93a1c11d0593cfc4832b5a99ffdad04eae6e7899dbfb4296" name = "github.com/aws/aws-sdk-go" @@ -16,6 +24,7 @@ "aws/credentials/endpointcreds", "aws/credentials/processcreds", "aws/credentials/stscreds", + "aws/crr", "aws/csm", "aws/defaults", "aws/ec2metadata", @@ -43,7 +52,9 @@ "service/acm", "service/autoscaling", "service/cloudwatchlogs", + "service/dynamodb", "service/ec2", + "service/ecs", "service/iam", "service/kms", "service/rds", @@ -52,6 +63,7 @@ "service/s3/s3manager", "service/sns", "service/sqs", + "service/ssm", "service/sts", ] pruneopts = "" @@ -78,6 +90,33 @@ revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" version = "v1.1.1" +[[projects]] + branch = "master" + digest = "1:d6c13a378213e3de60445e49084b8a0a9ce582776dfc77927775dbeb3ff72a35" + name = "github.com/docker/spdystream" + packages = [ + ".", + "spdy", + ] + pruneopts = "" + revision = "6480d4af844c189cf5dd913db24ddd339d3a4f85" + +[[projects]] + digest = "1:b13707423743d41665fd23f0c36b2f37bb49c30e94adb813319c44188a51ba22" + name = "github.com/ghodss/yaml" + packages = ["."] + pruneopts = "" + revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:26317724ed32bcf2ef15454613d2a8fe9d670b12f073cfd20db3bcec54e069ab" + name = "github.com/go-errors/errors" + packages = ["."] + pruneopts = "" + revision = "d98b870cc4e05f1545532a80e9909be8216095b6" + [[projects]] digest = "1:e692d16fdfbddb94e9e4886aaf6c08bdbae5cb4ac80651445de9181b371c6e46" name = "github.com/go-sql-driver/mysql" @@ -86,6 +125,55 @@ revision = "72cd26f257d44c1114970e19afddcd812016007e" version = "v1.4.1" +[[projects]] + digest = "1:fd53b471edb4c28c7d297f617f4da0d33402755f58d6301e7ca1197ef0a90937" + name = "github.com/gogo/protobuf" + packages = [ + "proto", + "sortkeys", + ] + pruneopts = "" + revision = "ba06b47c162d49f2af050fb4c75bcbc86a159d5c" + version = "v1.2.1" + +[[projects]] + branch = "master" + digest = "1:107b233e45174dbab5b1324201d092ea9448e58243ab9f039e4c0f332e121e3a" + name = "github.com/golang/glog" + packages = ["."] + pruneopts = "" + revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" + +[[projects]] + digest = "1:529d738b7976c3848cae5cf3a8036440166835e389c1f617af701eeb12a0518d" + name = "github.com/golang/protobuf" + packages = [ + "proto", + "ptypes", + "ptypes/any", + "ptypes/duration", + "ptypes/timestamp", + ] + pruneopts = "" + revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30" + version = "v1.3.1" + +[[projects]] + digest = "1:1e5b1e14524ed08301977b7b8e10c719ed853cbf3f24ecb66fae783a46f207a6" + name = "github.com/google/btree" + packages = ["."] + pruneopts = "" + revision = "4030bb1f1f0c35b30ca7009e9ebd06849dd45306" + version = "v1.0.0" + +[[projects]] + digest = "1:8d4a577a9643f713c25a32151c0f26af7228b4b97a219b5ddb7fd38d16f6e673" + name = "github.com/google/gofuzz" + packages = ["."] + pruneopts = "" + revision = "f140a6486e521aad38f5917de355cbf147cc0496" + version = "v1.0.0" + [[projects]] digest = "1:c1d7e883c50a26ea34019320d8ae40fad86c9e5d56e63a1ba2cb618cef43e986" name = "github.com/google/uuid" @@ -95,13 +183,46 @@ version = "0.2" [[projects]] - digest = "1:09b4e6af00a2f353af9d1e5df302a59a01188e510b6964b784b086d42116b6d3" + digest = "1:16b2837c8b3cf045fa2cdc82af0cf78b19582701394484ae76b2c3bc3c99ad73" + name = "github.com/googleapis/gnostic" + packages = [ + "OpenAPIv2", + "compiler", + "extensions", + ] + pruneopts = "" + revision = "7c663266750e7d82587642f65e60bc4083f1f84e" + version = "v0.2.0" + +[[projects]] + branch = "master" + digest = "1:326d7083af3723768cd8150db99b8ac730837b05ef290d5a042562905cc26210" + name = "github.com/gregjones/httpcache" + packages = [ + ".", + "diskcache", + ] + pruneopts = "" + revision = "3befbb6ad0cc97d4c25d851e9528915809e1a22f" + +[[projects]] + digest = "1:f032ebac9a824af56f183e82817a79792738f3faef09b4feced2252df7b253e7" + name = "github.com/gruntwork-io/gruntwork-cli" + packages = ["errors"] + pruneopts = "" + revision = "6a2163138f3d10377f313428e7e367b0a6c0c1c9" + version = "v0.4.2" + +[[projects]] + digest = "1:653bb665ede505dfaa7345261d8208c9ee8cc5bdbe7e258110ae9807eb34dace" name = "github.com/gruntwork-io/terratest" packages = [ "modules/aws", "modules/collections", "modules/customerrors", + "modules/environment", "modules/files", + "modules/k8s", "modules/logger", "modules/packer", "modules/random", @@ -112,8 +233,24 @@ "modules/test-structure", ] pruneopts = "" - revision = "da848892d7e2822604027814f5402743eb1c292c" - version = "v0.13.20" + revision = "892abb2c35878d0808101bbfe6559e931dc2d354" + version = "v0.16.0" + +[[projects]] + digest = "1:31bfd110d31505e9ffbc9478e31773bf05bf02adcaeb9b139af42684f9294c13" + name = "github.com/imdario/mergo" + packages = ["."] + pruneopts = "" + revision = "7c29201646fa3de8506f701213473dd407f19646" + version = "v0.3.7" + +[[projects]] + digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + pruneopts = "" + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" [[projects]] digest = "1:13fe471d0ed891e8544eddfeeb0471fd3c9f2015609a1c000aefdedf52a19d40" @@ -122,6 +259,54 @@ pruneopts = "" revision = "c2b33e84" +[[projects]] + digest = "1:12d3de2c11e54ea37d7f00daf85088ad5e61ec4e8a1f828d6c8b657976856be7" + name = "github.com/json-iterator/go" + packages = ["."] + pruneopts = "" + revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29" + version = "v1.1.6" + +[[projects]] + digest = "1:6dbb0eb72090871f2e58d1e37973fe3cb8c0f45f49459398d3fc740cb30e13bd" + name = "github.com/mitchellh/go-homedir" + packages = ["."] + pruneopts = "" + revision = "af06845cf3004701891bf4fdb884bfe4920b3727" + version = "v1.1.0" + +[[projects]] + digest = "1:0c0ff2a89c1bb0d01887e1dac043ad7efbf3ec77482ef058ac423d13497e16fd" + name = "github.com/modern-go/concurrent" + packages = ["."] + pruneopts = "" + revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" + version = "1.0.3" + +[[projects]] + digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855" + name = "github.com/modern-go/reflect2" + packages = ["."] + pruneopts = "" + revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" + version = "1.0.1" + +[[projects]] + branch = "master" + digest = "1:5f0faa008e8ff4221b55a1a5057c8b02cb2fd68da6a65c9e31c82b72cbc836d0" + name = "github.com/petar/GoLLRB" + packages = ["llrb"] + pruneopts = "" + revision = "33fb24c13b99c46c93183c291836c573ac382536" + +[[projects]] + digest = "1:4709c61d984ef9ba99b037b047546d8a576ae984fb49486e48d99658aa750cd5" + name = "github.com/peterbourgon/diskv" + packages = ["."] + pruneopts = "" + revision = "0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6" + version = "v3.0.0" + [[projects]] digest = "1:256484dbbcd271f9ecebc6795b2df8cad4c458dd0f5fd82a8c2fa0c29f233411" name = "github.com/pmezard/go-difflib" @@ -142,6 +327,22 @@ revision = "be78767b3e392ce45ea73444451022a6fc32ad0d" version = "v1.1.0" +[[projects]] + digest = "1:78715f4ed019d19795e67eed1dc63f525461d925616b1ed02b72582c01362440" + name = "github.com/spf13/cobra" + packages = ["."] + pruneopts = "" + revision = "67fc4837d267bc9bfd6e47f77783fcc3dffc68de" + version = "v0.0.4" + +[[projects]] + digest = "1:cbaf13cdbfef0e4734ed8a7504f57fe893d471d62a35b982bf6fb3f036449a66" + name = "github.com/spf13/pflag" + packages = ["."] + pruneopts = "" + revision = "298182f68c66c05229eb03ac171abe6e309ee79a" + version = "v1.0.3" + [[projects]] digest = "1:381bcbeb112a51493d9d998bbba207a529c73dbb49b3fd789e48c63fac1f192c" name = "github.com/stretchr/testify" @@ -153,6 +354,14 @@ revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" version = "v1.3.0" +[[projects]] + digest = "1:e85837cb04b78f61688c6eba93ea9d14f60d611e2aaf8319999b1a60d2dafbfa" + name = "github.com/urfave/cli" + packages = ["."] + pruneopts = "" + revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" + version = "v1.20.0" + [[projects]] branch = "master" digest = "1:59b49c47c11a48f1054529207f65907c014ecf5f9a7c0d9c0f1616dec7b062ed" @@ -166,6 +375,7 @@ "poly1305", "ssh", "ssh/agent", + "ssh/terminal", ] pruneopts = "" revision = "ff983b9c42bc9fbf91556e191cc8efb585c16908" @@ -174,22 +384,279 @@ branch = "master" digest = "1:1bee873b8f417fc58c796e2c8e76d015b4aeeecc5dac954a1b365d3e56f14b4c" name = "golang.org/x/net" - packages = ["context"] + packages = [ + "context", + "context/ctxhttp", + "http/httpguts", + "http2", + "http2/hpack", + "idna", + ] pruneopts = "" revision = "45ffb0cd1ba084b73e26dee67e667e1be5acce83" +[[projects]] + branch = "master" + digest = "1:fbb273eaa6359acf017f155480c5c68862f9c29728c798fbc620691a0495b2d6" + name = "golang.org/x/oauth2" + packages = [ + ".", + "google", + "internal", + "jws", + "jwt", + ] + pruneopts = "" + revision = "aaccbc9213b0974828f81aaac109d194880e3014" + +[[projects]] + branch = "master" + digest = "1:e292cb7347cb6bdfcb0fd7846f7bc61408d6a2d82354e4946fc527aff9b66921" + name = "golang.org/x/sys" + packages = [ + "unix", + "windows", + ] + pruneopts = "" + revision = "6a60838ec2595395fabc7b2e6c2ae9fb5a87722d" + +[[projects]] + digest = "1:740b51a55815493a8d0f2b1e0d0ae48fe48953bf7eaf3fcc4198823bf67768c0" + name = "golang.org/x/text" + packages = [ + "collate", + "collate/build", + "internal/colltab", + "internal/gen", + "internal/language", + "internal/language/compact", + "internal/tag", + "internal/triegen", + "internal/ucd", + "language", + "secure/bidirule", + "transform", + "unicode/bidi", + "unicode/cldr", + "unicode/norm", + "unicode/rangetable", + ] + pruneopts = "" + revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475" + version = "v0.3.2" + +[[projects]] + branch = "master" + digest = "1:9522af4be529c108010f95b05f1022cb872f2b9ff8b101080f554245673466e1" + name = "golang.org/x/time" + packages = ["rate"] + pruneopts = "" + revision = "9d24e82272b4f38b78bc8cff74fa936d31ccd8ef" + [[projects]] digest = "1:0a6cbf5be24f00105d33c9f6d2f40b8149e0316537a92be1b0d4c761b7ae39fb" name = "google.golang.org/appengine" - packages = ["cloudsql"] + packages = [ + ".", + "cloudsql", + "internal", + "internal/app_identity", + "internal/base", + "internal/datastore", + "internal/log", + "internal/modules", + "internal/remote_api", + "internal/urlfetch", + "urlfetch", + ] pruneopts = "" revision = "54a98f90d1c46b7731eb8fb305d2a321c30ef610" version = "v1.5.0" +[[projects]] + digest = "1:75fb3fcfc73a8c723efde7777b40e8e8ff9babf30d8c56160d01beffea8a95a6" + name = "gopkg.in/inf.v0" + packages = ["."] + pruneopts = "" + revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" + version = "v0.9.1" + +[[projects]] + digest = "1:cedccf16b71e86db87a24f8d4c70b0a855872eb967cb906a66b95de56aefbd0d" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "" + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" + +[[projects]] + branch = "release-1.12" + digest = "1:3e3e9df293bd6f9fd64effc9fa1f0edcd97e6c74145cd9ab05d35719004dc41f" + name = "k8s.io/api" + packages = [ + "admissionregistration/v1alpha1", + "admissionregistration/v1beta1", + "apps/v1", + "apps/v1beta1", + "apps/v1beta2", + "authentication/v1", + "authentication/v1beta1", + "authorization/v1", + "authorization/v1beta1", + "autoscaling/v1", + "autoscaling/v2beta1", + "autoscaling/v2beta2", + "batch/v1", + "batch/v1beta1", + "batch/v2alpha1", + "certificates/v1beta1", + "coordination/v1beta1", + "core/v1", + "events/v1beta1", + "extensions/v1beta1", + "networking/v1", + "policy/v1beta1", + "rbac/v1", + "rbac/v1alpha1", + "rbac/v1beta1", + "scheduling/v1alpha1", + "scheduling/v1beta1", + "settings/v1alpha1", + "storage/v1", + "storage/v1alpha1", + "storage/v1beta1", + ] + pruneopts = "" + revision = "6db15a15d2d3874a6c3ddb2140ac9f3bc7058428" + +[[projects]] + branch = "release-1.12" + digest = "1:9c7ee6fe7b8b621df5a7604e9a1f752b566ae451b2cf010c9c075e5e5ff81f56" + name = "k8s.io/apimachinery" + packages = [ + "pkg/api/errors", + "pkg/api/meta", + "pkg/api/resource", + "pkg/apis/meta/v1", + "pkg/apis/meta/v1/unstructured", + "pkg/apis/meta/v1beta1", + "pkg/conversion", + "pkg/conversion/queryparams", + "pkg/fields", + "pkg/labels", + "pkg/runtime", + "pkg/runtime/schema", + "pkg/runtime/serializer", + "pkg/runtime/serializer/json", + "pkg/runtime/serializer/protobuf", + "pkg/runtime/serializer/recognizer", + "pkg/runtime/serializer/streaming", + "pkg/runtime/serializer/versioning", + "pkg/selection", + "pkg/types", + "pkg/util/clock", + "pkg/util/errors", + "pkg/util/framer", + "pkg/util/httpstream", + "pkg/util/httpstream/spdy", + "pkg/util/intstr", + "pkg/util/json", + "pkg/util/naming", + "pkg/util/net", + "pkg/util/runtime", + "pkg/util/sets", + "pkg/util/validation", + "pkg/util/validation/field", + "pkg/util/yaml", + "pkg/version", + "pkg/watch", + "third_party/forked/golang/netutil", + "third_party/forked/golang/reflect", + ] + pruneopts = "" + revision = "01f179d85dbce0f2e0e4351a92394b38694b7cae" + +[[projects]] + branch = "release-9.0" + digest = "1:b1a32e8c431a032029c57bd211aa8b7e7de4fd7e142d4805be654da286f5efe4" + name = "k8s.io/client-go" + packages = [ + "discovery", + "kubernetes", + "kubernetes/scheme", + "kubernetes/typed/admissionregistration/v1alpha1", + "kubernetes/typed/admissionregistration/v1beta1", + "kubernetes/typed/apps/v1", + "kubernetes/typed/apps/v1beta1", + "kubernetes/typed/apps/v1beta2", + "kubernetes/typed/authentication/v1", + "kubernetes/typed/authentication/v1beta1", + "kubernetes/typed/authorization/v1", + "kubernetes/typed/authorization/v1beta1", + "kubernetes/typed/autoscaling/v1", + "kubernetes/typed/autoscaling/v2beta1", + "kubernetes/typed/autoscaling/v2beta2", + "kubernetes/typed/batch/v1", + "kubernetes/typed/batch/v1beta1", + "kubernetes/typed/batch/v2alpha1", + "kubernetes/typed/certificates/v1beta1", + "kubernetes/typed/coordination/v1beta1", + "kubernetes/typed/core/v1", + "kubernetes/typed/events/v1beta1", + "kubernetes/typed/extensions/v1beta1", + "kubernetes/typed/networking/v1", + "kubernetes/typed/policy/v1beta1", + "kubernetes/typed/rbac/v1", + "kubernetes/typed/rbac/v1alpha1", + "kubernetes/typed/rbac/v1beta1", + "kubernetes/typed/scheduling/v1alpha1", + "kubernetes/typed/scheduling/v1beta1", + "kubernetes/typed/settings/v1alpha1", + "kubernetes/typed/storage/v1", + "kubernetes/typed/storage/v1alpha1", + "kubernetes/typed/storage/v1beta1", + "pkg/apis/clientauthentication", + "pkg/apis/clientauthentication/v1alpha1", + "pkg/apis/clientauthentication/v1beta1", + "pkg/version", + "plugin/pkg/client/auth/exec", + "plugin/pkg/client/auth/gcp", + "rest", + "rest/watch", + "third_party/forked/golang/template", + "tools/auth", + "tools/clientcmd", + "tools/clientcmd/api", + "tools/clientcmd/api/latest", + "tools/clientcmd/api/v1", + "tools/metrics", + "tools/portforward", + "tools/reference", + "transport", + "transport/spdy", + "util/cert", + "util/connrotation", + "util/flowcontrol", + "util/homedir", + "util/integer", + "util/jsonpath", + ] + pruneopts = "" + revision = "b6aa6aafe32b0767f075245e5d391381c5449c8a" + +[[projects]] + digest = "1:30b201b810685671ff5b26a02f9d8a520cea5b451790ffe13f15c26170ff27fb" + name = "k8s.io/kubernetes" + packages = ["pkg/kubectl/generate"] + pruneopts = "" + revision = "66049e3b21efe110454d67df4fa62b08ea79a19b" + version = "v1.14.2" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 input-imports = [ + "github.com/gruntwork-io/terratest/modules/logger", "github.com/gruntwork-io/terratest/modules/random", "github.com/gruntwork-io/terratest/modules/terraform", "github.com/gruntwork-io/terratest/modules/test-structure", diff --git a/test/Gopkg.toml b/test/Gopkg.toml index 8cefd9d..bd93bc9 100644 --- a/test/Gopkg.toml +++ b/test/Gopkg.toml @@ -23,4 +23,4 @@ [[constraint]] name = "github.com/gruntwork-io/terratest" - version = "0.13.20" + version = "0.16.0" diff --git a/test/test_helpers.go b/test/test_helpers.go new file mode 100644 index 0000000..6c55e33 --- /dev/null +++ b/test/test_helpers.go @@ -0,0 +1,28 @@ +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func checkOutputs(t *testing.T, expectedFoo string, terratestOptions *terraform.Options) { + assertOutputEquals(t, "map_example", expectedFoo, terratestOptions) + assertOutputEquals(t, "list_example", expectedFoo, terratestOptions) +} + +func assertOutputEquals(t *testing.T, outputName string, expectedValue string, terratestOptions *terraform.Options) { + output := terraform.Output(t, terratestOptions, outputName) + assert.Equal(t, output, expectedValue) +} + +func createBaseTerratestOptions( + t *testing.T, + templatePath string, +) *terraform.Options { + terratestOptions := terraform.Options{ + TerraformDir: templatePath, + } + return &terratestOptions +} From 54f45ec355bb918163253adde7b551c762608235 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 12:31:28 -0700 Subject: [PATCH 03/10] Join path is tf12 compatible --- examples/join-path/main.tf | 4 ++++ examples/join-path/outputs.tf | 2 +- modules/join-path/main.tf | 4 ++++ modules/join-path/outputs.tf | 2 +- modules/join-path/vars.tf | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/join-path/main.tf b/examples/join-path/main.tf index 3a9ce62..9197728 100644 --- a/examples/join-path/main.tf +++ b/examples/join-path/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + module "path" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you # to a specific version of the modules, such as the following example: diff --git a/examples/join-path/outputs.tf b/examples/join-path/outputs.tf index 9d5bdd6..63f937a 100644 --- a/examples/join-path/outputs.tf +++ b/examples/join-path/outputs.tf @@ -1,3 +1,3 @@ output "path" { - value = "${module.path.path}" + value = module.path.path } diff --git a/modules/join-path/main.tf b/modules/join-path/main.tf index dfcaaf1..26f966a 100644 --- a/modules/join-path/main.tf +++ b/modules/join-path/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + module "os" { source = "../operating-system" } diff --git a/modules/join-path/outputs.tf b/modules/join-path/outputs.tf index d720669..b515d72 100644 --- a/modules/join-path/outputs.tf +++ b/modules/join-path/outputs.tf @@ -1,3 +1,3 @@ output "path" { - value = "${join(module.os.path_separator, var.path_parts)}" + value = join(module.os.path_separator, var.path_parts) } diff --git a/modules/join-path/vars.tf b/modules/join-path/vars.tf index 8ce4120..c855b19 100644 --- a/modules/join-path/vars.tf +++ b/modules/join-path/vars.tf @@ -5,7 +5,7 @@ variable "path_parts" { description = "A list of folder and file names to combine into a path, using the proper path separator for the current OS." - type = "list" + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux From 009db196c90bc5636c1326fd2b26dc2b5ddb9c4c Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 12:42:14 -0700 Subject: [PATCH 04/10] list-remove is tf12 compatible --- examples/list-remove/main.tf | 8 ++++++-- examples/list-remove/outputs.tf | 4 ++-- examples/list-remove/variables.tf | 4 ++-- modules/list-remove/main.tf | 12 ++++++++++-- modules/list-remove/outputs.tf | 2 +- modules/list-remove/variables.tf | 4 ++-- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/examples/list-remove/main.tf b/examples/list-remove/main.tf index 1f1f3af..e6fbecb 100644 --- a/examples/list-remove/main.tf +++ b/examples/list-remove/main.tf @@ -1,9 +1,13 @@ +terraform { + required_version = ">= 0.12" +} + module "list_remove" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you # to a specific version of the modules, such as the following example: # source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/list-remove?ref=v0.0.8" source = "../../modules/list-remove" - original_list = ["${var.input_list}"] - items_to_remove = ["${var.items_to_remove}"] + original_list = var.input_list + items_to_remove = var.items_to_remove } diff --git a/examples/list-remove/outputs.tf b/examples/list-remove/outputs.tf index 57122a4..79fc5fa 100644 --- a/examples/list-remove/outputs.tf +++ b/examples/list-remove/outputs.tf @@ -1,7 +1,7 @@ output "output_list" { - value = "${module.list_remove.output_list}" + value = module.list_remove.output_list } output "output_list_as_csv" { - value = "${join(",", module.list_remove.output_list)}" + value = join(",", module.list_remove.output_list) } diff --git a/examples/list-remove/variables.tf b/examples/list-remove/variables.tf index 1e4f7bc..d89589d 100644 --- a/examples/list-remove/variables.tf +++ b/examples/list-remove/variables.tf @@ -1,9 +1,9 @@ variable "input_list" { description = "The list of items from which you wish to remove items." - type = "list" + type = list(any) } variable "items_to_remove" { description = "The list of items you wish to remove from the input_list." - type = "list" + type = list(any) } diff --git a/modules/list-remove/main.tf b/modules/list-remove/main.tf index dd4d000..6acf67b 100644 --- a/modules/list-remove/main.tf +++ b/modules/list-remove/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + # Remove the items in items_to_remove from original_list. This works because: # a) concat will create a list in the order of the arguments it's given # b) distinct will discard duplicate items in the order they are found @@ -5,6 +9,10 @@ # second list of concat with all the elements from the first list removed. # Inspired by https://github.com/hashicorp/terraform/issues/16044#issuecomment-392269246 locals { - combined_list = "${distinct(concat(var.items_to_remove, var.original_list))}" - list_without_items = "${slice(local.combined_list, length(var.items_to_remove), length(local.combined_list))}" + combined_list = distinct(concat(var.items_to_remove, var.original_list)) + list_without_items = slice( + local.combined_list, + length(var.items_to_remove), + length(local.combined_list), + ) } diff --git a/modules/list-remove/outputs.tf b/modules/list-remove/outputs.tf index fb7ddd8..a83bf9d 100644 --- a/modules/list-remove/outputs.tf +++ b/modules/list-remove/outputs.tf @@ -1,3 +1,3 @@ output "output_list" { - value = "${local.list_without_items}" + value = local.list_without_items } diff --git a/modules/list-remove/variables.tf b/modules/list-remove/variables.tf index d5a8c9b..4688b81 100644 --- a/modules/list-remove/variables.tf +++ b/modules/list-remove/variables.tf @@ -5,10 +5,10 @@ variable "original_list" { description = "The list of items where you want to remove items from." - type = "list" + type = list(any) } variable "items_to_remove" { description = "The list of items that you want to remove from the original list." - type = "list" + type = list(any) } From 88c568bd7bb005736ba549a249132836e176a27e Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 12:53:48 -0700 Subject: [PATCH 05/10] require-executable is tf12 compatible --- examples/require-executable/main.tf | 12 ++++++++---- examples/require-executable/variables.tf | 2 +- modules/require-executable/main.tf | 8 ++++++-- modules/require-executable/outputs.tf | 2 +- modules/require-executable/variables.tf | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/require-executable/main.tf b/examples/require-executable/main.tf index 9c8b287..77d3a29 100644 --- a/examples/require-executable/main.tf +++ b/examples/require-executable/main.tf @@ -1,11 +1,15 @@ +terraform { + required_version = ">= 0.12" +} + module "require_executables" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you # to a specific version of the modules, such as the following example: # source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/require-executable?ref=v1.0.8" source = "../../modules/require-executable" - required_executables = ["${var.required_executables}"] - error_message = "${var.error_message}" + required_executables = var.required_executables + error_message = var.error_message } # Conditional checking example @@ -15,6 +19,6 @@ module "conditional_require_executables" { # source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/require-executable?ref=v1.0.8" source = "../../modules/require-executable" - required_executables = ["${var.validate_bad_executable ? "this-executable-should-not-exist" : ""}"] - error_message = "${var.bad_executable_error_message}" + required_executables = [var.validate_bad_executable ? "this-executable-should-not-exist" : ""] + error_message = var.bad_executable_error_message } diff --git a/examples/require-executable/variables.tf b/examples/require-executable/variables.tf index 83f7d4f..c58af03 100644 --- a/examples/require-executable/variables.tf +++ b/examples/require-executable/variables.tf @@ -5,7 +5,7 @@ variable "required_executables" { description = "A list of named executables that should exist on the OS PATH." - type = "list" + type = list(string) } variable "error_message" { diff --git a/modules/require-executable/main.tf b/modules/require-executable/main.tf index d1c1293..620118e 100644 --- a/modules/require-executable/main.tf +++ b/modules/require-executable/main.tf @@ -1,3 +1,7 @@ +terraform { + required_version = ">= 0.12" +} + data "external" "required_executable" { program = ["python", "${path.module}/require_executable.py"] @@ -5,7 +9,7 @@ data "external" "required_executable" { # to be a comma separated string. # See https://github.com/terraform-providers/terraform-provider-external/issues/2 query = { - required_executables = "${join(",", var.required_executables)}" - error_message = "${var.error_message}" + required_executables = join(",", var.required_executables) + error_message = var.error_message } } diff --git a/modules/require-executable/outputs.tf b/modules/require-executable/outputs.tf index 7d9c494..a870e85 100644 --- a/modules/require-executable/outputs.tf +++ b/modules/require-executable/outputs.tf @@ -1,4 +1,4 @@ output "executables" { description = "A map of the executables to the resolved path where they reside." - value = "${data.external.required_executable.result}" + value = data.external.required_executable.result } diff --git a/modules/require-executable/variables.tf b/modules/require-executable/variables.tf index a8e41e2..a749452 100644 --- a/modules/require-executable/variables.tf +++ b/modules/require-executable/variables.tf @@ -5,7 +5,7 @@ variable "required_executables" { description = "A list of named executables that should exist on the OS PATH." - type = "list" + type = list(string) } # --------------------------------------------------------------------------------------------------------------------- From d08484bdd6054f8d999fe36e018c007ed0f9ea85 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 13:15:37 -0700 Subject: [PATCH 06/10] Make pex code tf12 compatible --- examples/pex/main.tf | 19 ++++++++++++------- examples/pex/outputs.tf | 4 ++-- .../prepare-pex-environment/dependencies.tf | 10 +++++++--- modules/prepare-pex-environment/main.tf | 8 ++------ modules/prepare-pex-environment/outputs.tf | 4 ++-- modules/prepare-pex-environment/variables.tf | 9 +++------ modules/run-pex-as-data-source/main.tf | 13 ++++++++----- modules/run-pex-as-data-source/outputs.tf | 2 +- modules/run-pex-as-data-source/variables.tf | 11 ++++------- modules/run-pex-as-resource/main.tf | 14 +++++++++----- modules/run-pex-as-resource/variables.tf | 9 +++------ 11 files changed, 53 insertions(+), 50 deletions(-) diff --git a/examples/pex/main.tf b/examples/pex/main.tf index e8e49a8..9877fe8 100644 --- a/examples/pex/main.tf +++ b/examples/pex/main.tf @@ -4,6 +4,10 @@ # terraform in a portable manner that can work with multiple platforms and python versions. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +terraform { + required_version = ">= 0.12" +} + # Run the PEX binary as a local-exec provisioner on a null_resource. module "pex_resource" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you @@ -13,14 +17,14 @@ module "pex_resource" { # Path components to each of the PEX binary python2_pex_path_parts = [ - "${path.module}", + path.module, "sample-python-script", "bin", "sample_python_script_py27_env.pex", ] python3_pex_path_parts = [ - "${path.module}", + path.module, "sample-python-script", "bin", "sample_python_script_py3_env.pex", @@ -28,7 +32,7 @@ module "pex_resource" { # Path components to the folder that holds the python modules for sample_python_script pex_module_path_parts = [ - "${path.module}", + path.module, "sample-python-script", ] @@ -45,14 +49,14 @@ module "pex_data" { # Path components to each of the PEX binary python2_pex_path_parts = [ - "${path.module}", + path.module, "sample-python-script", "bin", "sample_python_script_py27_env.pex", ] python3_pex_path_parts = [ - "${path.module}", + path.module, "sample-python-script", "bin", "sample_python_script_py3_env.pex", @@ -60,7 +64,7 @@ module "pex_data" { # Path components to the folder that holds the python modules for sample_python_script pex_module_path_parts = [ - "${path.module}", + path.module, "sample-python-script", ] @@ -72,6 +76,7 @@ module "pex_data" { # Query parameter for the data source, that will be passed into the script in json format command_query = { - "echo" = "${var.echo_string}" + "echo" = var.echo_string } } + diff --git a/examples/pex/outputs.tf b/examples/pex/outputs.tf index 7f5e66d..5aa2a47 100644 --- a/examples/pex/outputs.tf +++ b/examples/pex/outputs.tf @@ -1,9 +1,9 @@ output "command_echo" { description = "For the pex data source, if successful, this will contain the echo string." - value = "${lookup(module.pex_data.result, "echo")}" + value = module.pex_data.result["echo"] } output "command_python_version" { description = "Read out the python version that was used to run the PEX" - value = "${lookup(module.pex_data.result, "python_version_info")}" + value = module.pex_data.result["python_version_info"] } diff --git a/modules/prepare-pex-environment/dependencies.tf b/modules/prepare-pex-environment/dependencies.tf index 28137a7..9e4b271 100644 --- a/modules/prepare-pex-environment/dependencies.tf +++ b/modules/prepare-pex-environment/dependencies.tf @@ -3,6 +3,10 @@ # Determine and calculate various intermediate variables that will help with setting up the PEX execution environment. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +terraform { + required_version = ">= 0.12" +} + # Figure out the installed and configured python version data "external" "python_version" { program = ["python", "-c", "import sys, json; print(json.dumps({\"major_version\": str(sys.version_info[0])}))"] @@ -17,15 +21,15 @@ module "os" { module "python2_pex_path" { source = "../join-path" - path_parts = ["${var.python2_pex_path_parts}"] + path_parts = var.python2_pex_path_parts } module "python3_pex_path" { source = "../join-path" - path_parts = ["${var.python3_pex_path_parts}"] + path_parts = var.python3_pex_path_parts } module "pex_module_path" { source = "../join-path" - path_parts = ["${var.pex_module_path_parts}"] + path_parts = var.pex_module_path_parts } diff --git a/modules/prepare-pex-environment/main.tf b/modules/prepare-pex-environment/main.tf index 35bdb55..93a139a 100644 --- a/modules/prepare-pex-environment/main.tf +++ b/modules/prepare-pex-environment/main.tf @@ -11,14 +11,10 @@ data "external" "determine_python_path" { "python", "${path.module}${module.os.path_separator}determine_python_path.py", "--module-path", - "${module.pex_module_path.path}", + module.pex_module_path.path, ] } locals { - pex = "${ - lookup(data.external.python_version.result, "major_version") == 2 - ? module.python2_pex_path.path - : module.python3_pex_path.path - }" + pex = data.external.python_version.result["major_version"] == 2 ? module.python2_pex_path.path : module.python3_pex_path.path } diff --git a/modules/prepare-pex-environment/outputs.tf b/modules/prepare-pex-environment/outputs.tf index 6077991..09e19c7 100644 --- a/modules/prepare-pex-environment/outputs.tf +++ b/modules/prepare-pex-environment/outputs.tf @@ -1,11 +1,11 @@ output "pex_path" { description = "Path to PEX file that should be run." - value = "${local.pex}" + value = local.pex } output "python_path" { description = "The python path that should be used for running PEX file. This should be set as the PYTHONPATH environment variable." - value = "${lookup(data.external.determine_python_path.result, "python_path")}" + value = data.external.determine_python_path.result["python_path"] } output "entrypoint_path" { diff --git a/modules/prepare-pex-environment/variables.tf b/modules/prepare-pex-environment/variables.tf index 738e9b1..367d41e 100644 --- a/modules/prepare-pex-environment/variables.tf +++ b/modules/prepare-pex-environment/variables.tf @@ -1,23 +1,20 @@ variable "python2_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 2 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "python3_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 3 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "pex_module_path_parts" { description = "Parts of the path (folders and file names) to the python package directory housing the pex file." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } diff --git a/modules/run-pex-as-data-source/main.tf b/modules/run-pex-as-data-source/main.tf index 8206c29..a3e39e2 100644 --- a/modules/run-pex-as-data-source/main.tf +++ b/modules/run-pex-as-data-source/main.tf @@ -5,11 +5,15 @@ # This utilizes the `prepare-pex-environment` module to ensure the execution of the binary is done in a portable manner. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +terraform { + required_version = ">= 0.12" +} + module "pex_env" { source = "../prepare-pex-environment" - python2_pex_path_parts = ["${var.python2_pex_path_parts}"] - python3_pex_path_parts = ["${var.python3_pex_path_parts}"] - pex_module_path_parts = ["${var.pex_module_path_parts}"] + python2_pex_path_parts = var.python2_pex_path_parts + python3_pex_path_parts = var.python3_pex_path_parts + pex_module_path_parts = var.pex_module_path_parts } data "external" "pex" { @@ -40,8 +44,7 @@ data "external" "pex" { env=env, ) PROGRAM - , ] - query = "${var.command_query}" + query = var.command_query } diff --git a/modules/run-pex-as-data-source/outputs.tf b/modules/run-pex-as-data-source/outputs.tf index 79dcd3b..ee1eda7 100644 --- a/modules/run-pex-as-data-source/outputs.tf +++ b/modules/run-pex-as-data-source/outputs.tf @@ -1,4 +1,4 @@ output "result" { description = "Data source result of executing the PEX binary." - value = "${data.external.pex.result}" + value = data.external.pex.result } diff --git a/modules/run-pex-as-data-source/variables.tf b/modules/run-pex-as-data-source/variables.tf index 13c73ad..2829425 100644 --- a/modules/run-pex-as-data-source/variables.tf +++ b/modules/run-pex-as-data-source/variables.tf @@ -1,23 +1,20 @@ variable "python2_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 2 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "python3_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 3 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "pex_module_path_parts" { description = "Parts of the path (folders and file names) to the python package directory housing the pex file." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } @@ -33,6 +30,6 @@ variable "command_args" { variable "command_query" { description = "The query for the command run as a data source." - type = "map" + type = map(string) default = {} } diff --git a/modules/run-pex-as-resource/main.tf b/modules/run-pex-as-resource/main.tf index 3a01146..37fcf42 100644 --- a/modules/run-pex-as-resource/main.tf +++ b/modules/run-pex-as-resource/main.tf @@ -4,19 +4,23 @@ # This utilizes the `prepare-pex-environment` module to ensure the execution of the binary is done in a portable manner. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +terraform { + required_version = ">= 0.12" +} + module "pex_env" { source = "../prepare-pex-environment" - python2_pex_path_parts = ["${var.python2_pex_path_parts}"] - python3_pex_path_parts = ["${var.python3_pex_path_parts}"] - pex_module_path_parts = ["${var.pex_module_path_parts}"] + python2_pex_path_parts = var.python2_pex_path_parts + python3_pex_path_parts = var.python3_pex_path_parts + pex_module_path_parts = var.pex_module_path_parts } resource "null_resource" "run_pex" { provisioner "local-exec" { command = "python ${module.pex_env.pex_path} ${module.pex_env.entrypoint_path} ${var.script_main_function} ${var.command_args}" - environment { - PYTHONPATH = "${module.pex_env.python_path}" + environment = { + PYTHONPATH = module.pex_env.python_path } } } diff --git a/modules/run-pex-as-resource/variables.tf b/modules/run-pex-as-resource/variables.tf index efa7042..5c268e5 100644 --- a/modules/run-pex-as-resource/variables.tf +++ b/modules/run-pex-as-resource/variables.tf @@ -1,23 +1,20 @@ variable "python2_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 2 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "python3_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 3 as a list of strings." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "pex_module_path_parts" { description = "Parts of the path (folders and file names) to the python package directory housing the pex file." - type = "list" - + type = list(string) # Example: # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } From 4d8850baf4332964fb33cffe35d655a8eb7138a7 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 13:16:10 -0700 Subject: [PATCH 07/10] Use tf12 in circleci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7e69782..a9a29f5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ jobs: curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version v0.0.21 gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.13.3" gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "v0.13.20" - configure-environment-for-gruntwork-module --circle-ci-2 --use-go-dep --go-src-path test --terragrunt-version NONE + configure-environment-for-gruntwork-module --circle-ci-2 --use-go-dep --go-src-path test --terragrunt-version NONE --terraform-version 0.12.0 - run: name: run tests (with python2) From 4130524caf03d5993a938cdcf524d9f510abad59 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 29 May 2019 13:29:36 -0700 Subject: [PATCH 08/10] Fix some badges --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9144455..c6c263e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_kubergrunt) +[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_package_terraform_utilities) +[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gruntwork-io/package-terraform-utilities.svg?label=latest)](https://github.com/gruntwork-io/package-terraform-utilities/releases/latest) +![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.12.0-blue.svg) # Terraform Utility Modules From 1cfcc1edc579b9d80a6dbdbb322e3edc0a211cbc Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 5 Jun 2019 17:39:55 -0700 Subject: [PATCH 09/10] Set concrete types for the inputs --- examples/pex/variables.tf | 1 + examples/require-executable/variables.tf | 3 +++ modules/require-executable/variables.tf | 1 + modules/run-pex-as-data-source/variables.tf | 2 ++ modules/run-pex-as-resource/variables.tf | 2 ++ 5 files changed, 9 insertions(+) diff --git a/examples/pex/variables.tf b/examples/pex/variables.tf index ef76e26..a00e7bd 100644 --- a/examples/pex/variables.tf +++ b/examples/pex/variables.tf @@ -1,4 +1,5 @@ variable "echo_string" { description = "This string will be echo'd back from the pex data source." + type = string default = "Hello world!" } diff --git a/examples/require-executable/variables.tf b/examples/require-executable/variables.tf index c58af03..ab94b33 100644 --- a/examples/require-executable/variables.tf +++ b/examples/require-executable/variables.tf @@ -10,14 +10,17 @@ variable "required_executables" { variable "error_message" { description = "Error message to show if the required executable is not found. This is printed for each executable that was not found. The module will make the following substitutions in the string: `__EXECUTABLE_NAME__` will become the name of the executable that was not found." + type = string } variable "validate_bad_executable" { description = "Whether or not to validate the existence of a bad executable." + type = bool default = false } variable "bad_executable_error_message" { description = "Error message to show for bad_executable check." + type = string default = "" } diff --git a/modules/require-executable/variables.tf b/modules/require-executable/variables.tf index a749452..a2e1d73 100644 --- a/modules/require-executable/variables.tf +++ b/modules/require-executable/variables.tf @@ -15,5 +15,6 @@ variable "required_executables" { variable "error_message" { description = "Error message to show if the required executable is not found. This is printed for each executable that was not found. The module will make the following substitutions in the string: `__EXECUTABLE_NAME__` will become the name of the executable that was not found." + type = string default = "Not found: __EXECUTABLE_NAME__" } diff --git a/modules/run-pex-as-data-source/variables.tf b/modules/run-pex-as-data-source/variables.tf index 2829425..d1ab01f 100644 --- a/modules/run-pex-as-data-source/variables.tf +++ b/modules/run-pex-as-data-source/variables.tf @@ -21,10 +21,12 @@ variable "pex_module_path_parts" { variable "script_main_function" { description = "Main function of the script, encoded as SCRIPT_MODULE:FUNCTION. So for example, if the main function of the script is in a file named `entrypoint.py` which houses the function `main`, then this should be `entrypoint:main`." + type = string } variable "command_args" { description = "The arguments to pass to the command as a string" + type = string default = "" } diff --git a/modules/run-pex-as-resource/variables.tf b/modules/run-pex-as-resource/variables.tf index 5c268e5..8e3447b 100644 --- a/modules/run-pex-as-resource/variables.tf +++ b/modules/run-pex-as-resource/variables.tf @@ -21,9 +21,11 @@ variable "pex_module_path_parts" { variable "script_main_function" { description = "Main function of the script, encoded as SCRIPT_MODULE:FUNCTION. So for example, if the main function of the script is in a file named `entrypoint.py` which houses the function `main`, then this should be `entrypoint:main`." + type = string } variable "command_args" { description = "The arguments to pass to the command as a string" + type = string default = "" } From d15e1c8ea032d92ea9813ab2b7b4adad7e313363 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Wed, 5 Jun 2019 17:46:38 -0700 Subject: [PATCH 10/10] Add better comments for all the variables --- modules/join-path/vars.tf | 2 +- modules/prepare-pex-environment/variables.tf | 6 +++--- modules/run-pex-as-data-source/variables.tf | 10 ++++++---- modules/run-pex-as-resource/variables.tf | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/join-path/vars.tf b/modules/join-path/vars.tf index c855b19..52c54cb 100644 --- a/modules/join-path/vars.tf +++ b/modules/join-path/vars.tf @@ -8,5 +8,5 @@ variable "path_parts" { type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } diff --git a/modules/prepare-pex-environment/variables.tf b/modules/prepare-pex-environment/variables.tf index 367d41e..67413aa 100644 --- a/modules/prepare-pex-environment/variables.tf +++ b/modules/prepare-pex-environment/variables.tf @@ -2,19 +2,19 @@ variable "python2_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 2 as a list of strings." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # python2_pex_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "python3_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 3 as a list of strings." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # python3_pex_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "pex_module_path_parts" { description = "Parts of the path (folders and file names) to the python package directory housing the pex file." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # pex_module_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } diff --git a/modules/run-pex-as-data-source/variables.tf b/modules/run-pex-as-data-source/variables.tf index d1ab01f..11e140f 100644 --- a/modules/run-pex-as-data-source/variables.tf +++ b/modules/run-pex-as-data-source/variables.tf @@ -2,21 +2,21 @@ variable "python2_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 2 as a list of strings." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # python2_pex_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "python3_pex_path_parts" { description = "Parts of the path (folders and files names) to the PEX executable for python 3 as a list of strings." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # python3_pex_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "pex_module_path_parts" { description = "Parts of the path (folders and file names) to the python package directory housing the pex file." type = list(string) # Example: - # default = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux + # pex_module_path_parts = ["foo", "bar", "baz.txt"] => outputs "foo/bar/baz.txt" on Linux } variable "script_main_function" { @@ -27,7 +27,9 @@ variable "script_main_function" { variable "command_args" { description = "The arguments to pass to the command as a string" type = string - default = "" + + # We don't use null here because this is interpolated into the python script. + default = "" } variable "command_query" { diff --git a/modules/run-pex-as-resource/variables.tf b/modules/run-pex-as-resource/variables.tf index 8e3447b..c85df43 100644 --- a/modules/run-pex-as-resource/variables.tf +++ b/modules/run-pex-as-resource/variables.tf @@ -27,5 +27,7 @@ variable "script_main_function" { variable "command_args" { description = "The arguments to pass to the command as a string" type = string - default = "" + + # We don't use null here because this is interpolated into the python script. + default = "" }