Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/suffix separator variable #218

Merged
merged 10 commits into from
Jan 5, 2022
2 changes: 1 addition & 1 deletion examples/compute_instance/disk_snapshot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module "instance_template" {
project_id = var.project_id
subnetwork = var.subnetwork
name_prefix = "instance-disk-snapshot"
service_account = null
service_account = { email = "", scopes = ["cloud-platform"] }

additional_disks = [
{
Expand Down
5 changes: 3 additions & 2 deletions examples/mig/healthcheck/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module "instance_template" {
source = "../../../modules/instance_template"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
service_account = null
service_account = { email = "", scopes = ["cloud-platform"] }
}

/** Instance Group within autoscale and health check **/
Expand All @@ -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 charactere 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 charactere 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 charactere to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no |
thiagonache marked this conversation as resolved.
Show resolved Hide resolved
| 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 charactere 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