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

instance_termination_action must be set for compute-vm spot instances #778

Merged
merged 6 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

<!-- None < 2022-06-06 13:42:51+00:00 -->

- [[#774](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/774)] FAST: fix data-platform-dev folder in stage 03-data-platform ([sttomm](https://github.com/sttomm)) <!-- 2022-08-16 07:36:24+00:00 -->

### FAST
### FAST

- [[#770](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/770)] FAST: fix to move without `output_location` ([daisuky-jp](https://github.com/daisuky-jp)) <!-- 2022-08-07 07:00:27+00:00 -->
- [[#767](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/767)] Allow interpolating SAs in project factory subnet IAM bindings ([ludoo](https://github.com/ludoo)) <!-- 2022-08-04 08:39:28+00:00 -->
Expand Down Expand Up @@ -56,6 +55,7 @@ All notable changes to this project will be documented in this file.

### MODULES

- [[#778]](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/778) **incompatible change** Add support for instance_termination_action to `compute-vm`
- [[#727](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/727)] Fix `ip_range` variable description in `apigee-x-instance` module ([alexlo03](https://github.com/alexlo03)) <!-- 2022-08-11 07:55:39+00:00 -->
- [[#773](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/773)] **incompatible change:** Refactor Cloud Run module ([ludoo](https://github.com/ludoo)) <!-- 2022-08-09 12:06:30+00:00 -->
- [[#754](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/754)] Add support to a public access to cloudsql-instance ([alefmreis](https://github.com/alefmreis)) <!-- 2022-08-09 11:42:42+00:00 -->
Expand Down Expand Up @@ -94,7 +94,6 @@ All notable changes to this project will be documented in this file.
- [[#680](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/680)] Tools: fix `ValueError` raised in `check_names.py` when overlong names are detected ([27Bslash6](https://github.com/27Bslash6)) <!-- 2022-06-16 08:01:59+00:00 -->
- [[#672](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/672)] Module attribution and version updater tool, plus release automation ([rosmo](https://github.com/rosmo)) <!-- 2022-06-09 11:40:50+00:00 -->


## [16.0.0] - 2022-06-06

- add support for [Spot VMs](https://cloud.google.com/compute/docs/instances/spot) to `gke-nodepool` module
Expand Down Expand Up @@ -586,7 +585,6 @@ All notable changes to this project will be documented in this file.

- merge development branch with suite of new modules and end-to-end examples


<!-- markdown-link-check-disable -->
[Unreleased]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v16.0.0...HEAD
[16.0.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v15.0.0...v16.0.0
Expand Down Expand Up @@ -651,4 +649,4 @@ All notable changes to this project will be documented in this file.
[1.3.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v0.1...v1.0.0
[1.0.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v0.1...v1.0.0
7 changes: 4 additions & 3 deletions fast/stages/02-networking-nva/nva.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ module "nva-template-ew1" {
create_template = true
instance_type = "f1-micro"
options = {
allow_stopping_for_update = true
deletion_protection = false
spot = true
allow_stopping_for_update = true
deletion_protection = false
spot = true
spot_instance_termination_action = "STOP"
}
metadata = {
startup-script = templatefile(
Expand Down
8 changes: 8 additions & 0 deletions fast/stages/02-networking-nva/test-resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -73,6 +74,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -107,6 +109,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -139,6 +142,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -174,6 +178,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -207,6 +212,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -242,6 +248,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -275,6 +282,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down
3 changes: 3 additions & 0 deletions fast/stages/02-networking-peering/test-resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -72,6 +73,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -105,6 +107,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down
3 changes: 3 additions & 0 deletions fast/stages/02-networking-vpn/test-resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -72,6 +73,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down Expand Up @@ -105,6 +107,7 @@
# allow_stopping_for_update = true
# deletion_protection = false
# spot = true
# spot_instance_termination_action = "STOP"
# }
# metadata = {
# startup-script = <<EOF
Expand Down
21 changes: 11 additions & 10 deletions modules/compute-vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module "spot-vm-example" {
allow_stopping_for_update = true
deletion_protection = false
spot = true
spot_instance_termination_action = "STOP"
}
network_interfaces = [{
network = var.vpc.self_link
Expand Down Expand Up @@ -327,8 +328,8 @@ module "instance-group" {
|---|---|:---:|:---:|:---:|
| [name](variables.tf#L160) | Instance name. | <code>string</code> | ✓ | |
| [network_interfaces](variables.tf#L174) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list&#40;object&#40;&#123;&#10; nat &#61; bool&#10; network &#61; string&#10; subnetwork &#61; string&#10; addresses &#61; object&#40;&#123;&#10; internal &#61; string&#10; external &#61; string&#10; &#125;&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [project_id](variables.tf#L201) | Project id. | <code>string</code> | ✓ | |
| [zone](variables.tf#L260) | Compute zone. | <code>string</code> | ✓ | |
| [project_id](variables.tf#L209) | Project id. | <code>string</code> | ✓ | |
| [zone](variables.tf#L268) | Compute zone. | <code>string</code> | ✓ | |
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object&#40;&#123;&#10; mode &#61; string&#10; replica_zone &#61; string&#10; type &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; auto_delete &#61; true&#10; mode &#61; &#34;READ_WRITE&#34;&#10; replica_zone &#61; null&#10; type &#61; &#34;pd-balanced&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [attached_disks](variables.tf#L32) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list&#40;object&#40;&#123;&#10; name &#61; string&#10; size &#61; string&#10; source &#61; string&#10; source_type &#61; string&#10; options &#61; object&#40;&#123;&#10; mode &#61; string&#10; replica_zone &#61; string&#10; type &#61; string&#10; &#125;&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [boot_disk](variables.tf#L58) | Boot disk properties. | <code title="object&#40;&#123;&#10; image &#61; string&#10; size &#61; number&#10; type &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; image &#61; &#34;projects&#47;debian-cloud&#47;global&#47;images&#47;family&#47;debian-11&#34;&#10; type &#61; &#34;pd-balanced&#34;&#10; size &#61; 10&#10;&#125;">&#123;&#8230;&#125;</code> |
Expand All @@ -347,14 +348,14 @@ module "instance-group" {
| [metadata](variables.tf#L148) | Instance metadata. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> |
| [min_cpu_platform](variables.tf#L154) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
| [network_interface_options](variables.tf#L165) | Network interfaces extended options. The key is the index of the inteface to configure. The value is an object with alias_ips and nic_type. Set alias_ips or nic_type to null if you need only one of them. | <code title="map&#40;object&#40;&#123;&#10; alias_ips &#61; map&#40;string&#41;&#10; nic_type &#61; string&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [options](variables.tf#L187) | Instance options. | <code title="object&#40;&#123;&#10; allow_stopping_for_update &#61; bool&#10; deletion_protection &#61; bool&#10; spot &#61; bool&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; allow_stopping_for_update &#61; true&#10; deletion_protection &#61; false&#10; spot &#61; false&#10;&#125;">&#123;&#8230;&#125;</code> |
| [scratch_disks](variables.tf#L206) | Scratch disks configuration. | <code title="object&#40;&#123;&#10; count &#61; number&#10; interface &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; count &#61; 0&#10; interface &#61; &#34;NVME&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [service_account](variables.tf#L218) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
| [service_account_create](variables.tf#L224) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
| [service_account_scopes](variables.tf#L232) | Scopes applied to service account. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [shielded_config](variables.tf#L238) | Shielded VM configuration of the instances. | <code title="object&#40;&#123;&#10; enable_secure_boot &#61; bool&#10; enable_vtpm &#61; bool&#10; enable_integrity_monitoring &#61; bool&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [tag_bindings](variables.tf#L248) | Tag bindings for this instance, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
| [tags](variables.tf#L254) | Instance network tags for firewall rule targets. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [options](variables.tf#L187) | Instance options. | <code title="object&#40;&#123;&#10; allow_stopping_for_update &#61; bool&#10; deletion_protection &#61; bool&#10; spot &#61; bool&#10; spot_instance_termination_action &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; allow_stopping_for_update &#61; true&#10; deletion_protection &#61; false&#10; spot &#61; false&#10; spot_instance_termination_action &#61; null&#10;&#125;">&#123;&#8230;&#125;</code> |
| [scratch_disks](variables.tf#L214) | Scratch disks configuration. | <code title="object&#40;&#123;&#10; count &#61; number&#10; interface &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; count &#61; 0&#10; interface &#61; &#34;NVME&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [service_account](variables.tf#L226) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
| [service_account_create](variables.tf#L232) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
| [service_account_scopes](variables.tf#L240) | Scopes applied to service account. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [shielded_config](variables.tf#L246) | Shielded VM configuration of the instances. | <code title="object&#40;&#123;&#10; enable_secure_boot &#61; bool&#10; enable_vtpm &#61; bool&#10; enable_integrity_monitoring &#61; bool&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [tag_bindings](variables.tf#L256) | Tag bindings for this instance, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
| [tags](variables.tf#L262) | Instance network tags for firewall rule targets. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |

## Outputs

Expand Down
18 changes: 9 additions & 9 deletions modules/compute-vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ locals {
for k, v in local.attached_disks :
k => v if try(v.options.replica_zone, null) == null
}
network_interface_options = {
for i, v in var.network_interfaces : i => lookup(var.network_interface_options, i, {
alias_ips = null,
nic_type = null
})
}
on_host_maintenance = (
var.options.spot || var.confidential_compute
? "TERMINATE"
Expand Down Expand Up @@ -60,13 +66,7 @@ locals {
]
)
)

network_interface_options = {
for i, v in var.network_interfaces : i => lookup(var.network_interface_options, i, {
alias_ips = null,
nic_type = null
})
}
spot_instance_termination_action = var.options.spot ? coalesce(var.options.spot_instance_termination_action, "STOP") : null
}

resource "google_compute_disk" "disks" {
Expand Down Expand Up @@ -213,10 +213,10 @@ resource "google_compute_instance" "default" {

scheduling {
automatic_restart = !var.options.spot
instance_termination_action = local.spot_instance_termination_action
on_host_maintenance = local.on_host_maintenance
preemptible = var.options.spot
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
instance_termination_action = var.options.spot ? "STOP" : null
}

dynamic "scratch_disk" {
Expand Down Expand Up @@ -341,10 +341,10 @@ resource "google_compute_instance_template" "default" {

scheduling {
automatic_restart = !var.options.spot
instance_termination_action = local.spot_instance_termination_action
on_host_maintenance = local.on_host_maintenance
preemptible = var.options.spot
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
instance_termination_action = var.options.spot ? "STOP" : null
}

service_account {
Expand Down
20 changes: 14 additions & 6 deletions modules/compute-vm/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,22 @@ variable "network_interfaces" {
variable "options" {
description = "Instance options."
type = object({
allow_stopping_for_update = bool
deletion_protection = bool
spot = bool
allow_stopping_for_update = bool
deletion_protection = bool
spot = bool
spot_instance_termination_action = string
sruffilli marked this conversation as resolved.
Show resolved Hide resolved
})
default = {
allow_stopping_for_update = true
deletion_protection = false
spot = false
allow_stopping_for_update = true
deletion_protection = false
spot = false
spot_instance_termination_action = null
}
validation {
condition = (var.options.spot_instance_termination_action == null
||
contains(["STOP", "DELETE"], coalesce(var.options.spot_instance_termination_action, "1")))
error_message = "Allowed values for options.spot_instance_termination_action are 'STOP', 'DELETE' and null"
}
}

Expand Down