From 8580668ac5ca5bc0db812e98cf816ca35de06106 Mon Sep 17 00:00:00 2001 From: Ihor Pukha Date: Fri, 19 Jul 2019 20:50:18 +0300 Subject: [PATCH] Add support for Terraform 0.12 #13 --- CHANGELOG.md | 5 + Gemfile | 2 +- Gemfile.lock | 152 ++++++++++-------- Makefile | 16 +- README.md | 7 + examples/compute_instance/simple/main.tf | 27 ++-- examples/compute_instance/simple/outputs.tf | 5 +- examples/compute_instance/simple/variables.tf | 8 +- examples/compute_instance/simple/versions.tf | 19 +++ .../additional_disks/main.tf | 13 +- .../additional_disks/outputs.tf | 5 +- .../additional_disks/variables.tf | 9 +- .../additional_disks/versions.tf | 19 +++ examples/instance_template/simple/main.tf | 17 +- examples/instance_template/simple/outputs.tf | 5 +- .../instance_template/simple/variables.tf | 13 +- examples/instance_template/simple/versions.tf | 19 +++ examples/mig/autoscaler/main.tf | 33 ++-- examples/mig/autoscaler/outputs.tf | 5 +- examples/mig/autoscaler/variables.tf | 13 +- examples/mig/autoscaler/versions.tf | 19 +++ examples/mig/full/main.tf | 105 ++++++------ examples/mig/full/outputs.tf | 5 +- examples/mig/full/variables.tf | 62 +++++-- examples/mig/full/versions.tf | 19 +++ examples/mig/simple/main.tf | 27 ++-- examples/mig/simple/outputs.tf | 3 +- examples/mig/simple/variables.tf | 9 +- examples/mig/simple/versions.tf | 19 +++ examples/umig/full/main.tf | 67 ++++---- examples/umig/full/outputs.tf | 5 +- examples/umig/full/variables.tf | 33 ++-- examples/umig/full/versions.tf | 19 +++ examples/umig/named_ports/main.tf | 29 ++-- examples/umig/named_ports/outputs.tf | 7 +- examples/umig/named_ports/variables.tf | 18 ++- examples/umig/named_ports/versions.tf | 19 +++ examples/umig/simple/main.tf | 27 ++-- examples/umig/simple/outputs.tf | 7 +- examples/umig/simple/variables.tf | 9 +- examples/umig/simple/versions.tf | 19 +++ examples/umig/static_ips/main.tf | 29 ++-- examples/umig/static_ips/outputs.tf | 7 +- examples/umig/static_ips/variables.tf | 10 +- examples/umig/static_ips/versions.tf | 19 +++ modules/compute_instance/main.tf | 26 +-- modules/compute_instance/outputs.tf | 5 +- modules/compute_instance/variables.tf | 3 +- modules/compute_instance/versions.tf | 19 +++ modules/instance_template/main.tf | 77 ++++++--- modules/instance_template/outputs.tf | 5 +- modules/instance_template/variables.tf | 21 ++- modules/instance_template/versions.tf | 19 +++ modules/mig/main.tf | 128 ++++++++++----- modules/mig/outputs.tf | 5 +- modules/mig/variables.tf | 37 +++-- modules/mig/versions.tf | 19 +++ modules/umig/main.tf | 53 +++--- modules/umig/outputs.tf | 7 +- modules/umig/variables.tf | 10 +- modules/umig/versions.tf | 19 +++ test/fixtures/compute_instance/simple/main.tf | 9 +- .../compute_instance/simple/outputs.tf | 7 +- .../compute_instance/simple/variables.tf | 9 +- .../compute_instance/simple/versions.tf | 19 +++ .../additional_disks/main.tf | 11 +- .../additional_disks/outputs.tf | 9 +- .../additional_disks/variables.tf | 7 +- .../additional_disks/versions.tf | 19 +++ .../fixtures/instance_template/simple/main.tf | 11 +- .../instance_template/simple/outputs.tf | 9 +- .../instance_template/simple/variables.tf | 8 +- .../instance_template/simple/versions.tf | 19 +++ test/fixtures/mig/autoscaler/main.tf | 19 ++- test/fixtures/mig/autoscaler/outputs.tf | 7 +- test/fixtures/mig/autoscaler/variables.tf | 9 +- test/fixtures/mig/autoscaler/versions.tf | 19 +++ test/fixtures/mig/simple/main.tf | 11 +- test/fixtures/mig/simple/outputs.tf | 9 +- test/fixtures/mig/simple/variables.tf | 9 +- test/fixtures/mig/simple/versions.tf | 19 +++ test/fixtures/shared/network.tf | 7 +- test/fixtures/umig/named_ports/main.tf | 9 +- test/fixtures/umig/named_ports/outputs.tf | 9 +- test/fixtures/umig/named_ports/variables.tf | 9 +- test/fixtures/umig/named_ports/versions.tf | 19 +++ test/fixtures/umig/simple/main.tf | 9 +- test/fixtures/umig/simple/outputs.tf | 9 +- test/fixtures/umig/simple/variables.tf | 10 +- test/fixtures/umig/simple/versions.tf | 19 +++ test/fixtures/umig/static_ips/main.tf | 9 +- test/fixtures/umig/static_ips/outputs.tf | 9 +- test/fixtures/umig/static_ips/variables.tf | 9 +- test/fixtures/umig/static_ips/versions.tf | 19 +++ test/make.sh | 11 +- test/verify_boilerplate.pyc | Bin 9055 -> 8935 bytes 96 files changed, 1278 insertions(+), 555 deletions(-) create mode 100644 examples/compute_instance/simple/versions.tf create mode 100644 examples/instance_template/additional_disks/versions.tf create mode 100644 examples/instance_template/simple/versions.tf create mode 100644 examples/mig/autoscaler/versions.tf create mode 100644 examples/mig/full/versions.tf create mode 100644 examples/mig/simple/versions.tf create mode 100644 examples/umig/full/versions.tf create mode 100644 examples/umig/named_ports/versions.tf create mode 100644 examples/umig/simple/versions.tf create mode 100644 examples/umig/static_ips/versions.tf create mode 100644 modules/compute_instance/versions.tf create mode 100644 modules/instance_template/versions.tf create mode 100644 modules/mig/versions.tf create mode 100644 modules/umig/versions.tf create mode 100644 test/fixtures/compute_instance/simple/versions.tf create mode 100644 test/fixtures/instance_template/additional_disks/versions.tf create mode 100644 test/fixtures/instance_template/simple/versions.tf create mode 100644 test/fixtures/mig/autoscaler/versions.tf create mode 100644 test/fixtures/mig/simple/versions.tf create mode 100644 test/fixtures/umig/named_ports/versions.tf create mode 100644 test/fixtures/umig/simple/versions.tf create mode 100644 test/fixtures/umig/static_ips/versions.tf diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ffd4df4..a7c8e261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + +- Supported version of Terraform is 0.12. [#16] + ## [0.2.0] - 2019-05-30 ### Added @@ -23,3 +27,4 @@ project adheres to [Semantic Versioning](http://semver.org/). [0.2.0]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v0.1.0...v0.2.0 [0.1.0]: https://github.com/terraform-google-modules/terraform-google-vm/releases/tag/v0.1.0 [#10]: https://github.com/terraform-google-modules/terraform-google-vm/pull/10 +[#16]: https://github.com/terraform-google-modules/terraform-google-vm/pull/16 diff --git a/Gemfile b/Gemfile index cdefb55c..87d5abb1 100644 --- a/Gemfile +++ b/Gemfile @@ -13,5 +13,5 @@ # limitations under the License. source 'https://rubygems.org/' do - gem 'kitchen-terraform', '~> 4.1' + gem 'kitchen-terraform', '~> 4.9' end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 2bc1e728..95bd501c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,61 +3,64 @@ GEM specs: addressable (2.6.0) public_suffix (>= 2.0.2, < 4.0) - aws-sdk (2.11.210) - aws-sdk-resources (= 2.11.210) - aws-sdk-core (2.11.210) + aws-eventstream (1.0.3) + aws-sdk (2.11.316) + aws-sdk-resources (= 2.11.316) + aws-sdk-core (2.11.316) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.210) - aws-sdk-core (= 2.11.210) - aws-sigv4 (1.0.3) - azure_graph_rbac (0.17.0) + aws-sdk-resources (2.11.316) + aws-sdk-core (= 2.11.316) + aws-sigv4 (1.1.0) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_graph_rbac (0.17.1) ms_rest_azure (~> 0.11.0) - azure_mgmt_key_vault (0.17.2) - ms_rest_azure (~> 0.11.0) - azure_mgmt_resources (0.17.2) + azure_mgmt_key_vault (0.17.4) ms_rest_azure (~> 0.11.0) + azure_mgmt_resources (0.17.6) + ms_rest_azure (~> 0.11.1) builder (3.2.3) coderay (1.1.2) - concurrent-ruby (1.1.4) + concurrent-ruby (1.1.5) declarative (0.0.10) declarative-option (0.1.0) diff-lcs (1.3) docker-api (1.34.2) excon (>= 0.47.0) multi_json - domain_name (0.5.20180417) + domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - dry-configurable (0.7.0) + dry-configurable (0.8.3) concurrent-ruby (~> 1.0) - dry-container (0.6.0) + dry-core (~> 0.4, >= 0.4.7) + dry-container (0.7.2) concurrent-ruby (~> 1.0) dry-configurable (~> 0.1, >= 0.1.3) - dry-core (0.4.7) + dry-core (0.4.8) concurrent-ruby (~> 1.0) - dry-equalizer (0.2.1) + dry-equalizer (0.2.2) dry-inflector (0.1.2) - dry-logic (0.4.2) - dry-container (~> 0.2, >= 0.2.6) + dry-logic (0.6.1) + concurrent-ruby (~> 1.0) dry-core (~> 0.2) dry-equalizer (~> 0.2) - dry-types (0.13.4) + dry-types (0.14.1) concurrent-ruby (~> 1.0) dry-container (~> 0.3) dry-core (~> 0.4, >= 0.4.4) dry-equalizer (~> 0.2) dry-inflector (~> 0.1, >= 0.1.2) - dry-logic (~> 0.4, >= 0.4.2) - dry-validation (0.12.2) + dry-logic (~> 0.5, >= 0.5) + dry-validation (0.13.0) concurrent-ruby (~> 1.0) dry-configurable (~> 0.1, >= 0.1.3) dry-core (~> 0.2, >= 0.2.1) dry-equalizer (~> 0.2) - dry-logic (~> 0.4, >= 0.4.0) - dry-types (~> 0.13.1) + dry-logic (~> 0.5, >= 0.5.0) + dry-types (~> 0.14, >= 0.14) equatable (0.5.0) erubis (2.7.0) - excon (0.62.0) + excon (0.64.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) @@ -65,7 +68,7 @@ GEM http-cookie (~> 1.0.0) faraday_middleware (0.12.2) faraday (>= 0.7.4, < 1.0) - ffi (1.10.0) + ffi (1.11.1) google-api-client (0.23.9) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.5, < 0.7.0) @@ -81,7 +84,7 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (~> 0.7) - gssapi (1.2.0) + gssapi (1.3.0) ffi (>= 1.0.1) gyoku (1.3.1) builder (>= 2.1.2) @@ -91,7 +94,7 @@ GEM domain_name (~> 0.5) httpclient (2.8.3) inifile (3.0.0) - inspec (3.2.6) + inspec (3.9.3) addressable (~> 2.4) faraday (>= 0.9.0) faraday_middleware (~> 0.12.2) @@ -112,19 +115,26 @@ GEM term-ansicolor thor (~> 0.20) tomlrb (~> 1.2) - train (~> 1.5, >= 1.6.3) + train (~> 1.5, >= 1.7.2) + train-habitat (~> 0.1) tty-prompt (~> 0.17) tty-table (~> 0.10) jmespath (1.4.0) json (2.1.0) - jwt (2.1.0) - kitchen-terraform (4.3.0) - dry-types (~> 0.9) - dry-validation (~> 0.10) + jwt (2.2.1) + kitchen-terraform (4.9.0) + dry-types (~> 0.14.0) + dry-validation (= 0.13.0) inspec (~> 3.0) + json (~> 2.1.0) mixlib-shellout (~> 2.2) test-kitchen (~> 1.23) tty-which (~> 0.4.0) + license-acceptance (1.0.13) + pastel (~> 0.7) + tomlrb (~> 1.2) + tty-box (~> 0.3) + tty-prompt (~> 0.18) little-plugger (1.1.4) logging (2.2.2) little-plugger (~> 1.1) @@ -133,34 +143,35 @@ GEM method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) - mime-types-data (3.2018.0812) - mixlib-install (3.11.5) + mime-types-data (3.2019.0331) + mixlib-install (3.11.18) mixlib-shellout mixlib-versioning thor mixlib-log (3.0.1) mixlib-shellout (2.4.4) mixlib-versioning (1.2.7) - ms_rest (0.7.3) + ms_rest (0.7.4) concurrent-ruby (~> 1.0) faraday (~> 0.9) - timeliness (~> 0.3) - ms_rest_azure (0.11.0) + timeliness (~> 0.3.10) + ms_rest_azure (0.11.1) concurrent-ruby (~> 1.0) faraday (~> 0.9) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.2) + ms_rest (~> 0.7.4) + unf_ext (= 0.0.7.2) multi_json (1.13.1) - multipart-post (2.0.0) + multipart-post (2.1.1) necromancer (0.4.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (4.2.0) - net-ssh-gateway (1.3.0) - net-ssh (>= 2.6.5) + net-ssh-gateway (2.0.0) + net-ssh (>= 4.0.0) nori (2.6.0) - os (1.0.0) - parallel (1.13.0) + os (1.0.1) + parallel (1.17.0) parslet (1.8.2) pastel (0.7.2) equatable (~> 0.5.0) @@ -168,7 +179,7 @@ GEM pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - public_suffix (3.0.3) + public_suffix (3.1.1) representable (3.0.4) declarative (< 0.1.0) declarative-option (< 0.2.0) @@ -178,20 +189,20 @@ GEM rspec-core (~> 3.8.0) rspec-expectations (~> 3.8.0) rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) + rspec-core (3.8.2) rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rspec-expectations (3.8.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-its (1.2.0) + rspec-its (1.3.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.8.0) + rspec-mocks (3.8.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (3.8.2) rubyntlm (0.6.2) - rubyzip (1.2.2) + rubyzip (1.2.3) semverse (3.0.0) signet (0.11.0) addressable (~> 2.3) @@ -199,29 +210,30 @@ GEM jwt (>= 1.5, < 3.0) multi_json (~> 1.10) sslshake (1.3.0) - strings (0.1.4) - strings-ansi (~> 0.1.0) - unicode-display_width (~> 1.4.0) - unicode_utils (~> 1.4.0) + strings (0.1.5) + strings-ansi (~> 0.1) + unicode-display_width (~> 1.5) + unicode_utils (~> 1.4) strings-ansi (0.1.0) term-ansicolor (1.7.1) tins (~> 1.0) - test-kitchen (1.24.0) + test-kitchen (1.25.0) + license-acceptance (~> 1.0, >= 1.0.11) mixlib-install (~> 3.6) mixlib-shellout (>= 1.2, < 3.0) - net-scp (~> 1.1) + net-scp (>= 1.1, < 3.0) net-ssh (>= 2.9, < 5.0) - net-ssh-gateway (~> 1.2) + net-ssh-gateway (>= 1.2, < 3.0) thor (~> 0.19) winrm (~> 2.0) winrm-elevated (~> 1.0) winrm-fs (~> 1.1) thor (0.20.3) - timeliness (0.3.8) + timeliness (0.3.10) timers (4.3.0) - tins (1.20.2) + tins (1.21.1) tomlrb (1.2.8) - train (1.6.3) + train (1.7.6) aws-sdk (~> 2) azure_graph_rbac (~> 0.16) azure_mgmt_key_vault (~> 0.17) @@ -231,13 +243,19 @@ GEM googleauth (~> 0.6.6) inifile json (>= 1.8, < 3.0) - mixlib-shellout (~> 2.0) + mixlib-shellout (>= 2.0) net-scp (~> 1.2) net-ssh (>= 2.9, < 6.0) winrm (~> 2.0) winrm-fs (~> 1.0) + train-habitat (0.1.1) + train (>= 1.7.5, < 3.0) + tty-box (0.3.0) + pastel (~> 0.7.2) + strings (~> 0.1.4) + tty-cursor (~> 0.6.0) tty-color (0.4.3) - tty-cursor (0.6.0) + tty-cursor (0.6.1) tty-prompt (0.18.1) necromancer (~> 0.4.0) pastel (~> 0.7.0) @@ -255,14 +273,14 @@ GEM pastel (~> 0.7.2) strings (~> 0.1.0) tty-screen (~> 0.6.4) - tty-which (0.4.0) + tty-which (0.4.1) uber (0.1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.5) - unicode-display_width (1.4.1) + unf_ext (0.0.7.2) + unicode-display_width (1.6.0) unicode_utils (1.4.0) - winrm (2.3.1) + winrm (2.3.2) builder (>= 2.1.2) erubis (~> 2.7) gssapi (~> 1.2) @@ -285,7 +303,7 @@ PLATFORMS ruby DEPENDENCIES - kitchen-terraform (~> 4.1)! + kitchen-terraform (~> 4.9)! BUNDLED WITH 1.17.3 diff --git a/Makefile b/Makefile index e39f49c2..dd1d4bb9 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ SHELL := /usr/bin/env bash # Docker build config variables CREDENTIALS_PATH ?= /cft/workdir/credentials.json DOCKER_ORG := gcr.io/cloud-foundation-cicd -DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 1.2.0 +DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0 DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM} @@ -31,7 +31,7 @@ all: check generate_docs # Run all available linters .PHONY: check -check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace +check: check_shell check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace # The .PHONY directive tells make that this isn't a real target and so # the presence of a file named 'check_shell' won't cause this target to stop @@ -101,7 +101,7 @@ docker_run: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - /bin/bash -c "source test/ci_integration.sh && setup_environment && exec /bin/bash" + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && exec /bin/bash" .PHONY: docker_create docker_create: @@ -111,7 +111,7 @@ docker_create: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - /bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create" + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen create" .PHONY: docker_converge docker_converge: @@ -121,7 +121,7 @@ docker_converge: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - /bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge" + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen converge" .PHONY: docker_verify docker_verify: @@ -131,7 +131,7 @@ docker_verify: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - /bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify" + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen verify" .PHONY: docker_destroy docker_destroy: @@ -141,7 +141,7 @@ docker_destroy: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - /bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy" + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen destroy" .PHONY: test_integration_docker test_integration_docker: @@ -151,4 +151,4 @@ test_integration_docker: -e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ -v $(CURDIR):/cft/workdir \ ${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ - make test_integration + /bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && make test_integration" diff --git a/README.md b/README.md index e5c43572..844922fb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,13 @@ This is a collection of opinionated submodules that can be used as building bloc * [Managed instance group](modules/mig) * [Unmanaged instance group](modules/umig) +## Compatibility + + This module is meant for use with Terraform 0.12. If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-12.html) + and need a Terraform 0.11.x-compatible version of this module, the last released version intended for + Terraform 0.11.x is [0.2.0](https://registry.terraform.io/modules/terraform-google-modules/vm/google/0.2.0). + + ## Examples Examples of how to use these modules can be found in the [examples](examples) folder. diff --git a/examples/compute_instance/simple/main.tf b/examples/compute_instance/simple/main.tf index 2dc64064..95228c0b 100644 --- a/examples/compute_instance/simple/main.tf +++ b/examples/compute_instance/simple/main.tf @@ -15,29 +15,30 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "compute_instance" { source = "../../../modules/compute_instance" - subnetwork = "${var.subnetwork}" - num_instances = "${var.num_instances}" + subnetwork = var.subnetwork + num_instances = var.num_instances hostname = "instance-simple" - instance_template = "${module.instance_template.self_link}" + instance_template = module.instance_template.self_link } + diff --git a/examples/compute_instance/simple/outputs.tf b/examples/compute_instance/simple/outputs.tf index 1b8f6c85..b71832fb 100644 --- a/examples/compute_instance/simple/outputs.tf +++ b/examples/compute_instance/simple/outputs.tf @@ -16,10 +16,11 @@ output "instances_self_links" { description = "List of self-links for compute instances" - value = "${module.compute_instance.instances_self_links}" + value = module.compute_instance.instances_self_links } output "available_zones" { description = "List of available zones in region" - value = "${module.compute_instance.available_zones}" + value = module.compute_instance.available_zones } + diff --git a/examples/compute_instance/simple/variables.tf b/examples/compute_instance/simple/variables.tf index 361796c2..323d586e 100644 --- a/examples/compute_instance/simple/variables.tf +++ b/examples/compute_instance/simple/variables.tf @@ -35,6 +35,10 @@ variable "num_instances" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string, + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } diff --git a/examples/compute_instance/simple/versions.tf b/examples/compute_instance/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/compute_instance/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/instance_template/additional_disks/main.tf b/examples/instance_template/additional_disks/main.tf index a1e87cc0..a5e1b47f 100644 --- a/examples/instance_template/additional_disks/main.tf +++ b/examples/instance_template/additional_disks/main.tf @@ -15,16 +15,16 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account name_prefix = "additional-disks" additional_disks = [ @@ -48,3 +48,4 @@ module "instance_template" { }, ] } + diff --git a/examples/instance_template/additional_disks/outputs.tf b/examples/instance_template/additional_disks/outputs.tf index 95bd8ccb..c221e11d 100644 --- a/examples/instance_template/additional_disks/outputs.tf +++ b/examples/instance_template/additional_disks/outputs.tf @@ -16,10 +16,11 @@ output "self_link" { description = "Self-link to the instance template" - value = "${module.instance_template.self_link}" + value = module.instance_template.self_link } output "name" { description = "Name of the instance templates" - value = "${module.instance_template.name}" + value = module.instance_template.name } + diff --git a/examples/instance_template/additional_disks/variables.tf b/examples/instance_template/additional_disks/variables.tf index 16aea539..7b6c95f2 100644 --- a/examples/instance_template/additional_disks/variables.tf +++ b/examples/instance_template/additional_disks/variables.tf @@ -32,6 +32,11 @@ variable "subnetwork" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/examples/instance_template/additional_disks/versions.tf b/examples/instance_template/additional_disks/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/instance_template/additional_disks/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/instance_template/simple/main.tf b/examples/instance_template/simple/main.tf index 4d9f41c0..be39c305 100644 --- a/examples/instance_template/simple/main.tf +++ b/examples/instance_template/simple/main.tf @@ -15,17 +15,18 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account name_prefix = "simple" - tags = "${var.tags}" - labels = "${var.labels}" + tags = var.tags + labels = var.labels } + diff --git a/examples/instance_template/simple/outputs.tf b/examples/instance_template/simple/outputs.tf index 95bd8ccb..c221e11d 100644 --- a/examples/instance_template/simple/outputs.tf +++ b/examples/instance_template/simple/outputs.tf @@ -16,10 +16,11 @@ output "self_link" { description = "Self-link to the instance template" - value = "${module.instance_template.self_link}" + value = module.instance_template.self_link } output "name" { description = "Name of the instance templates" - value = "${module.instance_template.name}" + value = module.instance_template.name } + diff --git a/examples/instance_template/simple/variables.tf b/examples/instance_template/simple/variables.tf index ef1b8b43..9d6526bb 100644 --- a/examples/instance_template/simple/variables.tf +++ b/examples/instance_template/simple/variables.tf @@ -32,16 +32,21 @@ variable "subnetwork" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } variable "tags" { - type = "list" + type = list(string) description = "Network tags, provided as a list" } variable "labels" { - type = "map" + type = map(string) description = "Labels, provided as a map" } + diff --git a/examples/instance_template/simple/versions.tf b/examples/instance_template/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/instance_template/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/mig/autoscaler/main.tf b/examples/mig/autoscaler/main.tf index fa65db08..54e095eb 100644 --- a/examples/mig/autoscaler/main.tf +++ b/examples/mig/autoscaler/main.tf @@ -15,32 +15,33 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "mig" { source = "../../../modules/mig" - region = "${var.region}" + region = var.region hostname = "mig-autoscaler" - subnetwork = "${var.subnetwork}" - autoscaling_enabled = "${var.autoscaling_enabled}" - min_replicas = "${var.min_replicas}" - autoscaling_cpu = "${var.autoscaling_cpu}" - instance_template = "${module.instance_template.self_link}" + subnetwork = var.subnetwork + autoscaling_enabled = var.autoscaling_enabled + min_replicas = var.min_replicas + autoscaling_cpu = var.autoscaling_cpu + instance_template = module.instance_template.self_link } + diff --git a/examples/mig/autoscaler/outputs.tf b/examples/mig/autoscaler/outputs.tf index f2932796..e4626393 100644 --- a/examples/mig/autoscaler/outputs.tf +++ b/examples/mig/autoscaler/outputs.tf @@ -16,10 +16,11 @@ output "instance_template_self_link" { description = "Self-link of instance template" - value = "${module.instance_template.self_link}" + value = module.instance_template.self_link } output "mig_self_link" { description = "Self-link for managed instance group" - value = "${module.mig.self_link}" + value = module.mig.self_link } + diff --git a/examples/mig/autoscaler/variables.tf b/examples/mig/autoscaler/variables.tf index eb4a8304..aff98f52 100644 --- a/examples/mig/autoscaler/variables.tf +++ b/examples/mig/autoscaler/variables.tf @@ -31,8 +31,12 @@ variable "subnetwork" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } variable "autoscaling_enabled" { @@ -43,7 +47,10 @@ variable "min_replicas" { description = "The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0." } + + variable "autoscaling_cpu" { description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization" - type = "list" + type = list(map(number)) } + diff --git a/examples/mig/autoscaler/versions.tf b/examples/mig/autoscaler/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/mig/autoscaler/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/mig/full/main.tf b/examples/mig/full/main.tf index 694f9191..afd4420f 100644 --- a/examples/mig/full/main.tf +++ b/examples/mig/full/main.tf @@ -15,78 +15,79 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" name_prefix = "${var.hostname}-instance-template" - machine_type = "${var.machine_type}" - tags = "${var.tags}" - labels = "${var.labels}" - startup_script = "${var.startup_script}" - metadata = "${var.metadata}" - service_account = "${var.service_account}" + machine_type = var.machine_type + tags = var.tags + labels = var.labels + startup_script = var.startup_script + metadata = var.metadata + service_account = var.service_account /* network */ - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - can_ip_forward = "${var.can_ip_forward}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + can_ip_forward = var.can_ip_forward /* image */ - source_image = "${var.source_image}" - source_image_family = "${var.source_image_family}" - source_image_project = "${var.source_image_project}" + source_image = var.source_image + source_image_family = var.source_image_family + source_image_project = var.source_image_project /* disks */ - disk_size_gb = "${var.disk_size_gb}" - disk_type = "${var.disk_type}" - auto_delete = "${var.auto_delete}" - additional_disks = "${var.additional_disks}" + disk_size_gb = var.disk_size_gb + disk_type = var.disk_type + auto_delete = var.auto_delete + additional_disks = var.additional_disks } module "mig" { source = "../../../modules/mig" - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - hostname = "${var.hostname}" - region = "${var.region}" - instance_template = "${module.instance_template.self_link}" - target_size = "${var.target_size}" - target_pools = "${var.target_pools}" - distribution_policy_zones = "${var.distribution_policy_zones}" - update_policy = "${var.update_policy}" - named_ports = "${var.named_ports}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + hostname = var.hostname + region = var.region + instance_template = module.instance_template.self_link + target_size = var.target_size + target_pools = var.target_pools + distribution_policy_zones = var.distribution_policy_zones + update_policy = var.update_policy + named_ports = var.named_ports /* health checks */ - http_healthcheck_enable = "${var.http_healthcheck_enable}" - tcp_healthcheck_enable = "${var.tcp_healthcheck_enable}" - hc_initial_delay_sec = "${var.hc_initial_delay_sec}" - hc_interval_sec = "${var.hc_interval_sec}" - hc_timeout_sec = "${var.hc_timeout_sec}" - hc_healthy_threshold = "${var.hc_healthy_threshold}" - hc_unhealthy_threshold = "${var.hc_unhealthy_threshold}" - hc_path = "${var.hc_path}" - hc_port = "${var.hc_port}" + http_healthcheck_enable = var.http_healthcheck_enable + tcp_healthcheck_enable = var.tcp_healthcheck_enable + hc_initial_delay_sec = var.hc_initial_delay_sec + hc_interval_sec = var.hc_interval_sec + hc_timeout_sec = var.hc_timeout_sec + hc_healthy_threshold = var.hc_healthy_threshold + hc_unhealthy_threshold = var.hc_unhealthy_threshold + hc_path = var.hc_path + hc_port = var.hc_port /* autoscaler */ - autoscaling_enabled = "${var.autoscaling_enabled}" - max_replicas = "${var.max_replicas}" - min_replicas = "${var.min_replicas}" - cooldown_period = "${var.cooldown_period}" - autoscaling_cpu = "${var.autoscaling_cpu}" - autoscaling_metric = "${var.autoscaling_metric}" - autoscaling_lb = "${var.autoscaling_lb}" + autoscaling_enabled = var.autoscaling_enabled + max_replicas = var.max_replicas + min_replicas = var.min_replicas + cooldown_period = var.cooldown_period + autoscaling_cpu = var.autoscaling_cpu + autoscaling_metric = var.autoscaling_metric + autoscaling_lb = var.autoscaling_lb } + diff --git a/examples/mig/full/outputs.tf b/examples/mig/full/outputs.tf index f2932796..e4626393 100644 --- a/examples/mig/full/outputs.tf +++ b/examples/mig/full/outputs.tf @@ -16,10 +16,11 @@ output "instance_template_self_link" { description = "Self-link of instance template" - value = "${module.instance_template.self_link}" + value = module.instance_template.self_link } output "mig_self_link" { description = "Self-link for managed instance group" - value = "${module.mig.self_link}" + value = module.mig.self_link } + diff --git a/examples/mig/full/variables.tf b/examples/mig/full/variables.tf index 51c09e02..9e381a29 100644 --- a/examples/mig/full/variables.tf +++ b/examples/mig/full/variables.tf @@ -54,8 +54,11 @@ variable "subnetwork_project" { variable "named_ports" { description = "Named name and named port" - type = "list" - default = [] + type = list(object({ + name = string + port = number + })) + default = [] } #################### @@ -77,13 +80,13 @@ variable "can_ip_forward" { } variable "tags" { - type = "list" + type = list(string) description = "Network tags, provided as a list" default = [] } variable "labels" { - type = "map" + type = map(string) description = "Labels, provided as a map" default = {} } @@ -121,10 +124,16 @@ variable "auto_delete" { variable "additional_disks" { description = "List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name" - type = "list" - default = [] + type = list(object({ + auto_delete = bool + boot = bool + disk_size_gb = number + disk_type = string + })) + default = [] } + /* metadata */ variable "startup_script" { description = "User startup script to run when instances spin up" @@ -132,15 +141,19 @@ variable "startup_script" { } variable "metadata" { - type = "map" + type = map(string) description = "Metadata, provided as a map" default = {} } /* service account */ variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } ########################## @@ -154,20 +167,28 @@ variable "target_size" { variable "target_pools" { description = "The target load balancing pools to assign this group to." - type = "list" + type = list(string) default = [] } variable "distribution_policy_zones" { description = "The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region." - type = "list" + type = list(string) default = [] } variable "update_policy" { description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager.html#rolling_update_policy" - type = "list" - default = [] + type = list(object({ + max_surge_fixed = number + max_surge_percent = number + max_unavailable_fixed = number + max_unavailable_percent = number + min_ready_sec = number + minimal_action = string + type = string + })) + default = [] } /* health checks */ @@ -236,22 +257,29 @@ variable "cooldown_period" { variable "autoscaling_cpu" { description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization" - type = "list" + type = list(map(number)) default = [] } variable "autoscaling_metric" { description = "Autoscaling, metric policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#metric" - type = "list" - default = [] + type = list(object({ + name = string + target = number + type = string + })) + default = [] } variable "autoscaling_lb" { description = "Autoscaling, load balancing utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#load_balancing_utilization" - type = "list" + type = list(map(number)) default = [] } variable "autoscaling_enabled" { description = "Creates an autoscaler for the managed instance group" + type = bool + default = false } + diff --git a/examples/mig/full/versions.tf b/examples/mig/full/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/mig/full/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/mig/simple/main.tf b/examples/mig/simple/main.tf index c8183013..e4d82815 100644 --- a/examples/mig/simple/main.tf +++ b/examples/mig/simple/main.tf @@ -15,29 +15,30 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "mig" { source = "../../../modules/mig" - region = "${var.region}" - target_size = "${var.target_size}" + region = var.region + target_size = var.target_size hostname = "mig-simple" - instance_template = "${module.instance_template.self_link}" + instance_template = module.instance_template.self_link } + diff --git a/examples/mig/simple/outputs.tf b/examples/mig/simple/outputs.tf index 9e22763f..23b81662 100644 --- a/examples/mig/simple/outputs.tf +++ b/examples/mig/simple/outputs.tf @@ -16,5 +16,6 @@ output "self_link" { description = "Self-link of the managed instance group" - value = "${module.mig.self_link}" + value = module.mig.self_link } + diff --git a/examples/mig/simple/variables.tf b/examples/mig/simple/variables.tf index ee5c589b..32589f68 100644 --- a/examples/mig/simple/variables.tf +++ b/examples/mig/simple/variables.tf @@ -35,6 +35,11 @@ variable "target_size" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/examples/mig/simple/versions.tf b/examples/mig/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/mig/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/umig/full/main.tf b/examples/umig/full/main.tf index 0be27cf9..ba7a3d22 100644 --- a/examples/umig/full/main.tf +++ b/examples/umig/full/main.tf @@ -15,55 +15,56 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" name_prefix = "${var.hostname}-instance-template" - machine_type = "${var.machine_type}" - tags = "${var.tags}" - labels = "${var.labels}" - startup_script = "${var.startup_script}" - metadata = "${var.metadata}" - service_account = "${var.service_account}" + machine_type = var.machine_type + tags = var.tags + labels = var.labels + startup_script = var.startup_script + metadata = var.metadata + service_account = var.service_account /* network */ - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - can_ip_forward = "${var.can_ip_forward}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + can_ip_forward = var.can_ip_forward /* image */ - source_image = "${var.source_image}" - source_image_family = "${var.source_image_family}" - source_image_project = "${var.source_image_project}" + source_image = var.source_image + source_image_family = var.source_image_family + source_image_project = var.source_image_project /* disks */ - disk_size_gb = "${var.disk_size_gb}" - disk_type = "${var.disk_type}" - auto_delete = "${var.auto_delete}" - additional_disks = "${var.additional_disks}" + disk_size_gb = var.disk_size_gb + disk_type = var.disk_type + auto_delete = var.auto_delete + additional_disks = var.additional_disks } module "umig" { source = "../../../modules/umig" - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - hostname = "${var.hostname}" - static_ips = "${var.static_ips}" - num_instances = "${var.target_size}" - instance_template = "${module.instance_template.self_link}" - named_ports = "${var.named_ports}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + hostname = var.hostname + static_ips = var.static_ips + num_instances = var.target_size + instance_template = module.instance_template.self_link + named_ports = var.named_ports } + diff --git a/examples/umig/full/outputs.tf b/examples/umig/full/outputs.tf index 38ac536d..1a510bf9 100644 --- a/examples/umig/full/outputs.tf +++ b/examples/umig/full/outputs.tf @@ -16,10 +16,11 @@ output "instance_template_self_link" { description = "Self-link of instance template" - value = "${module.instance_template.self_link}" + value = module.instance_template.self_link } output "umig_self_links" { description = "List of self-links for unmanaged instance groups" - value = "${module.umig.self_links}" + value = module.umig.self_links } + diff --git a/examples/umig/full/variables.tf b/examples/umig/full/variables.tf index 9dc60100..6fe35323 100644 --- a/examples/umig/full/variables.tf +++ b/examples/umig/full/variables.tf @@ -53,8 +53,11 @@ variable "subnetwork_project" { variable "named_ports" { description = "Named name and named port" - type = "list" - default = [] + type = list(object({ + name = string + port = number + })) + default = [] } #################### @@ -76,13 +79,13 @@ variable "can_ip_forward" { } variable "tags" { - type = "list" + type = list(string) description = "Network tags, provided as a list" default = [] } variable "labels" { - type = "map" + type = map(string) description = "Labels, provided as a map" default = {} } @@ -120,8 +123,13 @@ variable "auto_delete" { variable "additional_disks" { description = "List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name" - type = "list" - default = [] + type = list(object({ + auto_delete = bool + boot = bool + disk_size_gb = number + disk_type = string + })) + default = [] } /* metadata */ @@ -131,15 +139,19 @@ variable "startup_script" { } variable "metadata" { - type = "map" + type = map(string) description = "Metadata, provided as a map" default = {} } /* service account */ variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } ############################ @@ -152,7 +164,8 @@ variable "target_size" { } variable "static_ips" { - type = "list" + type = list(string) description = "List of static IPs for VM instances." default = [] } + diff --git a/examples/umig/full/versions.tf b/examples/umig/full/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/umig/full/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/umig/named_ports/main.tf b/examples/umig/named_ports/main.tf index c04d4d6a..a8592960 100644 --- a/examples/umig/named_ports/main.tf +++ b/examples/umig/named_ports/main.tf @@ -15,30 +15,31 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "umig" { source = "../../../modules/umig" - subnetwork = "${var.subnetwork}" - num_instances = "${var.num_instances}" + subnetwork = var.subnetwork + num_instances = var.num_instances hostname = "umig-named-ports" - instance_template = "${module.instance_template.self_link}" - named_ports = "${var.named_ports}" + instance_template = module.instance_template.self_link + named_ports = var.named_ports } + diff --git a/examples/umig/named_ports/outputs.tf b/examples/umig/named_ports/outputs.tf index 2d1fa0ae..244f0748 100644 --- a/examples/umig/named_ports/outputs.tf +++ b/examples/umig/named_ports/outputs.tf @@ -16,15 +16,16 @@ output "self_links" { description = "List of self-links of unmanaged instance groups" - value = "${module.umig.self_links}" + value = module.umig.self_links } output "instances_self_links" { description = "List of self-links for compute instances" - value = "${module.umig.instances_self_links}" + value = module.umig.instances_self_links } output "available_zones" { description = "List of available zones in region" - value = "${module.umig.available_zones}" + value = module.umig.available_zones } + diff --git a/examples/umig/named_ports/variables.tf b/examples/umig/named_ports/variables.tf index 96b021e2..a4c32281 100644 --- a/examples/umig/named_ports/variables.tf +++ b/examples/umig/named_ports/variables.tf @@ -35,11 +35,19 @@ variable "num_instances" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } variable "named_ports" { - description = "List of named ports" - type = "list" -} + description = "Named name and named port" + type = list(object({ + name = string + port = number + })) + default = [] +} \ No newline at end of file diff --git a/examples/umig/named_ports/versions.tf b/examples/umig/named_ports/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/umig/named_ports/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/umig/simple/main.tf b/examples/umig/simple/main.tf index 102d0cc6..6925a280 100644 --- a/examples/umig/simple/main.tf +++ b/examples/umig/simple/main.tf @@ -15,29 +15,30 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "umig" { source = "../../../modules/umig" - subnetwork = "${var.subnetwork}" - num_instances = "${var.num_instances}" + subnetwork = var.subnetwork + num_instances = var.num_instances hostname = "umig-simple" - instance_template = "${module.instance_template.self_link}" + instance_template = module.instance_template.self_link } + diff --git a/examples/umig/simple/outputs.tf b/examples/umig/simple/outputs.tf index 2d1fa0ae..244f0748 100644 --- a/examples/umig/simple/outputs.tf +++ b/examples/umig/simple/outputs.tf @@ -16,15 +16,16 @@ output "self_links" { description = "List of self-links of unmanaged instance groups" - value = "${module.umig.self_links}" + value = module.umig.self_links } output "instances_self_links" { description = "List of self-links for compute instances" - value = "${module.umig.instances_self_links}" + value = module.umig.instances_self_links } output "available_zones" { description = "List of available zones in region" - value = "${module.umig.available_zones}" + value = module.umig.available_zones } + diff --git a/examples/umig/simple/variables.tf b/examples/umig/simple/variables.tf index 361796c2..a3cffd92 100644 --- a/examples/umig/simple/variables.tf +++ b/examples/umig/simple/variables.tf @@ -35,6 +35,11 @@ variable "num_instances" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/examples/umig/simple/versions.tf b/examples/umig/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/umig/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/examples/umig/static_ips/main.tf b/examples/umig/static_ips/main.tf index d5e9f694..f6d7ac36 100644 --- a/examples/umig/static_ips/main.tf +++ b/examples/umig/static_ips/main.tf @@ -15,30 +15,31 @@ */ provider "google" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } provider "google-beta" { - credentials = "${file(var.credentials_path)}" - project = "${var.project_id}" - region = "${var.region}" - version = "~> 1.19" + credentials = file(var.credentials_path) + project = var.project_id + region = var.region + version = "~> 2.7.0" } module "instance_template" { source = "../../../modules/instance_template" - subnetwork = "${var.subnetwork}" - service_account = "${var.service_account}" + subnetwork = var.subnetwork + service_account = var.service_account } module "umig" { source = "../../../modules/umig" - subnetwork = "${var.subnetwork}" - num_instances = "${var.num_instances}" + subnetwork = var.subnetwork + num_instances = var.num_instances hostname = "umig-static-ips" - instance_template = "${module.instance_template.self_link}" - static_ips = "${var.static_ips}" + instance_template = module.instance_template.self_link + static_ips = var.static_ips } + diff --git a/examples/umig/static_ips/outputs.tf b/examples/umig/static_ips/outputs.tf index 2d1fa0ae..244f0748 100644 --- a/examples/umig/static_ips/outputs.tf +++ b/examples/umig/static_ips/outputs.tf @@ -16,15 +16,16 @@ output "self_links" { description = "List of self-links of unmanaged instance groups" - value = "${module.umig.self_links}" + value = module.umig.self_links } output "instances_self_links" { description = "List of self-links for compute instances" - value = "${module.umig.instances_self_links}" + value = module.umig.instances_self_links } output "available_zones" { description = "List of available zones in region" - value = "${module.umig.available_zones}" + value = module.umig.available_zones } + diff --git a/examples/umig/static_ips/variables.tf b/examples/umig/static_ips/variables.tf index 9558b1cf..a8b887e7 100644 --- a/examples/umig/static_ips/variables.tf +++ b/examples/umig/static_ips/variables.tf @@ -36,11 +36,15 @@ variable "num_instances" { } variable "static_ips" { - type = "list" + type = list(string) description = "List of static IPs for VM instances" } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } diff --git a/examples/umig/static_ips/versions.tf b/examples/umig/static_ips/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/examples/umig/static_ips/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/modules/compute_instance/main.tf b/modules/compute_instance/main.tf index c935d4e5..f3295c43 100644 --- a/modules/compute_instance/main.tf +++ b/modules/compute_instance/main.tf @@ -15,37 +15,39 @@ */ locals { - hostname = "${var.hostname == "" ? "default" : var.hostname}" - num_instances = "${length(var.static_ips) == 0 ? var.num_instances : length(var.static_ips)}" + hostname = var.hostname == "" ? "default" : var.hostname + num_instances = length(var.static_ips) == 0 ? var.num_instances : length(var.static_ips) # local.static_ips is the same as var.static_ips with a dummy element appended # at the end of the list to work around "list does not have any elements so cannot # determine type" error when var.static_ips is empty - static_ips = "${concat(var.static_ips, list("NOT_AN_IP"))}" + static_ips = concat(var.static_ips, ["NOT_AN_IP"]) } ############### # Data Sources ############### -data "google_compute_zones" "available" {} +data "google_compute_zones" "available" { +} ############# # Instances ############# resource "google_compute_instance_from_template" "compute_instance" { - provider = "google" - count = "${local.num_instances}" + provider = google + count = local.num_instances name = "${local.hostname}-${format("%03d", count.index + 1)}" - zone = "${data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)]}" + zone = data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] network_interface { - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - network_ip = "${length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index)}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + network_ip = length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index) } - source_instance_template = "${var.instance_template}" + source_instance_template = var.instance_template } + diff --git a/modules/compute_instance/outputs.tf b/modules/compute_instance/outputs.tf index 7fa00c25..7984fce3 100644 --- a/modules/compute_instance/outputs.tf +++ b/modules/compute_instance/outputs.tf @@ -16,10 +16,11 @@ output "instances_self_links" { description = "List of self-links for compute instances" - value = ["${google_compute_instance_from_template.compute_instance.*.self_link}"] + value = google_compute_instance_from_template.compute_instance.*.self_link } output "available_zones" { description = "List of available zones in region" - value = ["${data.google_compute_zones.available.names}"] + value = data.google_compute_zones.available.names } + diff --git a/modules/compute_instance/variables.tf b/modules/compute_instance/variables.tf index 0d4dd15c..f298f388 100644 --- a/modules/compute_instance/variables.tf +++ b/modules/compute_instance/variables.tf @@ -35,7 +35,7 @@ variable "hostname" { } variable "static_ips" { - type = "list" + type = list(string) description = "List of static IPs for VM instances" default = [] } @@ -48,3 +48,4 @@ variable "num_instances" { variable "instance_template" { description = "Instance template self_link used to create compute instances" } + diff --git a/modules/compute_instance/versions.tf b/modules/compute_instance/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/modules/compute_instance/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/modules/instance_template/main.tf b/modules/instance_template/main.tf index 54b52d47..e4672559 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -18,13 +18,13 @@ # Data Sources ############### data "google_compute_image" "image" { - project = "${var.source_image != "" ? var.source_image_project : "centos-cloud"}" - name = "${var.source_image != "" ? var.source_image : "centos-6-v20180716"}" + project = var.source_image != "" ? var.source_image_project : "centos-cloud" + name = var.source_image != "" ? var.source_image : "centos-6-v20180716" } data "google_compute_image" "image_family" { - project = "${var.source_image_family != "" ? var.source_image_project : "centos-cloud"}" - family = "${var.source_image_family != "" ? var.source_image_family : "centos-6"}" + project = var.source_image_family != "" ? var.source_image_project : "centos-cloud" + family = var.source_image_family != "" ? var.source_image_family : "centos-6" } ######### @@ -32,15 +32,17 @@ data "google_compute_image" "image_family" { ######### locals { - boot_disk = [{ - source_image = "${var.source_image != "" ? data.google_compute_image.image.self_link : data.google_compute_image.image_family.self_link}" - disk_size_gb = "${var.disk_size_gb}" - disk_type = "${var.disk_type}" - auto_delete = "${var.auto_delete}" - boot = "true" - }] + boot_disk = [ + { + source_image = var.source_image != "" ? data.google_compute_image.image.self_link : data.google_compute_image.image_family.self_link + disk_size_gb = var.disk_size_gb + disk_type = var.disk_type + auto_delete = var.auto_delete + boot = "true" + }, + ] - all_disks = "${concat(local.boot_disk, var.additional_disks)}" + all_disks = concat(local.boot_disk, var.additional_disks) } #################### @@ -48,22 +50,51 @@ locals { #################### resource "google_compute_instance_template" "tpl" { name_prefix = "${var.name_prefix}-" - machine_type = "${var.machine_type}" - labels = "${var.labels}" - metadata = "${var.metadata}" - tags = "${var.tags}" - can_ip_forward = "${var.can_ip_forward}" - metadata_startup_script = "${var.startup_script}" - disk = ["${local.all_disks}"] - service_account = ["${var.service_account}"] + machine_type = var.machine_type + labels = var.labels + metadata = var.metadata + tags = var.tags + can_ip_forward = var.can_ip_forward + metadata_startup_script = var.startup_script + dynamic "disk" { + for_each = local.all_disks + content { + auto_delete = lookup(disk.value, "auto_delete", null) + boot = lookup(disk.value, "boot", null) + device_name = lookup(disk.value, "device_name", null) + disk_name = lookup(disk.value, "disk_name", null) + disk_size_gb = lookup(disk.value, "disk_size_gb", null) + disk_type = lookup(disk.value, "disk_type", null) + interface = lookup(disk.value, "interface", null) + mode = lookup(disk.value, "mode", null) + source = lookup(disk.value, "source", null) + source_image = lookup(disk.value, "source_image", null) + type = lookup(disk.value, "type", null) + + dynamic "disk_encryption_key" { + for_each = lookup(disk.value, "disk_encryption_key", []) + content { + kms_key_self_link = lookup(disk_encryption_key.value, "kms_key_self_link", null) + } + } + } + } + dynamic "service_account" { + for_each = [var.service_account] + content { + email = lookup(service_account.value, "email", null) + scopes = lookup(service_account.value, "scopes", null) + } + } network_interface { - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project } lifecycle { create_before_destroy = "true" } } + diff --git a/modules/instance_template/outputs.tf b/modules/instance_template/outputs.tf index 1dcad802..b0678331 100644 --- a/modules/instance_template/outputs.tf +++ b/modules/instance_template/outputs.tf @@ -15,9 +15,10 @@ */ output "self_link" { - value = "${google_compute_instance_template.tpl.self_link}" + value = google_compute_instance_template.tpl.self_link } output "name" { - value = "${google_compute_instance_template.tpl.name}" + value = google_compute_instance_template.tpl.name } + diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index 94fe1a04..2ed50f06 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -30,13 +30,13 @@ variable "can_ip_forward" { } variable "tags" { - type = "list" + type = list(string) description = "Network tags, provided as a list" default = [] } variable "labels" { - type = "map" + type = map(string) description = "Labels, provided as a map" default = {} } @@ -76,8 +76,13 @@ variable "auto_delete" { variable "additional_disks" { description = "List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name" - type = "list" - default = [] + type = list(object({ + auto_delete = bool + boot = bool + disk_size_gb = number + disk_type = string + })) + default = [] } #################### @@ -108,7 +113,7 @@ variable "startup_script" { } variable "metadata" { - type = "map" + type = map(string) description = "Metadata, provided as a map" default = {} } @@ -118,6 +123,10 @@ variable "metadata" { ################## variable "service_account" { - type = "map" + type = object({ + email = string + scopes = set(string) + }) description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/modules/instance_template/versions.tf b/modules/instance_template/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/modules/instance_template/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/modules/mig/main.tf b/modules/mig/main.tf index d5d663e1..c7ce3b7f 100644 --- a/modules/mig/main.tf +++ b/modules/mig/main.tf @@ -15,36 +15,58 @@ */ locals { - distribution_policy_zones = { - default = ["${data.google_compute_zones.available.names}"] - user = ["${var.distribution_policy_zones}"] + healthchecks = concat( + google_compute_health_check.http_healthcheck.*.self_link, + google_compute_health_check.tcp_healthcheck.*.self_link, + ) + distribution_policy_zones_base = { + default = data.google_compute_zones.available.names + user = var.distribution_policy_zones } + distribution_policy_zones = local.distribution_policy_zones_base[length(var.distribution_policy_zones) == 0 ? "default" : "user"] } -data "google_compute_zones" "available" {} +data "google_compute_zones" "available" { +} resource "google_compute_region_instance_group_manager" "mig" { - provider = "google-beta" - base_instance_name = "${var.hostname}" + provider = google-beta + base_instance_name = var.hostname - version = { + version { name = "${var.hostname}-mig-version-0" - instance_template = "${var.instance_template}" + instance_template = var.instance_template } - name = "${var.hostname}-mig" - region = "${var.region}" - named_port = ["${var.named_ports}"] - target_pools = ["${var.target_pools}"] - target_size = "${var.autoscaling_enabled ? var.min_replicas : var.target_size}" + name = "${var.hostname}-mig" + region = var.region + dynamic "named_port" { + for_each = var.named_ports + content { + name = lookup(named_port.value, "name", null) + port = lookup(named_port.value, "port", null) + } + } + target_pools = var.target_pools + target_size = var.autoscaling_enabled ? var.min_replicas : var.target_size auto_healing_policies { - health_check = "${var.http_healthcheck_enable || var.tcp_healthcheck_enable ? element(concat(google_compute_health_check.http_healthcheck.*.self_link, google_compute_health_check.tcp_healthcheck.*.self_link, list("")),0) : ""}" - initial_delay_sec = "${var.hc_initial_delay_sec}" + health_check = length(local.healthchecks) > 0 ? local.healthchecks[0] : null + initial_delay_sec = length(local.healthchecks) > 0 ? var.hc_initial_delay_sec : null + } + distribution_policy_zones = local.distribution_policy_zones + dynamic "update_policy" { + for_each = var.update_policy + content { + max_surge_fixed = lookup(update_policy.value, "max_surge_fixed", null) + max_surge_percent = lookup(update_policy.value, "max_surge_percent", null) + max_unavailable_fixed = lookup(update_policy.value, "max_unavailable_fixed", null) + max_unavailable_percent = lookup(update_policy.value, "max_unavailable_percent", null) + min_ready_sec = lookup(update_policy.value, "min_ready_sec", null) + minimal_action = update_policy.value.minimal_action + type = update_policy.value.type + } } - - distribution_policy_zones = ["${local.distribution_policy_zones["${length(var.distribution_policy_zones) == 0 ? "default" : "user"}"]}"] - update_policy = ["${var.update_policy}"] lifecycle { create_before_destroy = "true" @@ -52,48 +74,66 @@ resource "google_compute_region_instance_group_manager" "mig" { } resource "google_compute_region_autoscaler" "autoscaler" { - provider = "google" - count = "${var.autoscaling_enabled ? 1 : 0}" + provider = google + count = var.autoscaling_enabled ? 1 : 0 name = "${var.hostname}-autoscaler" - target = "${google_compute_region_instance_group_manager.mig.self_link}" - - autoscaling_policy = { - max_replicas = "${var.max_replicas}" - min_replicas = "${var.min_replicas}" - cooldown_period = "${var.cooldown_period}" - cpu_utilization = ["${var.autoscaling_cpu}"] - metric = ["${var.autoscaling_metric}"] - load_balancing_utilization = ["${var.autoscaling_lb}"] + target = google_compute_region_instance_group_manager.mig.self_link + + autoscaling_policy { + max_replicas = var.max_replicas + min_replicas = var.min_replicas + cooldown_period = var.cooldown_period + dynamic "cpu_utilization" { + for_each = var.autoscaling_cpu + content { + target = lookup(cpu_utilization.value, "target", null) + } + } + dynamic "metric" { + for_each = var.autoscaling_metric + content { + name = lookup(metric.value, "name", null) + target = lookup(metric.value, "target", null) + type = lookup(metric.value, "type", null) + } + } + dynamic "load_balancing_utilization" { + for_each = var.autoscaling_lb + content { + target = lookup(load_balancing_utilization.value, "target", null) + } + } } } resource "google_compute_health_check" "http_healthcheck" { - provider = "google" - count = "${var.http_healthcheck_enable ? 1 : 0}" + provider = google + count = var.http_healthcheck_enable ? 1 : 0 name = "${var.hostname}-http-healthcheck" - check_interval_sec = "${var.hc_interval_sec}" - timeout_sec = "${var.hc_timeout_sec}" - healthy_threshold = "${var.hc_healthy_threshold}" - unhealthy_threshold = "${var.hc_unhealthy_threshold}" + check_interval_sec = var.hc_interval_sec + timeout_sec = var.hc_timeout_sec + healthy_threshold = var.hc_healthy_threshold + unhealthy_threshold = var.hc_unhealthy_threshold http_health_check { - request_path = "${var.hc_path}" - port = "${var.hc_port}" + request_path = var.hc_path + port = var.hc_port } } resource "google_compute_health_check" "tcp_healthcheck" { - provider = "google" - count = "${var.tcp_healthcheck_enable ? 1 : 0}" + provider = google + count = var.tcp_healthcheck_enable ? 1 : 0 name = "${var.hostname}-tcp-healthcheck" - check_interval_sec = "${var.hc_interval_sec}" - timeout_sec = "${var.hc_timeout_sec}" - healthy_threshold = "${var.hc_healthy_threshold}" - unhealthy_threshold = "${var.hc_unhealthy_threshold}" + check_interval_sec = var.hc_interval_sec + timeout_sec = var.hc_timeout_sec + healthy_threshold = var.hc_healthy_threshold + unhealthy_threshold = var.hc_unhealthy_threshold tcp_health_check { - port = "${var.hc_port}" + port = var.hc_port } } + diff --git a/modules/mig/outputs.tf b/modules/mig/outputs.tf index e642e49f..3aef5cd6 100644 --- a/modules/mig/outputs.tf +++ b/modules/mig/outputs.tf @@ -16,10 +16,11 @@ output "self_link" { description = "Self-link of managed instance group" - value = "${google_compute_region_instance_group_manager.mig.self_link}" + value = google_compute_region_instance_group_manager.mig.self_link } output "instance_group" { description = "Instance-group url of managed instance group" - value = "${google_compute_region_instance_group_manager.mig.instance_group}" + value = google_compute_region_instance_group_manager.mig.instance_group } + diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index 77680ccf..b8d278ee 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -34,13 +34,13 @@ variable "target_size" { variable "target_pools" { description = "The target load balancing pools to assign this group to." - type = "list" + type = list(string) default = [] } variable "distribution_policy_zones" { description = "The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region." - type = "list" + type = list(string) default = [] } @@ -50,8 +50,16 @@ variable "distribution_policy_zones" { variable "update_policy" { description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager.html#rolling_update_policy" - type = "list" - default = [] + type = list(object({ + max_surge_fixed = number + max_surge_percent = number + max_unavailable_fixed = number + max_unavailable_percent = number + min_ready_sec = number + minimal_action = string + type = string + })) + default = [] } ############## @@ -128,19 +136,23 @@ variable "cooldown_period" { variable "autoscaling_cpu" { description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization" - type = "list" + type = list(map(number)) default = [] } variable "autoscaling_metric" { description = "Autoscaling, metric policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#metric" - type = "list" - default = [] + type = list(object({ + name = string + target = number + type = string + })) + default = [] } variable "autoscaling_lb" { description = "Autoscaling, load balancing utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#load_balancing_utilization" - type = "list" + type = list(map(number)) default = [] } @@ -162,7 +174,10 @@ variable "subnetwork_project" { } variable "named_ports" { - description = "Named name and named port. https://cloud.google.com/load-balancing/docs/backend-service#named_ports" - type = "list" - default = [] + description = "Named name and named port" + type = list(object({ + name = string + port = number + })) + default = [] } diff --git a/modules/mig/versions.tf b/modules/mig/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/modules/mig/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/modules/umig/main.tf b/modules/umig/main.tf index 441043c3..287693a2 100644 --- a/modules/umig/main.tf +++ b/modules/umig/main.tf @@ -15,49 +15,64 @@ */ locals { - hostname = "${var.hostname == "" ? "default" : var.hostname}" - num_instances = "${length(var.static_ips) == 0 ? var.num_instances : length(var.static_ips)}" + hostname = var.hostname == "" ? "default" : var.hostname + num_instances = length(var.static_ips) == 0 ? var.num_instances : length(var.static_ips) # local.static_ips is the same as var.static_ips with a dummy element appended # at the end of the list to work around "list does not have any elements so cannot # determine type" error when var.static_ips is empty - static_ips = "${concat(var.static_ips, list("NOT_AN_IP"))}" + static_ips = concat(var.static_ips, ["NOT_AN_IP"]) - instance_group_count = "${min(local.num_instances, length(data.google_compute_zones.available.names))}" + instance_group_count = min( + local.num_instances, + length(data.google_compute_zones.available.names), + ) } ############### # Data Sources ############### -data "google_compute_zones" "available" {} +data "google_compute_zones" "available" { +} ############# # Instances ############# resource "google_compute_instance_from_template" "compute_instance" { - provider = "google" - count = "${local.num_instances}" + provider = google + count = local.num_instances name = "${local.hostname}-${format("%03d", count.index + 1)}" - zone = "${data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)]}" + zone = data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] network_interface { - network = "${var.network}" - subnetwork = "${var.subnetwork}" - subnetwork_project = "${var.subnetwork_project}" - network_ip = "${length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index)}" + network = var.network + subnetwork = var.subnetwork + subnetwork_project = var.subnetwork_project + network_ip = length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index) } - source_instance_template = "${var.instance_template}" + source_instance_template = var.instance_template } resource "google_compute_instance_group" "instance_group" { - provider = "google" - count = "${local.instance_group_count}" - name = "${local.hostname}-instance-group-${format("%03d", count.index + 1)}" - zone = "${element(data.google_compute_zones.available.names, count.index)}" - instances = ["${matchkeys(google_compute_instance_from_template.compute_instance.*.self_link, google_compute_instance_from_template.compute_instance.*.zone, list(data.google_compute_zones.available.names[count.index]))}"] + provider = google + count = local.instance_group_count + name = "${local.hostname}-instance-group-${format("%03d", count.index + 1)}" + zone = element(data.google_compute_zones.available.names, count.index) + instances = matchkeys( + google_compute_instance_from_template.compute_instance.*.self_link, + google_compute_instance_from_template.compute_instance.*.zone, + [data.google_compute_zones.available.names[count.index]], + ) - named_port = "${var.named_ports}" + dynamic "named_port" { + for_each = var.named_ports + content { + name = named_port.value.name + port = named_port.value.port + } + } } + diff --git a/modules/umig/outputs.tf b/modules/umig/outputs.tf index e6870a16..dbd326de 100644 --- a/modules/umig/outputs.tf +++ b/modules/umig/outputs.tf @@ -16,15 +16,16 @@ output "self_links" { description = "List of self-links for unmanaged instance groups" - value = ["${google_compute_instance_group.instance_group.*.self_link}"] + value = google_compute_instance_group.instance_group.*.self_link } output "instances_self_links" { description = "List of self-links for compute instances" - value = ["${google_compute_instance_from_template.compute_instance.*.self_link}"] + value = google_compute_instance_from_template.compute_instance.*.self_link } output "available_zones" { description = "List of available zones in region" - value = ["${data.google_compute_zones.available.names}"] + value = data.google_compute_zones.available.names } + diff --git a/modules/umig/variables.tf b/modules/umig/variables.tf index 91879726..d5c57f6c 100644 --- a/modules/umig/variables.tf +++ b/modules/umig/variables.tf @@ -35,7 +35,7 @@ variable "hostname" { } variable "static_ips" { - type = "list" + type = list(string) description = "List of static IPs for VM instances" default = [] } @@ -47,10 +47,14 @@ variable "num_instances" { variable "named_ports" { description = "Named name and named port" - type = "list" - default = [] + type = list(object({ + name = string + port = number + })) + default = [] } variable "instance_template" { description = "Instance template self_link used to create compute instances" } + diff --git a/modules/umig/versions.tf b/modules/umig/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/modules/umig/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/compute_instance/simple/main.tf b/test/fixtures/compute_instance/simple/main.tf index a794b55a..52bd4b96 100644 --- a/test/fixtures/compute_instance/simple/main.tf +++ b/test/fixtures/compute_instance/simple/main.tf @@ -20,10 +20,11 @@ locals { module "instance_simple" { source = "../../../../examples/compute_instance/simple" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" + credentials_path = local.credentials_path + project_id = var.project_id region = "us-central1" - subnetwork = "${google_compute_subnetwork.main.name}" + subnetwork = google_compute_subnetwork.main.name num_instances = 4 - service_account = "${var.service_account}" + service_account = var.service_account } + diff --git a/test/fixtures/compute_instance/simple/outputs.tf b/test/fixtures/compute_instance/simple/outputs.tf index 9b8b0a32..12a4dc8d 100644 --- a/test/fixtures/compute_instance/simple/outputs.tf +++ b/test/fixtures/compute_instance/simple/outputs.tf @@ -16,15 +16,16 @@ output "instances_self_links" { description = "List of instance self-links" - value = "${module.instance_simple.instances_self_links}" + value = module.instance_simple.instances_self_links } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/compute_instance/simple/variables.tf b/test/fixtures/compute_instance/simple/variables.tf index 59ac0fd0..a87f8ff0 100644 --- a/test/fixtures/compute_instance/simple/variables.tf +++ b/test/fixtures/compute_instance/simple/variables.tf @@ -23,6 +23,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = list(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/compute_instance/simple/versions.tf b/test/fixtures/compute_instance/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/compute_instance/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/instance_template/additional_disks/main.tf b/test/fixtures/instance_template/additional_disks/main.tf index 935f6030..cb54648d 100644 --- a/test/fixtures/instance_template/additional_disks/main.tf +++ b/test/fixtures/instance_template/additional_disks/main.tf @@ -20,9 +20,10 @@ locals { module "instance_template_additional_disks" { source = "../../../../examples/instance_template/additional_disks" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" - region = "${var.region}" - subnetwork = "${google_compute_subnetwork.main.name}" - service_account = "${var.service_account}" + credentials_path = local.credentials_path + project_id = var.project_id + region = var.region + subnetwork = google_compute_subnetwork.main.name + service_account = var.service_account } + diff --git a/test/fixtures/instance_template/additional_disks/outputs.tf b/test/fixtures/instance_template/additional_disks/outputs.tf index 08e318ed..ec354ec8 100644 --- a/test/fixtures/instance_template/additional_disks/outputs.tf +++ b/test/fixtures/instance_template/additional_disks/outputs.tf @@ -16,20 +16,21 @@ output "self_link" { description = "Self-link to instance template" - value = "${module.instance_template_additional_disks.self_link}" + value = module.instance_template_additional_disks.self_link } output "name" { description = "Name of instance template" - value = "${module.instance_template_additional_disks.name}" + value = module.instance_template_additional_disks.name } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/instance_template/additional_disks/variables.tf b/test/fixtures/instance_template/additional_disks/variables.tf index 4a02862e..49c6e021 100644 --- a/test/fixtures/instance_template/additional_disks/variables.tf +++ b/test/fixtures/instance_template/additional_disks/variables.tf @@ -27,6 +27,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" + default = null + type = object({ + email = string + scopes = set(string) + }) description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/instance_template/additional_disks/versions.tf b/test/fixtures/instance_template/additional_disks/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/instance_template/additional_disks/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/instance_template/simple/main.tf b/test/fixtures/instance_template/simple/main.tf index ff704e15..8c249199 100644 --- a/test/fixtures/instance_template/simple/main.tf +++ b/test/fixtures/instance_template/simple/main.tf @@ -20,14 +20,15 @@ locals { module "instance_template_simple" { source = "../../../../examples/instance_template/simple" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" - region = "${var.region}" - subnetwork = "${google_compute_subnetwork.main.name}" - service_account = "${var.service_account}" + credentials_path = local.credentials_path + project_id = var.project_id + region = var.region + subnetwork = google_compute_subnetwork.main.name + service_account = var.service_account tags = ["foo", "bar"] labels = { environment = "dev" } } + diff --git a/test/fixtures/instance_template/simple/outputs.tf b/test/fixtures/instance_template/simple/outputs.tf index 44b261d5..fa8e0db1 100644 --- a/test/fixtures/instance_template/simple/outputs.tf +++ b/test/fixtures/instance_template/simple/outputs.tf @@ -16,20 +16,21 @@ output "self_link" { description = "Self-link to instance template" - value = "${module.instance_template_simple.self_link}" + value = module.instance_template_simple.self_link } output "name" { description = "Name of instance template" - value = "${module.instance_template_simple.name}" + value = module.instance_template_simple.name } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/instance_template/simple/variables.tf b/test/fixtures/instance_template/simple/variables.tf index 4a02862e..5043c27a 100644 --- a/test/fixtures/instance_template/simple/variables.tf +++ b/test/fixtures/instance_template/simple/variables.tf @@ -27,6 +27,10 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." + default = null + type = object({ + email = string + scopes = list(string) + }) } + diff --git a/test/fixtures/instance_template/simple/versions.tf b/test/fixtures/instance_template/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/instance_template/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/mig/autoscaler/main.tf b/test/fixtures/mig/autoscaler/main.tf index 0d5cdcbc..520be8d2 100644 --- a/test/fixtures/mig/autoscaler/main.tf +++ b/test/fixtures/mig/autoscaler/main.tf @@ -20,15 +20,18 @@ locals { module "mig_autoscaler" { source = "../../../../examples/mig/autoscaler" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" - region = "${var.region}" - subnetwork = "${google_compute_subnetwork.main.name}" - service_account = "${var.service_account}" + credentials_path = local.credentials_path + project_id = var.project_id + region = var.region + subnetwork = google_compute_subnetwork.main.name + service_account = var.service_account autoscaling_enabled = "true" min_replicas = 4 - autoscaling_cpu = [{ - target = 0.6 - }] + autoscaling_cpu = [ + { + target = 0.6 + }, + ] } + diff --git a/test/fixtures/mig/autoscaler/outputs.tf b/test/fixtures/mig/autoscaler/outputs.tf index c2c0ba26..03bf6a41 100644 --- a/test/fixtures/mig/autoscaler/outputs.tf +++ b/test/fixtures/mig/autoscaler/outputs.tf @@ -16,15 +16,16 @@ output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "region" { description = "The GCP region to create and test resources in" - value = "${var.region}" + value = var.region } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/mig/autoscaler/variables.tf b/test/fixtures/mig/autoscaler/variables.tf index 6a893373..49c6e021 100644 --- a/test/fixtures/mig/autoscaler/variables.tf +++ b/test/fixtures/mig/autoscaler/variables.tf @@ -27,6 +27,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/mig/autoscaler/versions.tf b/test/fixtures/mig/autoscaler/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/mig/autoscaler/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/mig/simple/main.tf b/test/fixtures/mig/simple/main.tf index 671cc0dc..a76dedc2 100644 --- a/test/fixtures/mig/simple/main.tf +++ b/test/fixtures/mig/simple/main.tf @@ -20,10 +20,11 @@ locals { module "mig_simple" { source = "../../../../examples/mig/simple" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" - region = "${var.region}" - subnetwork = "${google_compute_subnetwork.main.name}" + credentials_path = local.credentials_path + project_id = var.project_id + region = var.region + subnetwork = google_compute_subnetwork.main.name target_size = 4 - service_account = "${var.service_account}" + service_account = var.service_account } + diff --git a/test/fixtures/mig/simple/outputs.tf b/test/fixtures/mig/simple/outputs.tf index 3f2bb486..7f9b0ef5 100644 --- a/test/fixtures/mig/simple/outputs.tf +++ b/test/fixtures/mig/simple/outputs.tf @@ -16,20 +16,21 @@ output "mig_self_link" { description = "Self-link to managed instance group" - value = "${module.mig_simple.self_link}" + value = module.mig_simple.self_link } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "region" { description = "The GCP region to create and test resources in" - value = "${var.region}" + value = var.region } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/mig/simple/variables.tf b/test/fixtures/mig/simple/variables.tf index 6a893373..49c6e021 100644 --- a/test/fixtures/mig/simple/variables.tf +++ b/test/fixtures/mig/simple/variables.tf @@ -27,6 +27,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/mig/simple/versions.tf b/test/fixtures/mig/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/mig/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/shared/network.tf b/test/fixtures/shared/network.tf index faf87b4e..2c8f0e15 100644 --- a/test/fixtures/shared/network.tf +++ b/test/fixtures/shared/network.tf @@ -21,15 +21,16 @@ resource "random_string" "suffix" { } resource "google_compute_network" "main" { - project = "${var.project_id}" + project = var.project_id name = "cft-vm-test-${random_string.suffix.result}" auto_create_subnetworks = "false" } resource "google_compute_subnetwork" "main" { - project = "${var.project_id}" + project = var.project_id region = "us-central1" name = "cft-vm-test-${random_string.suffix.result}" ip_cidr_range = "10.128.0.0/20" - network = "${google_compute_network.main.self_link}" + network = google_compute_network.main.self_link } + diff --git a/test/fixtures/umig/named_ports/main.tf b/test/fixtures/umig/named_ports/main.tf index 076e15a5..67a7fb97 100644 --- a/test/fixtures/umig/named_ports/main.tf +++ b/test/fixtures/umig/named_ports/main.tf @@ -20,12 +20,12 @@ locals { module "umig_named_ports" { source = "../../../../examples/umig/named_ports" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" + credentials_path = local.credentials_path + project_id = var.project_id region = "us-central1" - subnetwork = "${google_compute_subnetwork.main.name}" + subnetwork = google_compute_subnetwork.main.name num_instances = 4 - service_account = "${var.service_account}" + service_account = var.service_account named_ports = [ { @@ -38,3 +38,4 @@ module "umig_named_ports" { }, ] } + diff --git a/test/fixtures/umig/named_ports/outputs.tf b/test/fixtures/umig/named_ports/outputs.tf index 3387df74..b0771ecd 100644 --- a/test/fixtures/umig/named_ports/outputs.tf +++ b/test/fixtures/umig/named_ports/outputs.tf @@ -16,20 +16,21 @@ output "self_links" { description = "List of self-links to unmanaged instance groups" - value = "${module.umig_named_ports.self_links}" + value = module.umig_named_ports.self_links } output "instances_self_links" { description = "List of instance self-links" - value = "${module.umig_named_ports.instances_self_links}" + value = module.umig_named_ports.instances_self_links } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/umig/named_ports/variables.tf b/test/fixtures/umig/named_ports/variables.tf index 59ac0fd0..73aa9f93 100644 --- a/test/fixtures/umig/named_ports/variables.tf +++ b/test/fixtures/umig/named_ports/variables.tf @@ -23,6 +23,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/umig/named_ports/versions.tf b/test/fixtures/umig/named_ports/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/umig/named_ports/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/umig/simple/main.tf b/test/fixtures/umig/simple/main.tf index e63358a4..a4cb2074 100644 --- a/test/fixtures/umig/simple/main.tf +++ b/test/fixtures/umig/simple/main.tf @@ -20,10 +20,11 @@ locals { module "umig_simple" { source = "../../../../examples/umig/simple" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" + credentials_path = local.credentials_path + project_id = var.project_id region = "us-central1" - subnetwork = "${google_compute_subnetwork.main.name}" + subnetwork = google_compute_subnetwork.main.name num_instances = 4 - service_account = "${var.service_account}" + service_account = var.service_account } + diff --git a/test/fixtures/umig/simple/outputs.tf b/test/fixtures/umig/simple/outputs.tf index 6325677c..b4597339 100644 --- a/test/fixtures/umig/simple/outputs.tf +++ b/test/fixtures/umig/simple/outputs.tf @@ -16,20 +16,21 @@ output "self_links" { description = "List of self-links to unmanaged instance groups" - value = "${module.umig_simple.self_links}" + value = module.umig_simple.self_links } output "instances_self_links" { description = "List of instance self-links" - value = "${module.umig_simple.instances_self_links}" + value = module.umig_simple.instances_self_links } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/umig/simple/variables.tf b/test/fixtures/umig/simple/variables.tf index 59ac0fd0..6f1de984 100644 --- a/test/fixtures/umig/simple/variables.tf +++ b/test/fixtures/umig/simple/variables.tf @@ -23,6 +23,10 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" -} + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." +} \ No newline at end of file diff --git a/test/fixtures/umig/simple/versions.tf b/test/fixtures/umig/simple/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/umig/simple/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/fixtures/umig/static_ips/main.tf b/test/fixtures/umig/static_ips/main.tf index bdcaf3f3..20bdceac 100644 --- a/test/fixtures/umig/static_ips/main.tf +++ b/test/fixtures/umig/static_ips/main.tf @@ -20,10 +20,10 @@ locals { module "umig_static_ips" { source = "../../../../examples/umig/static_ips" - credentials_path = "${local.credentials_path}" - project_id = "${var.project_id}" + credentials_path = local.credentials_path + project_id = var.project_id region = "us-central1" - subnetwork = "${google_compute_subnetwork.main.name}" + subnetwork = google_compute_subnetwork.main.name static_ips = [ "10.128.0.10", @@ -32,5 +32,6 @@ module "umig_static_ips" { "10.128.0.13", ] - service_account = "${var.service_account}" + service_account = var.service_account } + diff --git a/test/fixtures/umig/static_ips/outputs.tf b/test/fixtures/umig/static_ips/outputs.tf index 86106417..8036660a 100644 --- a/test/fixtures/umig/static_ips/outputs.tf +++ b/test/fixtures/umig/static_ips/outputs.tf @@ -16,20 +16,21 @@ output "self_links" { description = "List of self-links to unmanaged instance groups" - value = "${module.umig_static_ips.self_links}" + value = module.umig_static_ips.self_links } output "instances_self_links" { description = "List of instance self-links" - value = "${module.umig_static_ips.instances_self_links}" + value = module.umig_static_ips.instances_self_links } output "project_id" { description = "The GCP project to use for integration tests" - value = "${var.project_id}" + value = var.project_id } output "credentials_path" { description = "The path to the GCP credentials JSON file" - value = "${local.credentials_path}" + value = local.credentials_path } + diff --git a/test/fixtures/umig/static_ips/variables.tf b/test/fixtures/umig/static_ips/variables.tf index 59ac0fd0..73aa9f93 100644 --- a/test/fixtures/umig/static_ips/variables.tf +++ b/test/fixtures/umig/static_ips/variables.tf @@ -23,6 +23,11 @@ variable "credentials_path_relative" { } variable "service_account" { - type = "map" - description = "Service account email address and scopes" + default = null + type = object({ + email = string + scopes = set(string) + }) + description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." } + diff --git a/test/fixtures/umig/static_ips/versions.tf b/test/fixtures/umig/static_ips/versions.tf new file mode 100644 index 00000000..832ec1df --- /dev/null +++ b/test/fixtures/umig/static_ips/versions.tf @@ -0,0 +1,19 @@ +/** + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +terraform { + required_version = ">= 0.12" +} diff --git a/test/make.sh b/test/make.sh index b7746ed8..860fe37c 100644 --- a/test/make.sh +++ b/test/make.sh @@ -36,21 +36,14 @@ function basefiles() { test -f README.md || echo "Missing README.md" } -# This function runs the hadolint linter on -# every file named 'Dockerfile' -function docker() { - echo "Running hadolint on Dockerfiles" - find . -name "Dockerfile" -exec hadolint {} \; -} - # This function runs 'terraform validate' against all # files ending in '.tf' function check_terraform() { echo "Running terraform validate" #shellcheck disable=SC2156 - find . -name "*.tf" -not -path "./test/fixtures/shared/*" -not -path "./test/fixtures/all_examples/*" -exec bash -c 'terraform validate --check-variables=false $(dirname "{}")' \; + find . -name "*.tf" -not -path "./test/fixtures/shared/*" -not -path "./test/fixtures/all_examples/*" -exec bash -c 'cd $(dirname "{}") && terraform init && terraform validate ' \; echo "Running terraform fmt" - terraform fmt -check=true -write=false + find . -type f -name "*.tf" -exec terraform fmt -check=true -write=false {} \; } # This function runs 'go fmt' and 'go vet' on every file diff --git a/test/verify_boilerplate.pyc b/test/verify_boilerplate.pyc index 21726a03943ee2d58bb3c26e515fdb34e4227486..b607a357bf9b85509af6faf3f004b0cb364e31d8 100644 GIT binary patch delta 438 zcmccb_S}_&`7`-d e-oGwoLzLwPoAc$|h*J5IC?^6#lV!4&vMB(;_nCqK delta 550 zcmaFvdf$zM`7sZMh+Vmop1&Q2K~_D)S_bj;>_IqyyATQ^nCr|qGbK_%#w`K zB)#PPT>avFu-xSPvId){u#_>At}BXT0xRjdtoU9qlB!F8bD_X>l3l1jdAi7QQmr!B i+$Xw}j38{5vLVfZoA1k#5$KbbD()oNOOw|rSponYmBrZr