Skip to content

Commit 07970f9

Browse files
authored
feat(compute_instance): added a variable to add/remove the hostname suffix for compute instance submodule (#177)
* [compute_instance] adding an optional var to override the generated hostname * Removing override var and adding a var for the suffix
1 parent 85bfb4a commit 07970f9

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

modules/compute_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
1616
| Name | Description | Type | Default | Required |
1717
|------|-------------|------|---------|:--------:|
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 |
19+
| add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no |
1920
| hostname | Hostname of instances | `string` | `""` | no |
2021
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
2122
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | 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 = "${local.hostname}-${format("%03d", count.index + 1)}"
44+
name = var.add_hostname_suffix ? "${local.hostname}-${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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ variable "hostname" {
3434
default = ""
3535
}
3636

37+
variable "add_hostname_suffix" {
38+
description = "Adds a suffix to the hostname"
39+
default = true
40+
}
41+
3742
variable "static_ips" {
3843
type = list(string)
3944
description = "List of static IPs for VM instances"

0 commit comments

Comments
 (0)