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(TPG>=5.5)!: support setting maintenance_interval in instance_template #357

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/umig/named_ports/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "instance_template" {
source = "terraform-google-modules/vm/google//modules/instance_template"
version = "~> 10.0"

project_id = var.project_id
subnetwork = var.subnetwork
service_account = var.service_account
}
Expand Down
1 change: 1 addition & 0 deletions examples/umig/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "instance_template" {
source = "terraform-google-modules/vm/google//modules/instance_template"
version = "~> 10.0"

project_id = var.project_id
subnetwork = var.subnetwork
service_account = var.service_account
}
Expand Down
1 change: 1 addition & 0 deletions examples/umig/static_ips/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "instance_template" {
source = "terraform-google-modules/vm/google//modules/instance_template"
version = "~> 10.0"

project_id = var.project_id
subnetwork = var.subnetwork
service_account = var.service_account
}
Expand Down
1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
| ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | <pre>list(object({<br> network_tier = string<br> }))</pre> | `[]` | no |
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
| machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no |
| maintenance\_interval | Specifies the frequency of planned maintenance events | `string` | `null` | no |
| metadata | Metadata, provided as a map | `map(string)` | `{}` | no |
| min\_cpu\_platform | Specifies a minimum CPU platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell or Intel Skylake. See the complete list: https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform | `string` | `null` | no |
| name\_prefix | Name prefix for the instance template | `string` | `"default-instance-template"` | no |
Expand Down
6 changes: 4 additions & 2 deletions modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ locals {
# Instance Template
####################
resource "google_compute_instance_template" "tpl" {
provider = google-beta
name_prefix = "${var.name_prefix}-"
project = var.project_id
machine_type = var.machine_type
Expand Down Expand Up @@ -175,11 +176,12 @@ resource "google_compute_instance_template" "tpl" {
}

scheduling {
preemptible = local.preemptible
automatic_restart = local.automatic_restart
instance_termination_action = var.spot ? var.spot_instance_termination_action : null
maintenance_interval = var.maintenance_interval
on_host_maintenance = local.on_host_maintenance
preemptible = local.preemptible
provisioning_model = var.spot ? "SPOT" : null
instance_termination_action = var.spot ? var.spot_instance_termination_action : null
}

advanced_machine_features {
Expand Down
4 changes: 4 additions & 0 deletions modules/instance_template/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ spec:
description: Machine type to create, e.g. n1-standard-1
varType: string
defaultValue: n1-standard-1
- name: maintenance_interval
description: Specifies the frequency of planned maintenance events
varType: string
defaultValue: null
- name: metadata
description: Metadata, provided as a map
varType: map(string)
Expand Down
10 changes: 10 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ variable "automatic_restart" {
default = true
}

variable "maintenance_interval" {
type = string
description = "Specifies the frequency of planned maintenance events"
default = null
validation {
condition = var.maintenance_interval == null || var.maintenance_interval == "PERIODIC"
error_message = "var.maintenance_interval must be set to null or \"PERIODIC\""
}
}

variable "on_host_maintenance" {
type = string
description = "Instance availability Policy"
Expand Down
6 changes: 3 additions & 3 deletions modules/instance_template/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
terraform {
required_version = ">=0.13.0"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.67, < 6"
google-beta = {
source = "hashicorp/google-beta"
version = ">= 5.5, < 6"
}
}
provider_meta "google" {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/instance_template/additional_disks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "instance_template_additional_disks" {
source = "../../../../examples/instance_template/additional_disks"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
}

2 changes: 1 addition & 1 deletion test/fixtures/instance_template/alias_ip_range/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
module "instance_template_alias_ip_range" {
source = "../../../../examples/instance_template/alias_ip_range"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
}
2 changes: 1 addition & 1 deletion test/fixtures/instance_template/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "instance_template_simple" {
source = "../../../../examples/instance_template/simple"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
tags = ["foo", "bar"]

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mig/autoscaler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "mig_autoscaler" {
source = "../../../../examples/mig/autoscaler"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
autoscaling_enabled = "true"
min_replicas = 4
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mig/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "mig_simple" {
source = "../../../../examples/mig/simple"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
target_size = 4
service_account = var.service_account
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mig_stateful/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "mig_stateful" {
source = "../../../examples/mig_stateful"
project_id = var.project_id
region = "us-central1"
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
target_size = 3
service_account = var.service_account
}
2 changes: 1 addition & 1 deletion test/fixtures/mig_with_percent/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
module "mig_with_percent_simple" {
source = "../../../../examples/mig_with_percent/simple"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "preemptible_and_regular_instance_templates" {
source = "../../../../examples/preemptible_and_regular_instance_templates/simple"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
service_account = var.service_account
tags = ["foo", "bar"]

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/umig/named_ports/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "umig_named_ports" {
source = "../../../../examples/umig/named_ports"
project_id = var.project_id
region = "us-central1"
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
num_instances = 4
service_account = var.service_account

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/umig/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "umig_simple" {
source = "../../../../examples/umig/simple"
project_id = var.project_id
region = "us-central1"
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link
num_instances = 4
service_account = var.service_account
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/umig/static_ips/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "umig_static_ips" {
source = "../../../../examples/umig/static_ips"
project_id = var.project_id
region = "us-central1"
subnetwork = google_compute_subnetwork.main.name
subnetwork = google_compute_subnetwork.main.self_link

static_ips = [
"10.128.0.10",
Expand Down