Skip to content

Commit

Permalink
feat(compute_instance): added a variable to add/remove the hostname s…
Browse files Browse the repository at this point in the history
…uffix 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
  • Loading branch information
jeenx authored May 26, 2021
1 parent 85bfb4a commit 07970f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/compute_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <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 |
| 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 |
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 = "${local.hostname}-${format("%03d", count.index + 1)}"
name = var.add_hostname_suffix ? "${local.hostname}-${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
5 changes: 5 additions & 0 deletions modules/compute_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ variable "hostname" {
default = ""
}

variable "add_hostname_suffix" {
description = "Adds a suffix to the hostname"
default = true
}

variable "static_ips" {
type = list(string)
description = "List of static IPs for VM instances"
Expand Down

0 comments on commit 07970f9

Please sign in to comment.