|
| 1 | +--- |
| 2 | +subcategory: "Autoscaling" |
| 3 | +page_title: "Scaleway: scaleway_autoscaling_instance_group" |
| 4 | +--- |
| 5 | + |
| 6 | +# Resource: scaleway_autoscaling_instance_group |
| 7 | + |
| 8 | +Books and manages Autoscaling Instance groups. |
| 9 | + |
| 10 | +## Example Usage |
| 11 | + |
| 12 | +### Basic |
| 13 | + |
| 14 | +```terraform |
| 15 | +resource "scaleway_autoscaling_instance_group" "main" { |
| 16 | + name = "asg-group" |
| 17 | + template_id = scaleway_autoscaling_instance_template.main.id |
| 18 | + tags = ["terraform-test", "instance-group"] |
| 19 | + capacity { |
| 20 | + max_replicas = 5 |
| 21 | + min_replicas = 1 |
| 22 | + cooldown_delay = "300" |
| 23 | + } |
| 24 | + load_balancer { |
| 25 | + id = scaleway_lb.main.id |
| 26 | + backend_ids = [scaleway_lb_backend.main.id] |
| 27 | + private_network_id = scaleway_vpc_private_network.main.id |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +### With template and policies |
| 33 | + |
| 34 | +```terraform |
| 35 | +resource "scaleway_vpc" "main" { |
| 36 | + name = "TestAccAutoscalingVPC" |
| 37 | +} |
| 38 | +
|
| 39 | +resource "scaleway_vpc_private_network" "main" { |
| 40 | + name = "TestAccAutoscalingVPC" |
| 41 | + vpc_id = scaleway_vpc.main.id |
| 42 | +} |
| 43 | +
|
| 44 | +resource "scaleway_block_volume" "main" { |
| 45 | + iops = 5000 |
| 46 | + size_in_gb = 10 |
| 47 | +} |
| 48 | +
|
| 49 | +resource "scaleway_block_snapshot" "main" { |
| 50 | + name = "test-ds-block-snapshot-basic" |
| 51 | + volume_id = scaleway_block_volume.main.id |
| 52 | +} |
| 53 | +
|
| 54 | +resource "scaleway_lb_ip" "main" {} |
| 55 | +resource "scaleway_lb" "main" { |
| 56 | + ip_id = scaleway_lb_ip.main.id |
| 57 | + name = "test-lb" |
| 58 | + type = "lb-s" |
| 59 | + private_network { |
| 60 | + private_network_id = scaleway_vpc_private_network.main.id |
| 61 | + } |
| 62 | +} |
| 63 | +
|
| 64 | +resource "scaleway_lb_backend" "main" { |
| 65 | + lb_id = scaleway_lb.main.id |
| 66 | + forward_protocol = "tcp" |
| 67 | + forward_port = 80 |
| 68 | + proxy_protocol = "none" |
| 69 | +} |
| 70 | +
|
| 71 | +resource "scaleway_autoscaling_instance_template" "main" { |
| 72 | + name = "autoscaling-instance-template-basic" |
| 73 | + commercial_type = "PLAY2-MICRO" |
| 74 | + tags = ["terraform-test", "basic"] |
| 75 | + volumes { |
| 76 | + name = "as-volume" |
| 77 | + volume_type = "sbs" |
| 78 | + boot = true |
| 79 | + from_snapshot { |
| 80 | + snapshot_id = scaleway_block_snapshot.main.id |
| 81 | + } |
| 82 | + perf_iops = 5000 |
| 83 | + } |
| 84 | + public_ips_v4_count = 1 |
| 85 | + private_network_ids = [scaleway_vpc_private_network.main.id] |
| 86 | +} |
| 87 | +
|
| 88 | +resource "scaleway_autoscaling_instance_group" "main" { |
| 89 | + name = "autoscaling-instance-group-basic" |
| 90 | + template_id = scaleway_autoscaling_instance_template.main.id |
| 91 | + tags = ["terraform-test", "instance-group"] |
| 92 | + capacity { |
| 93 | + max_replicas = 5 |
| 94 | + min_replicas = 1 |
| 95 | + cooldown_delay = "300" |
| 96 | + } |
| 97 | + load_balancer { |
| 98 | + id = scaleway_lb.main.id |
| 99 | + backend_ids = [scaleway_lb_backend.main.id] |
| 100 | + private_network_id = scaleway_vpc_private_network.main.id |
| 101 | + } |
| 102 | + delete_servers_on_destroy = true |
| 103 | +} |
| 104 | +
|
| 105 | +resource "scaleway_autoscaling_instance_policy" "up" { |
| 106 | + instance_group_id = scaleway_autoscaling_instance_group.main.id |
| 107 | + name = "scale-up-if-cpu-high" |
| 108 | + action = "scale_up" |
| 109 | + type = "flat_count" |
| 110 | + value = 1 |
| 111 | + priority = 1 |
| 112 | +
|
| 113 | + metric { |
| 114 | + name = "cpu scale up" |
| 115 | + managed_metric = "managed_metric_instance_cpu" |
| 116 | + operator = "operator_greater_than" |
| 117 | + aggregate = "aggregate_average" |
| 118 | + sampling_range_min = 5 |
| 119 | + threshold = 70 |
| 120 | + } |
| 121 | +} |
| 122 | +
|
| 123 | +resource "scaleway_autoscaling_instance_policy" "down" { |
| 124 | + instance_group_id = scaleway_autoscaling_instance_group.main.id |
| 125 | + name = "scale-down-if-cpu-low" |
| 126 | + action = "scale_down" |
| 127 | + type = "flat_count" |
| 128 | + value = 1 |
| 129 | + priority = 2 |
| 130 | +
|
| 131 | + metric { |
| 132 | + name = "cpu scale down" |
| 133 | + managed_metric = "managed_metric_instance_cpu" |
| 134 | + operator = "operator_less_than" |
| 135 | + aggregate = "aggregate_average" |
| 136 | + sampling_range_min = 5 |
| 137 | + threshold = 40 |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +## Argument Reference |
| 143 | + |
| 144 | +The following arguments are supported: |
| 145 | + |
| 146 | +- `template_id` - (Required) The ID of the Instance template to attach to the Instance group. |
| 147 | +- `tags` - (Optional) The tags associated with the Instance group. |
| 148 | +- `name` - (Optional) The Instance group name. |
| 149 | +- `capacity` - (Optional) The specification of the minimum and maximum replicas for the Instance group, and the cooldown interval between two scaling events. |
| 150 | + - `max_replicas` - The maximum count of Instances for the Instance group. |
| 151 | + - `min_replicas` - The minimum count of Instances for the Instance group. |
| 152 | + - `cooldown_delay` - Time (in seconds) after a scaling action during which requests to carry out a new scaling action will be denied. |
| 153 | +- `load_balancer` - (Optional) The specification of the Load Balancer to link to the Instance group. |
| 154 | + - `id` - The ID of the Load Balancer. |
| 155 | + - `backend_ids` - The Load Balancer backend IDs. |
| 156 | + - `private_network_id` - The ID of the Private Network attached to the Load Balancer. |
| 157 | +- `delete_servers_on_destroy` - (Optional) Whether to delete all instances in this group when the group is destroyed. Set to `true` to tear them down, `false` (the default) leaves them running. |
| 158 | +- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance group exists. |
| 159 | +- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance group is associated with. |
| 160 | + |
| 161 | +## Attributes Reference |
| 162 | + |
| 163 | +In addition to all arguments above, the following attributes are exported: |
| 164 | + |
| 165 | +- `id` - The ID of the Instance group. |
| 166 | +- `created_at` - Date and time of Instance group's creation (RFC 3339 format). |
| 167 | +- `updated_at` - Date and time of Instance group's last update (RFC 3339 format). |
| 168 | + |
| 169 | +~> **Important:** Autoscaling Instance group IDs are [zonal](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111` |
| 170 | + |
| 171 | +## Import |
| 172 | + |
| 173 | +Autoscaling Instance groups can be imported using `{zone}/{id}`, e.g. |
| 174 | + |
| 175 | +```bash |
| 176 | +terraform import scaleway_autoscaling_instance_group.main fr-par-1/11111111-1111-1111-1111-111111111111 |
| 177 | +``` |
0 commit comments