Skip to content

Commit

Permalink
feat: add suffix separator variable (#218)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
thiagonache and bharathkkb authored Jan 5, 2022
1 parent 75dda37 commit d4e0e87
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/mig/healthcheck/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
1 change: 1 addition & 0 deletions modules/compute_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | 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 |
Expand Down
2 changes: 1 addition & 1 deletion modules/compute_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions modules/compute_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "-"
}
1 change: 1 addition & 0 deletions modules/umig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>list(list(object({<br> nat_ip = string<br> network_tier = string<br> })))</pre> | `[]` | no |
| 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 |
| 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 | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/umig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
6 changes: 6 additions & 0 deletions modules/umig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "-"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d4e0e87

Please sign in to comment.