diff --git a/README.md b/README.md index 208945fe..0e48c413 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,20 @@ This is a collection of opinionated submodules that can be used as building bloc * [Unmanaged instance group](modules/umig) ## Compatibility -This module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+. If you find incompatibilities using Terraform >=0.13, please open an issue. - If you haven't -[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform +This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue. + +If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform 0.12.x-compatible version of this module, the last released version intended for Terraform 0.12.x is [v5.1.0](https://registry.terraform.io/modules/terraform-google-modules/-vm/google/v5.1.0). +Terraform compatibility: + +| Module Version | Terraform Version Required | +|-----------------------|----------------------------| +| >= 12.0.0 | >= 1.3.0 | +| >= 6.0.0 and < 12.0.0 | 0.13 or greater | +| <= 5.1.0 | 0.12 | + ## Examples Examples of how to use these modules can be found in the [examples](examples) folder. diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index 7589746a..52ebb3fe 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -145,19 +145,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" diff --git a/autogen/versions.tf.tmpl b/autogen/versions.tf.tmpl index 5464f589..ace24c91 100644 --- a/autogen/versions.tf.tmpl +++ b/autogen/versions.tf.tmpl @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index a252f364..35a72abe 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -97,3 +97,28 @@ module "mig" { enable_logging = false } } + +module "mig_health_check_optional_fields" { + source = "terraform-google-modules/vm/google//modules/mig" + version = "~> 11.0" + + project_id = var.project_id + instance_template = module.instance_template.self_link + region = var.region + autoscaling_enabled = true + min_replicas = 2 + autoscaler_name = "mig-as-optional-fields" + hostname = "mig-as-optional-fields" + + autoscaling_cpu = [ + { + target = 0.4 + predictive_method = null # use default of NONE + }, + ] + + health_check_name = "mig-http-hc" + health_check = { + type = "http" # use default port 80 and path / + } +} diff --git a/modules/mig/README.md b/modules/mig/README.md index 216bcaa3..2810fcd9 100644 --- a/modules/mig/README.md +++ b/modules/mig/README.md @@ -28,7 +28,7 @@ The current version is 2.X. The following guides are available to assist with up | cooldown\_period | The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. | `number` | `60` | no | | distribution\_policy\_target\_shape | MIG target distribution shape (EVEN, BALANCED, ANY, ANY\_SINGLE\_ZONE) | `string` | `null` | no | | distribution\_policy\_zones | The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region. | `list(string)` | `[]` | no | -| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = string
initial_delay_sec = number
check_interval_sec = number
healthy_threshold = number
timeout_sec = number
unhealthy_threshold = number
response = string
proxy_header = string
port = number
request = string
request_path = string
host = string
enable_logging = bool
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | +| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = optional(string, "")
initial_delay_sec = optional(number, 30)
check_interval_sec = optional(number, 30)
healthy_threshold = optional(number, 1)
timeout_sec = optional(number, 10)
unhealthy_threshold = optional(number, 5)
response = optional(string, "")
proxy_header = optional(string, "NONE")
port = optional(number, 80)
request = optional(string, "")
request_path = optional(string, "/")
host = optional(string, "")
enable_logging = optional(bool, false)
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | | health\_check\_name | Health check name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no | | hostname | Hostname prefix for instances | `string` | `"default"` | no | | instance\_template | Instance template self\_link used to create compute instances | `string` | n/a | yes | diff --git a/modules/mig/metadata.yaml b/modules/mig/metadata.yaml index b53348a7..9033a766 100644 --- a/modules/mig/metadata.yaml +++ b/modules/mig/metadata.yaml @@ -28,7 +28,7 @@ spec: version: 11.1.0 actuationTool: flavor: Terraform - version: ">=0.13.0" + version: ">=1.3.0" description: {} content: examples: @@ -133,19 +133,19 @@ spec: description: Health check to determine whether instances are responsive and able to do work varType: |- object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) defaultValue: check_interval_sec: 30 diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index e440ee2e..cfcffd80 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -127,19 +127,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" diff --git a/modules/mig/versions.tf b/modules/mig/versions.tf index 20c07d24..fbb10041 100644 --- a/modules/mig/versions.tf +++ b/modules/mig/versions.tf @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" diff --git a/modules/mig_with_percent/README.md b/modules/mig_with_percent/README.md index 5e10aec7..be680ad0 100644 --- a/modules/mig_with_percent/README.md +++ b/modules/mig_with_percent/README.md @@ -27,7 +27,7 @@ The current version is 2.X. The following guides are available to assist with up | cooldown\_period | The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. | `number` | `60` | no | | distribution\_policy\_target\_shape | MIG target distribution shape (EVEN, BALANCED, ANY, ANY\_SINGLE\_ZONE) | `string` | `null` | no | | distribution\_policy\_zones | The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region. | `list(string)` | `[]` | no | -| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = string
initial_delay_sec = number
check_interval_sec = number
healthy_threshold = number
timeout_sec = number
unhealthy_threshold = number
response = string
proxy_header = string
port = number
request = string
request_path = string
host = string
enable_logging = bool
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | +| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = optional(string, "")
initial_delay_sec = optional(number, 30)
check_interval_sec = optional(number, 30)
healthy_threshold = optional(number, 1)
timeout_sec = optional(number, 10)
unhealthy_threshold = optional(number, 5)
response = optional(string, "")
proxy_header = optional(string, "NONE")
port = optional(number, 80)
request = optional(string, "")
request_path = optional(string, "/")
host = optional(string, "")
enable_logging = optional(bool, false)
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | | health\_check\_name | Health check name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no | | hostname | Hostname prefix for instances | `string` | `"default"` | no | | instance\_template\_initial\_version | Instance template self\_link used to create compute instances for the initial version | `string` | n/a | yes | diff --git a/modules/mig_with_percent/metadata.yaml b/modules/mig_with_percent/metadata.yaml index e0fab86a..7946ae87 100644 --- a/modules/mig_with_percent/metadata.yaml +++ b/modules/mig_with_percent/metadata.yaml @@ -28,7 +28,7 @@ spec: version: 11.1.0 actuationTool: flavor: Terraform - version: ">=0.13.0" + version: ">=1.3.0" description: {} content: examples: @@ -133,19 +133,19 @@ spec: description: Health check to determine whether instances are responsive and able to do work varType: |- object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) defaultValue: check_interval_sec: 30 diff --git a/modules/mig_with_percent/variables.tf b/modules/mig_with_percent/variables.tf index 759cd9de..99f1f08f 100644 --- a/modules/mig_with_percent/variables.tf +++ b/modules/mig_with_percent/variables.tf @@ -137,19 +137,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" diff --git a/modules/mig_with_percent/versions.tf b/modules/mig_with_percent/versions.tf index 0b4c836e..50d2a6f5 100644 --- a/modules/mig_with_percent/versions.tf +++ b/modules/mig_with_percent/versions.tf @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" diff --git a/test/fixtures/mig/healthcheck/versions.tf b/test/fixtures/mig/healthcheck/versions.tf index fb3fee63..ad68a2c4 100644 --- a/test/fixtures/mig/healthcheck/versions.tf +++ b/test/fixtures/mig/healthcheck/versions.tf @@ -15,5 +15,5 @@ */ terraform { - required_version = ">=0.12.6" + required_version = ">=1.3.0" } diff --git a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb index 5c089be7..54170ca7 100644 --- a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb +++ b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb @@ -40,6 +40,25 @@ end end + describe command("gcloud --project=#{project_id} compute instances list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instances" do + it "should be #{expected_instances}" do + expect(data.length).to eq(expected_instances) + end + end + end + describe command("gcloud --project=#{project_id} compute instance-groups list --format=json --filter='name~^mig-as*'") do its(:exit_status) { should eq 0 } its(:stderr) { should eq '' } @@ -59,6 +78,25 @@ end end + describe command("gcloud --project=#{project_id} compute instance-groups list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instance groups" do + it "should be #{expected_instance_groups}" do + expect(data.length).to eq(expected_instance_groups) + end + end + end + describe command("gcloud --project=#{project_id} compute instance-groups managed list --format=json --filter='name~^mig-as*'") do its(:exit_status) { should eq 0 } its(:stderr) { should eq '' } @@ -84,7 +122,44 @@ end describe "autoscaler scaling policy" do - it "minNumReplicas should be 4" do + it "minNumReplicas should be 2" do + expect(data[0]['autoscaler']['autoscalingPolicy']['minNumReplicas']).to eq(2) + end + end + + describe "autoscaler scaling policy" do + it "cpuUtilization target should be 0.4" do + expect(data[0]['autoscaler']['autoscalingPolicy']['cpuUtilization']['utilizationTarget']).to eq(0.4) + end + end + end + + describe command("gcloud --project=#{project_id} compute instance-groups managed list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instance groups" do + it "should be #{expected_instance_groups}" do + expect(data.length).to eq(expected_instance_groups) + end + end + + describe "autoscaling" do + it "should be enabled" do + expect(data[0]['autoscaled']).to eq("yes") + end + end + + describe "autoscaler scaling policy" do + it "minNumReplicas should be 2" do expect(data[0]['autoscaler']['autoscalingPolicy']['minNumReplicas']).to eq(2) end end @@ -140,7 +215,56 @@ describe "https health check settings" do it "unhealthyThreshold should be 2" do - expect(data[0]['healthyThreshold']).to eq(2) + expect(data[0]['unhealthyThreshold']).to eq(2) + end + end + end + + describe command("gcloud --project=#{project_id} compute health-checks list --format=json --filter='name~^mig-http-hc*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "http health check settings" do + it "port should be 80" do + expect(data[0]['httpHealthCheck']['port']).to eq(80) + end + end + + describe "http health check settings" do + it "requestPath should be /" do + expect(data[0]['httpHealthCheck']['requestPath']).to eq('/') + end + end + + describe "http health check settings" do + it "proxyHeader should be NONE" do + expect(data[0]['httpHealthCheck']['proxyHeader']).to eq('NONE') + end + end + + describe "http health check settings" do + it "healthyThreshold should be 1" do + expect(data[0]['healthyThreshold']).to eq(1) + end + end + + describe "http health check settings" do + it "checkIntervalSec should be 30" do + expect(data[0]['checkIntervalSec']).to eq(30) + end + end + + describe "http health check settings" do + it "unhealthyThreshold should be 5" do + expect(data[0]['unhealthyThreshold']).to eq(5) end end end