diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index d54b5d5d..946f1e41 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -64,9 +64,10 @@ module "mig" { project_id = var.project_id instance_template = module.instance_template.self_link region = var.region - autoscaling_enabled = "true" + autoscaling_enabled = true min_replicas = 2 autoscaler_name = "mig-as" + hostname = "mig-as" autoscaling_cpu = [ { diff --git a/modules/compute_instance/README.md b/modules/compute_instance/README.md index 77d8b5af..4bfa7e7c 100644 --- a/modules/compute_instance/README.md +++ b/modules/compute_instance/README.md @@ -18,6 +18,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm | access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
list(object({| `[]` | no | | add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no | | hostname | Hostname of instances | `string` | `""` | no | +| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no | | instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes | | network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | | num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no | diff --git a/modules/compute_instance/main.tf b/modules/compute_instance/main.tf index df09b1ae..7d2e7e47 100644 --- a/modules/compute_instance/main.tf +++ b/modules/compute_instance/main.tf @@ -41,7 +41,7 @@ data "google_compute_zones" "available" { resource "google_compute_instance_from_template" "compute_instance" { provider = google count = local.num_instances - name = var.add_hostname_suffix ? "${local.hostname}-${format("%03d", count.index + 1)}" : local.hostname + name = var.add_hostname_suffix ? format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) : local.hostname project = local.project_id zone = var.zone == null ? data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] : var.zone diff --git a/modules/compute_instance/variables.tf b/modules/compute_instance/variables.tf index cb2e5a11..de8ed84f 100644 --- a/modules/compute_instance/variables.tf +++ b/modules/compute_instance/variables.tf @@ -74,3 +74,9 @@ variable "zone" { description = "Zone where the instances should be created. If not specified, instances will be spread across available zones in the region." default = null } + +variable "hostname_suffix_separator" { + type = string + description = "Separator character to compose hostname when add_hostname_suffix is set to true." + default = "-" +} diff --git a/modules/umig/README.md b/modules/umig/README.md index 34f8e38e..67bf0c8f 100644 --- a/modules/umig/README.md +++ b/modules/umig/README.md @@ -18,6 +18,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm | access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
nat_ip = string
network_tier = string
}))
list(list(object({| `[]` | no | | additional\_networks | Additional network interface details for GCE, if any. |
nat_ip = string
network_tier = string
})))
list(object({| `[]` | no | | hostname | Hostname of instances | `string` | `""` | no | +| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no | | instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes | | named\_ports | Named name and named port |
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
access_config = list(object({
nat_ip = string
network_tier = string
}))
}))
list(object({| `[]` | no | | network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | diff --git a/modules/umig/main.tf b/modules/umig/main.tf index 191135a3..a3a96e77 100644 --- a/modules/umig/main.tf +++ b/modules/umig/main.tf @@ -46,7 +46,7 @@ data "google_compute_zones" "available" { resource "google_compute_instance_from_template" "compute_instance" { provider = google count = local.num_instances - name = "${local.hostname}-${format("%03d", count.index + 1)}" + name = format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) project = var.project_id zone = data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] diff --git a/modules/umig/variables.tf b/modules/umig/variables.tf index e4d35054..7b18c17f 100644 --- a/modules/umig/variables.tf +++ b/modules/umig/variables.tf @@ -92,3 +92,9 @@ variable "access_config" { }))) default = [] } + +variable "hostname_suffix_separator" { + type = string + description = "Separator character to compose hostname when add_hostname_suffix is set to true." + default = "-" +} diff --git a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb index 27c732f2..5c089be7 100644 --- a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb +++ b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb @@ -134,7 +134,7 @@ describe "https health check settings" do it "checkIntervalSec should be 5" do - expect(data[0]['healthyThreshold']).to eq(5) + expect(data[0]['checkIntervalSec']).to eq(5) end end
name = string
port = number
}))