Skip to content

Commit 75a8baa

Browse files
authored
feat: Allow overriding MIG name (#142)
1 parent a53e140 commit 75a8baa

File tree

8 files changed

+20
-3
lines changed

8 files changed

+20
-3
lines changed

autogen/main.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resource "google_compute_region_instance_group_manager" "{{ module_name }}" {
5959
}
6060
{% endif %}
6161

62-
name = "${var.hostname}-{{ module_name_hr }}"
62+
name = var.mig_name == "default" ? "${var.hostname}-{{ module_name_hr }}" : var.mig_name
6363
region = var.region
6464
dynamic "named_port" {
6565
for_each = var.named_ports

autogen/variables.tf.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ variable "hostname" {
2727
default = "default"
2828
}
2929

30+
variable "mig_name" {
31+
description = "Managed instance group name. When set to `default`, name will be derived from var.hostname."
32+
default = "default"
33+
}
34+
3035
variable "region" {
3136
description = "The GCP region where the managed instance group resides."
3237
}

modules/mig/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The current version is 2.X. The following guides are available to assist with up
2828
| hostname | Hostname prefix for instances | `string` | `"default"` | no |
2929
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
3030
| max\_replicas | The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas. | `number` | `10` | no |
31+
| mig\_name | Managed instance group name. When set to `default`, name will be derived from var.hostname. | `string` | `"default"` | no |
3132
| mig\_timeouts | Times for creation, deleting and updating the MIG resources. Can be helpful when using wait\_for\_instances to allow a longer VM startup time. | <pre>object({<br> create = string<br> update = string<br> delete = string<br> })</pre> | <pre>{<br> "create": "5m",<br> "delete": "15m",<br> "update": "5m"<br>}</pre> | no |
3233
| min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `number` | `2` | no |
3334
| named\_ports | Named name and named port. https://cloud.google.com/load-balancing/docs/backend-service#named_ports | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |

modules/mig/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "google_compute_region_instance_group_manager" "mig" {
4343
instance_template = var.instance_template
4444
}
4545

46-
name = "${var.hostname}-mig"
46+
name = var.mig_name == "default" ? "${var.hostname}-mig" : var.mig_name
4747
region = var.region
4848
dynamic "named_port" {
4949
for_each = var.named_ports

modules/mig/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ variable "hostname" {
2727
default = "default"
2828
}
2929

30+
variable "mig_name" {
31+
description = "Managed instance group name. When set to `default`, name will be derived from var.hostname."
32+
default = "default"
33+
}
34+
3035
variable "region" {
3136
description = "The GCP region where the managed instance group resides."
3237
}

modules/mig_with_percent/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The current version is 2.X. The following guides are available to assist with up
2828
| instance\_template\_initial\_version | Instance template self\_link used to create compute instances for the initial version | `any` | n/a | yes |
2929
| instance\_template\_next\_version | Instance template self\_link used to create compute instances for the second version | `any` | n/a | yes |
3030
| max\_replicas | The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas. | `number` | `10` | no |
31+
| mig\_name | Managed instance group name. When set to `default`, name will be derived from var.hostname. | `string` | `"default"` | no |
3132
| mig\_timeouts | Times for creation, deleting and updating the MIG resources. Can be helpful when using wait\_for\_instances to allow a longer VM startup time. | <pre>object({<br> create = string<br> update = string<br> delete = string<br> })</pre> | <pre>{<br> "create": "5m",<br> "delete": "15m",<br> "update": "5m"<br>}</pre> | no |
3233
| min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `number` | `2` | no |
3334
| named\_ports | Named name and named port. https://cloud.google.com/load-balancing/docs/backend-service#named_ports | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |

modules/mig_with_percent/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ resource "google_compute_region_instance_group_manager" "mig_with_percent" {
5252
}
5353
}
5454

55-
name = "${var.hostname}-mig-with-percent"
55+
name = var.mig_name == "default" ? "${var.hostname}-mig-with-percent" : var.mig_name
5656
region = var.region
5757
dynamic "named_port" {
5858
for_each = var.named_ports

modules/mig_with_percent/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ variable "hostname" {
2727
default = "default"
2828
}
2929

30+
variable "mig_name" {
31+
description = "Managed instance group name. When set to `default`, name will be derived from var.hostname."
32+
default = "default"
33+
}
34+
3035
variable "region" {
3136
description = "The GCP region where the managed instance group resides."
3237
}

0 commit comments

Comments
 (0)