From b366344a412974d60056f4b94560a409bd0fbedb Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Mon, 9 Mar 2020 16:05:25 -0700 Subject: [PATCH] Add node group autoscaling policy (#3230) * Add node group autoscaling policy * add default_from_api * Update api.yaml --- products/compute/api.yaml | 32 +++++++++++++++++++ products/compute/terraform.yaml | 15 +++++++++ .../node_group_autoscaling_policy.tf.erb | 26 +++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 templates/terraform/examples/node_group_autoscaling_policy.tf.erb diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 902c269c3c7f..067cf36219d9 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -7358,6 +7358,38 @@ objects: The total number of nodes in the node group. required: true send_empty_value: true + - !ruby/object:Api::Type::NestedObject + name: 'autoscalingPolicy' + min_version: beta + description: | + If you use sole-tenant nodes for your workloads, you can use the node + group autoscaler to automatically manage the sizes of your node groups. + properties: + - !ruby/object:Api::Type::Enum + name: 'mode' + required: true + description: | + The autoscaling mode. Set to one of the following: + - OFF: Disables the autoscaler. + - ON: Enables scaling in and scaling out. + - ONLY_SCALE_OUT: Enables only scaling out. + You must use this mode if your node groups are configured to + restart their hosted VMs on minimal servers. + values: + - :OFF + - :ON + - :ONLY_SCALE_OUT + - !ruby/object:Api::Type::Integer + name: 'minNodes' + description: | + Minimum size of the node group. Must be less + than or equal to max-nodes. The default value is 0. + - !ruby/object:Api::Type::Integer + name: 'maxNodes' + description: | + Maximum size of the node group. Set to a value less than or equal + to 100 and greater than or equal to min-nodes. + required: true - !ruby/object:Api::Resource name: 'NetworkPeeringRoutesConfig' base_url: 'projects/{{project}}/global/networks/{{network}}' diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 1b61549fa4fd..cf88ed2a7281 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -1119,11 +1119,26 @@ overrides: !ruby/object:Overrides::ResourceOverrides vars: group_name: "soletenant-group" template_name: "soletenant-tmpl" + - !ruby/object:Provider::Terraform::Examples + name: "node_group_autoscaling_policy" + min_version: beta + primary_resource_id: "nodes" + vars: + group_name: "soletenant-group" + template_name: "soletenant-tmpl" properties: zone: !ruby/object:Overrides::Terraform::PropertyOverride required: false default_from_api: true custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' + autoscalingPolicy: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true + autoscalingPolicy.mode: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true + autoscalingPolicy.minNodes: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true + autoscalingPolicy.maxNodes: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true NodeTemplate: !ruby/object:Overrides::Terraform::ResourceOverride examples: - !ruby/object:Provider::Terraform::Examples diff --git a/templates/terraform/examples/node_group_autoscaling_policy.tf.erb b/templates/terraform/examples/node_group_autoscaling_policy.tf.erb new file mode 100644 index 000000000000..da1be0e9a3a8 --- /dev/null +++ b/templates/terraform/examples/node_group_autoscaling_policy.tf.erb @@ -0,0 +1,26 @@ +data "google_compute_node_types" "central1a" { + provider = google-beta + zone = "us-central1-a" +} + +resource "google_compute_node_template" "soletenant-tmpl" { + provider = google-beta + name = "<%= ctx[:vars]['template_name'] %>" + region = "us-central1" + node_type = data.google_compute_node_types.central1a.names[0] +} + +resource "google_compute_node_group" "<%= ctx[:primary_resource_id] %>" { + provider = google-beta + name = "<%= ctx[:vars]['group_name'] %>" + zone = "us-central1-a" + description = "example google_compute_node_group for Terraform Google Provider" + + size = 1 + node_template = google_compute_node_template.soletenant-tmpl.self_link + autoscaling_policy { + mode = "ON" + min_nodes = 1 + max_nodes = 10 + } +}