diff --git a/generators/build/templates/Dockerfile b/generators/build/templates/Dockerfile index 1106958..c57b4f7 100644 --- a/generators/build/templates/Dockerfile +++ b/generators/build/templates/Dockerfile @@ -1,6 +1,6 @@ # Pull the base image with given version. -ARG BUILD_TERRAFORM_VERSION="0.11.7" -FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION} +ARG BUILD_TERRAFORM_VERSION="0.12.10" +FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION} ARG MODULE_NAME="terraform-azurerm-template" diff --git a/generators/build/templates/Gemfile b/generators/build/templates/Gemfile index a63f87a..68e7193 100644 --- a/generators/build/templates/Gemfile +++ b/generators/build/templates/Gemfile @@ -4,6 +4,6 @@ source 'https://rubygems.org/' group :test do git 'https://github.com/Azure/terramodtest.git' do - gem 'terramodtest', :tag => 'v0.2.0' + gem 'terramodtest', :tag => 'v0.3.0' end end diff --git a/generators/build/templates/Rakefile b/generators/build/templates/Rakefile index 2c5f316..beb4845 100644 --- a/generators/build/templates/Rakefile +++ b/generators/build/templates/Rakefile @@ -21,6 +21,10 @@ namespace :static do style_tf end task :lint do + success = system ("terraform init") + if not success + raise "ERROR: terraform init failed!\n".red + end lint_tf end task :format do diff --git a/generators/build/templates/env_setup.sh b/generators/build/templates/env_setup.sh index 86d4f27..dd11873 100755 --- a/generators/build/templates/env_setup.sh +++ b/generators/build/templates/env_setup.sh @@ -14,7 +14,7 @@ else fi # Version, OS and Arch for Terraform. -TERRAFORM_VERSION="0.11.7" +TERRAFORM_VERSION="0.12.10" # Version for Ruby SDK. RUBY_VERSION="2.3.3" RUBY_INSTALLED_VERSION_REGEX="^(ruby) ([0-9].[0-9].[0-9]p[0-9]+)" diff --git a/generators/module/templates/main.tf b/generators/module/templates/main.tf index 1dc4bf3..ec7ce6f 100644 --- a/generators/module/templates/main.tf +++ b/generators/module/templates/main.tf @@ -1,4 +1,4 @@ resource "random_shuffle" "rs" { - input = ["${var.raw_string_list}"] - result_count = "${var.permutation_count}" + input = var.raw_string_list + result_count = var.permutation_count } diff --git a/generators/module/templates/outputs.tf b/generators/module/templates/outputs.tf index a4a3646..56d0375 100644 --- a/generators/module/templates/outputs.tf +++ b/generators/module/templates/outputs.tf @@ -1,4 +1,4 @@ output "permutation_string_list" { description = "" - value = ["${random_shuffle.rs.result}"] + value = random_shuffle.rs.result } diff --git a/generators/module/templates/variables.tf b/generators/module/templates/variables.tf index a362207..6bc3cbf 100644 --- a/generators/module/templates/variables.tf +++ b/generators/module/templates/variables.tf @@ -1,4 +1,5 @@ variable "raw_string_list" { + type = list(string) description = "" default = ["us-west-1a", "us-west-1b", "us-west-1c"] } diff --git a/generators/test/templates/fixture/main.tf b/generators/test/templates/fixture/main.tf index 52fc267..6792e14 100644 --- a/generators/test/templates/fixture/main.tf +++ b/generators/test/templates/fixture/main.tf @@ -1,5 +1,5 @@ module "template" { source = "../../" - raw_string_list = ["${var.raw_string_list_test}"] - permutation_count = "${var.permutation_count_test}" + raw_string_list = var.raw_string_list_test + permutation_count = var.permutation_count_test } diff --git a/generators/test/templates/fixture/outputs.tf b/generators/test/templates/fixture/outputs.tf index 78c1c1d..8036325 100644 --- a/generators/test/templates/fixture/outputs.tf +++ b/generators/test/templates/fixture/outputs.tf @@ -1,4 +1,4 @@ output "permutation_string_list_test" { description = "" - value = ["${module.template.permutation_string_list}"] + value = module.template.permutation_string_list } diff --git a/generators/test/templates/fixture/terraform.tfvars b/generators/test/templates/fixture/terraform.tfvars index 4765db1..84fb438 100644 --- a/generators/test/templates/fixture/terraform.tfvars +++ b/generators/test/templates/fixture/terraform.tfvars @@ -1,2 +1,2 @@ -raw_string_list_test = ["us-west-1a", "us-west-1b", "us-west-1c", "us-west-1d"] +raw_string_list_test = ["us-west-1a", "us-west-1b", "us-west-1c", "us-west-1d"] permutation_count_test = 2 diff --git a/generators/test/templates/fixture/variables.tf b/generators/test/templates/fixture/variables.tf index 5e62152..d962bba 100644 --- a/generators/test/templates/fixture/variables.tf +++ b/generators/test/templates/fixture/variables.tf @@ -1,4 +1,5 @@ variable "raw_string_list_test" { + type = list(string) description = "" default = [] } diff --git a/generators/test/templates/template_test.go b/generators/test/templates/template_test.go index 01c977d..e9074f9 100644 --- a/generators/test/templates/template_test.go +++ b/generators/test/templates/template_test.go @@ -13,6 +13,12 @@ func TestTerraformTemplate(t *testing.T) { fixtureFolder := "./fixture" + // At the end of the test, clean up any resources that were created + defer test_structure.RunTestStage(t, "teardown", func() { + terraformOptions := test_structure.LoadTerraformOptions(t, fixtureFolder) + terraform.Destroy(t, terraformOptions) + }) + // Deploy the example test_structure.RunTestStage(t, "setup", func() { terraformOptions := configureTerraformOptions(t, fixtureFolder) @@ -29,19 +35,12 @@ func TestTerraformTemplate(t *testing.T) { terraformOptions := test_structure.LoadTerraformOptions(t, fixtureFolder) stringList := terraform.Output(t, terraformOptions, "permutation_string_list_test") - const LENGTH int = 22 fmt.Println(stringList) - if len(stringList) != LENGTH { + if len(stringList) <= 0 { t.Fatal("Wrong output") } }) - // At the end of the test, clean up any resources that were created - test_structure.RunTestStage(t, "teardown", func() { - terraformOptions := test_structure.LoadTerraformOptions(t, fixtureFolder) - terraform.Destroy(t, terraformOptions) - }) - } func configureTerraformOptions(t *testing.T, fixtureFolder string) *terraform.Options {