Skip to content

Commit

Permalink
feat: support setting maintenance_interval in instance_template
Browse files Browse the repository at this point in the history
  • Loading branch information
tpdownes committed Oct 24, 2023
1 parent d61838d commit 4a6f31f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
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
4 changes: 2 additions & 2 deletions modules/instance_template/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
terraform {
required_version = ">=0.13.0"
required_providers {
google = {
source = "hashicorp/google"
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.67, < 5.0"
}
}
Expand Down

0 comments on commit 4a6f31f

Please sign in to comment.