Skip to content

Commit 280975a

Browse files
yfodilremyleone
andauthored
feat(autoscaling): add support for v1alpha1 (#3159)
* feat(autoscaling): add support for v1alpha1 * lint * lint * Fix format --------- Co-authored-by: Rémy Léone <[email protected]>
1 parent 13e7fad commit 280975a

25 files changed

+12196
-16
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
products:
1414
- account
1515
- applesilicon
16+
- autoscaling
1617
- az
1718
- baremetal
1819
- billing
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
```
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
subcategory: "Autoscaling"
3+
page_title: "Scaleway: scaleway_autoscaling_instance_policy"
4+
---
5+
6+
# Resource: scaleway_autoscaling_instance_policy
7+
8+
Books and manages Autoscaling Instance policies.
9+
10+
## Example Usage
11+
12+
### Basic
13+
14+
```terraform
15+
resource "scaleway_autoscaling_instance_policy" "up" {
16+
instance_group_id = scaleway_autoscaling_instance_group.main.id
17+
name = "scale-up-if-cpu-high"
18+
action = "scale_up"
19+
type = "flat_count"
20+
value = 1
21+
priority = 1
22+
23+
metric {
24+
name = "cpu scale up"
25+
managed_metric = "managed_metric_instance_cpu"
26+
operator = "operator_greater_than"
27+
aggregate = "aggregate_average"
28+
sampling_range_min = 5
29+
threshold = 70
30+
}
31+
}
32+
33+
resource "scaleway_autoscaling_instance_policy" "down" {
34+
instance_group_id = scaleway_autoscaling_instance_group.main.id
35+
name = "scale-down-if-cpu-low"
36+
action = "scale_down"
37+
type = "flat_count"
38+
value = 1
39+
priority = 2
40+
41+
metric {
42+
name = "cpu scale down"
43+
managed_metric = "managed_metric_instance_cpu"
44+
operator = "operator_less_than"
45+
aggregate = "aggregate_average"
46+
sampling_range_min = 5
47+
threshold = 40
48+
}
49+
}
50+
```
51+
52+
## Argument Reference
53+
54+
The following arguments are supported:
55+
56+
- `instance_group_id` - (Required) The ID of the Instance group related to this policy.
57+
- `name` - (Optional) The Instance policy name.
58+
- `action` - (Required) The action to execute when the metric-based condition is met.
59+
- `type` - (Required) How to use the number defined in `value` when determining by how many Instances to scale up/down.
60+
- `value` - (Required) The value representing the magnitude of the scaling action to take for the Instance group. Depending on the `type` parameter, this number could represent a total number of Instances in the group, a number of Instances to add, or a percentage to scale the group by.
61+
- `priority` - (Required) The priority of this policy compared to all other scaling policies. This determines the processing order. The lower the number, the higher the priority.
62+
- `metric` - (Optional) Cockpit metric to use when determining whether to trigger a scale up/down action.
63+
- `name` - Name or description of the metric policy.
64+
- `operator` - Operator used when comparing the threshold value of the chosen `metric` to the actual sampled and aggregated value.
65+
- `aggregate` - How the values sampled for the `metric` should be aggregated.
66+
- `managed_metric` - The managed metric to use for this policy. These are available by default in Cockpit without any configuration or `node_exporter`. The chosen metric forms the basis of the condition that will be checked to determine whether a scaling action should be triggered.
67+
- `cockpit_metric_name` - The custom metric to use for this policy. This must be stored in Scaleway Cockpit. The metric forms the basis of the condition that will be checked to determine whether a scaling action should be triggered
68+
- `sampling_range_min` - The Interval of time, in minutes, during which metric is sampled.
69+
- `threshold` - The threshold value to measure the aggregated sampled `metric` value against. Combined with the `operator` field, determines whether a scaling action should be triggered.
70+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance policy exists.
71+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance policy is associated with.
72+
73+
## Attributes Reference
74+
75+
In addition to all arguments above, the following attributes are exported:
76+
77+
- `id` - The ID of the Instance policy.
78+
79+
~> **Important:** Autoscaling policies 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`
80+
81+
## Import
82+
83+
Autoscaling instance policies can be imported using `{zone}/{id}`, e.g.
84+
85+
```bash
86+
terraform import scaleway_autoscaling_instance_policy.main fr-par-1/11111111-1111-1111-1111-111111111111
87+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
subcategory: "Autoscaling"
3+
page_title: "Scaleway: scaleway_autoscaling_instance_template"
4+
---
5+
6+
# Resource: scaleway_autoscaling_instance_template
7+
8+
Books and manages Autoscaling Instance templates.
9+
10+
## Example Usage
11+
12+
### Basic
13+
14+
```terraform
15+
resource "scaleway_autoscaling_instance_template" "main" {
16+
name = "asg-template"
17+
commercial_type = "PLAY2-MICRO"
18+
tags = ["terraform-test", "basic"]
19+
volumes {
20+
name = "as-volume"
21+
volume_type = "sbs"
22+
boot = true
23+
from_snapshot {
24+
snapshot_id = scaleway_block_snapshot.main.id
25+
}
26+
perf_iops = 5000
27+
}
28+
public_ips_v4_count = 1
29+
private_network_ids = [scaleway_vpc_private_network.main.id]
30+
}
31+
```
32+
33+
## Argument Reference
34+
35+
The following arguments are supported:
36+
37+
- `commercial_type` - (Required) The name of Instance commercial type.
38+
- `tags` - (Optional) The tags associated with the Instance template.
39+
- `name` - (Optional) The Instance group template.
40+
- `image_id` - (Optional) The instance image ID. Can be an ID of a marketplace or personal image. This image must be compatible with `volume` and `commercial_type` template.
41+
- `volumes` - (Required) The template of Instance volume.
42+
- `name` - The name of the volume.
43+
- `perf_iops` - The maximum IO/s expected, according to the different options available in stock (`5000 | 15000`).
44+
- `tags` - The list of tags assigned to the volume.
45+
- `boot` - Force the Instance to boot on this volume.
46+
- `volume_type` - The type of the volume.
47+
- `security_group_id` - (Optional) The instance security group ID.
48+
- `placement_group_id` - (Optional) The instance placement group ID. This is optional, but it is highly recommended to set a preference for Instance location within Availability Zone.
49+
- `public_ips_v4_count` - (Optional) The number of flexible IPv4 addresses to attach to the new Instance.
50+
- `public_ips_v6_count` - (Optional) The number of flexible IPv6 addresses to attach to the new Instance.
51+
- `private_network_ids` - (Optional) The private Network IDs to attach to the new Instance.
52+
- `cloud_init` - (Optional) The instance image ID. Can be an ID of a marketplace or personal image. This image must be compatible with `volume` and `commercial_type` template.
53+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance template exists.
54+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance template is associated with.
55+
56+
## Attributes Reference
57+
58+
In addition to all arguments above, the following attributes are exported:
59+
60+
- `id` - The ID of the Instance group.
61+
- `created_at` - Date and time of Instance group's creation (RFC 3339 format).
62+
- `updated_at` - Date and time of Instance group's last update (RFC 3339 format).
63+
64+
~> **Important:** Autoscaling Instance template 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`
65+
66+
## Import
67+
68+
Autoscaling Instance templates can be imported using `{zone}/{id}`, e.g.
69+
70+
```bash
71+
terraform import scaleway_autoscaling_instance_template.main fr-par-1/11111111-1111-1111-1111-111111111111
72+
```

internal/locality/regional/ids.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ func NewID(region scw.Region, id string) ID {
2121
}
2222
}
2323

24+
func NewIDStrings(region scw.Region, ids []string) []string {
25+
if ids == nil {
26+
return nil
27+
}
28+
29+
flattenedIDs := make([]string, len(ids))
30+
for i, id := range ids {
31+
flattenedIDs[i] = NewIDString(region, id)
32+
}
33+
34+
return flattenedIDs
35+
}
36+
2437
func (z ID) String() string {
2538
return fmt.Sprintf("%s/%s", z.Region, z.ID)
2639
}
@@ -68,16 +81,3 @@ func ParseID(regionalID string) (region scw.Region, id string, err error) {
6881

6982
return
7083
}
71-
72-
func NewRegionalIDs(region scw.Region, ids []string) []string {
73-
if ids == nil {
74-
return nil
75-
}
76-
77-
flattenedIDs := make([]string, len(ids))
78-
for i, id := range ids {
79-
flattenedIDs[i] = NewIDString(region, id)
80-
}
81-
82-
return flattenedIDs
83-
}

0 commit comments

Comments
 (0)