From 6d8a27959a25c7a22869bc2f06a164fdcd26f351 Mon Sep 17 00:00:00 2001 From: Luc Charpentier Date: Mon, 13 Oct 2025 17:21:12 +0200 Subject: [PATCH] feat(umig): add add_hostname_suffix variable to align hostname behavior with compute_instance module --- modules/umig/README.md | 1 + modules/umig/main.tf | 2 +- modules/umig/metadata.display.yaml | 3 +++ modules/umig/metadata.yaml | 4 ++++ modules/umig/variables.tf | 6 ++++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/umig/README.md b/modules/umig/README.md index 3cda1fa0..644badb5 100644 --- a/modules/umig/README.md +++ b/modules/umig/README.md @@ -16,6 +16,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
list(list(object({
nat_ip = string
network_tier = string
})))
| `[]` | no | +| add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no | | additional\_networks | Additional network interface details for GCE, if any. |
list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
access_config = list(object({
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
}))
| `[]` | 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 | diff --git a/modules/umig/main.tf b/modules/umig/main.tf index 20265c74..5dd04c5d 100644 --- a/modules/umig/main.tf +++ b/modules/umig/main.tf @@ -48,7 +48,7 @@ data "google_compute_zones" "available" { resource "google_compute_instance_from_template" "compute_instance" { provider = google count = local.num_instances - name = format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) + name = var.add_hostname_suffix ? format("%s%s%s", local.hostname, var.hostname_suffix_separator, format("%03d", count.index + 1)) : local.hostname project = var.project_id zone = local.zones[count.index % length(local.zones)] diff --git a/modules/umig/metadata.display.yaml b/modules/umig/metadata.display.yaml index 7ee9c3b1..1c464bc3 100644 --- a/modules/umig/metadata.display.yaml +++ b/modules/umig/metadata.display.yaml @@ -31,6 +31,9 @@ spec: access_config: name: access_config title: Access Config + add_hostname_suffix: + name: add_hostname_suffix + title: Add Hostname Suffix additional_networks: name: additional_networks title: Additional Networks diff --git a/modules/umig/metadata.yaml b/modules/umig/metadata.yaml index 288ac12a..735a1527 100644 --- a/modules/umig/metadata.yaml +++ b/modules/umig/metadata.yaml @@ -122,6 +122,10 @@ spec: description: Hostname of instances varType: string defaultValue: "" + - name: add_hostname_suffix + description: Adds a suffix to the hostname + varType: bool + defaultValue: true - name: static_ips description: List of static IPs for VM instances varType: list(string) diff --git a/modules/umig/variables.tf b/modules/umig/variables.tf index 4c056106..2c1ba05b 100644 --- a/modules/umig/variables.tf +++ b/modules/umig/variables.tf @@ -67,6 +67,12 @@ variable "hostname" { default = "" } +variable "add_hostname_suffix" { + description = "Adds a suffix to the hostname" + type = bool + default = true +} + variable "static_ips" { type = list(string) description = "List of static IPs for VM instances"