Skip to content

Commit d4e0e87

Browse files
feat: add suffix separator variable (#218)
* Add hostname_suffix_separator variable in compute_instance module * Add hostname_suffix_separator variable in umig module * Update READMEs * Set service account data instead of passing null since it will fail due to dynamic block in the instance template module * Update code to match tests and fix a bug in a specific test * chore: serial init for build * Revert "Set service account data instead of passing null since it will fail due to dynamic block in the instance template module" This reverts commit 80f9276. * Update modules/umig/README.md Co-authored-by: Bharath KKB <[email protected]> * Fix typo Co-authored-by: bharathkkb <[email protected]>
1 parent 75dda37 commit d4e0e87

File tree

8 files changed

+19
-4
lines changed

8 files changed

+19
-4
lines changed

examples/mig/healthcheck/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ module "mig" {
6464
project_id = var.project_id
6565
instance_template = module.instance_template.self_link
6666
region = var.region
67-
autoscaling_enabled = "true"
67+
autoscaling_enabled = true
6868
min_replicas = 2
6969
autoscaler_name = "mig-as"
70+
hostname = "mig-as"
7071

7172
autoscaling_cpu = [
7273
{

modules/compute_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
1818
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | no |
1919
| add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no |
2020
| hostname | Hostname of instances | `string` | `""` | no |
21+
| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no |
2122
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
2223
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
2324
| num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no |

modules/compute_instance/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data "google_compute_zones" "available" {
4141
resource "google_compute_instance_from_template" "compute_instance" {
4242
provider = google
4343
count = local.num_instances
44-
name = var.add_hostname_suffix ? "${local.hostname}-${format("%03d", count.index + 1)}" : local.hostname
44+
name = var.add_hostname_suffix ? format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) : local.hostname
4545
project = local.project_id
4646
zone = var.zone == null ? data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)] : var.zone
4747

modules/compute_instance/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ variable "zone" {
7474
description = "Zone where the instances should be created. If not specified, instances will be spread across available zones in the region."
7575
default = null
7676
}
77+
78+
variable "hostname_suffix_separator" {
79+
type = string
80+
description = "Separator character to compose hostname when add_hostname_suffix is set to true."
81+
default = "-"
82+
}

modules/umig/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
1818
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(list(object({<br> nat_ip = string<br> network_tier = string<br> })))</pre> | `[]` | no |
1919
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
2020
| hostname | Hostname of instances | `string` | `""` | no |
21+
| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no |
2122
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
2223
| named\_ports | Named name and named port | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |
2324
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |

modules/umig/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ data "google_compute_zones" "available" {
4646
resource "google_compute_instance_from_template" "compute_instance" {
4747
provider = google
4848
count = local.num_instances
49-
name = "${local.hostname}-${format("%03d", count.index + 1)}"
49+
name = format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1))
5050
project = var.project_id
5151
zone = data.google_compute_zones.available.names[count.index % length(data.google_compute_zones.available.names)]
5252

modules/umig/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ variable "access_config" {
9292
})))
9393
default = []
9494
}
95+
96+
variable "hostname_suffix_separator" {
97+
type = string
98+
description = "Separator character to compose hostname when add_hostname_suffix is set to true."
99+
default = "-"
100+
}

test/integration/mig_healthcheck/controls/mig_healthcheck.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134

135135
describe "https health check settings" do
136136
it "checkIntervalSec should be 5" do
137-
expect(data[0]['healthyThreshold']).to eq(5)
137+
expect(data[0]['checkIntervalSec']).to eq(5)
138138
end
139139
end
140140

0 commit comments

Comments
 (0)