|
| 1 | +/** |
| 2 | +* Copyright 2024 Google LLC |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/** |
| 18 | +* Made to resemble: |
| 19 | +* gcloud compute instance-groups managed create flex-igm \ |
| 20 | +* --region us-central1 \ |
| 21 | +* --size 3 \ |
| 22 | +* --template example-template \ |
| 23 | +* --target-distribution-shape=any-single-zone \ |
| 24 | +* --instance-redistribution-type none \ |
| 25 | +* --instance-selection-machine-types "machine-type=n1-standard-16,n2-standard-16,e2-standard-16" |
| 26 | +*/ |
| 27 | + |
| 28 | +terraform { |
| 29 | + required_providers { |
| 30 | + google = { |
| 31 | + source = "hashicorp/google" |
| 32 | + version = ">= 6.13.0" |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +# [START compute_region_igm_instance_flexibility_policy_parent_tag] |
| 38 | +resource "google_compute_instance_template" "default" { |
| 39 | + name = "example-template" |
| 40 | + machine_type = "e2-medium" |
| 41 | + disk { |
| 42 | + source_image = "debian-cloud/debian-11" |
| 43 | + } |
| 44 | + network_interface { |
| 45 | + network = "default" |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +# [START compute_region_igm_instance_flexibility_policy] |
| 50 | +resource "google_compute_region_instance_group_manager" "default" { |
| 51 | + name = "flex-igm" |
| 52 | + base_instance_name = "tf-test-flex-igm" |
| 53 | + region = "us-central1" |
| 54 | + |
| 55 | + target_size = 3 |
| 56 | + distribution_policy_target_shape = "ANY_SINGLE_ZONE" |
| 57 | + |
| 58 | + version { |
| 59 | + instance_template = google_compute_instance_template.default.id |
| 60 | + } |
| 61 | + |
| 62 | + instance_flexibility_policy { |
| 63 | + instance_selections { |
| 64 | + name = "default-instance-selection" |
| 65 | + machine_types = ["n1-standard-16", "n2-standard-16", "e2-standard-16"] |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + update_policy { |
| 70 | + instance_redistribution_type = "NONE" |
| 71 | + type = "OPPORTUNISTIC" |
| 72 | + minimal_action = "REPLACE" |
| 73 | + max_surge_fixed = 0 |
| 74 | + max_unavailable_fixed = 6 |
| 75 | + } |
| 76 | +} |
| 77 | +# [END compute_region_igm_instance_flexibility_policy] |
| 78 | +# [END compute_region_igm_instance_flexibility_policy_parent_tag] |
0 commit comments