Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
products:
- account
- applesilicon
- autoscaling
- az
- baremetal
- billing
Expand Down
177 changes: 177 additions & 0 deletions docs/resources/autoscaling_instance_group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
subcategory: "Autoscaling"
page_title: "Scaleway: scaleway_autoscaling_instance_group"
---

# Resource: scaleway_autoscaling_instance_group

Books and manages Autoscaling Instance groups.

## Example Usage

### Basic

```terraform
resource "scaleway_autoscaling_instance_group" "main" {
name = "asg-group"
template_id = scaleway_autoscaling_instance_template.main.id
tags = ["terraform-test", "instance-group"]
capacity {
max_replicas = 5
min_replicas = 1
cooldown_delay = "300"
}
load_balancer {
id = scaleway_lb.main.id
backend_ids = [scaleway_lb_backend.main.id]
private_network_id = scaleway_vpc_private_network.main.id
}
}
```

### With template and policies

```terraform
resource "scaleway_vpc" "main" {
name = "TestAccAutoscalingVPC"
}

resource "scaleway_vpc_private_network" "main" {
name = "TestAccAutoscalingVPC"
vpc_id = scaleway_vpc.main.id
}

resource "scaleway_block_volume" "main" {
iops = 5000
size_in_gb = 10
}

resource "scaleway_block_snapshot" "main" {
name = "test-ds-block-snapshot-basic"
volume_id = scaleway_block_volume.main.id
}

resource "scaleway_lb_ip" "main" {}
resource "scaleway_lb" "main" {
ip_id = scaleway_lb_ip.main.id
name = "test-lb"
type = "lb-s"
private_network {
private_network_id = scaleway_vpc_private_network.main.id
}
}

resource "scaleway_lb_backend" "main" {
lb_id = scaleway_lb.main.id
forward_protocol = "tcp"
forward_port = 80
proxy_protocol = "none"
}

resource "scaleway_autoscaling_instance_template" "main" {
name = "autoscaling-instance-template-basic"
commercial_type = "PLAY2-MICRO"
tags = ["terraform-test", "basic"]
volumes {
name = "as-volume"
volume_type = "sbs"
boot = true
from_snapshot {
snapshot_id = scaleway_block_snapshot.main.id
}
perf_iops = 5000
}
public_ips_v4_count = 1
private_network_ids = [scaleway_vpc_private_network.main.id]
}

resource "scaleway_autoscaling_instance_group" "main" {
name = "autoscaling-instance-group-basic"
template_id = scaleway_autoscaling_instance_template.main.id
tags = ["terraform-test", "instance-group"]
capacity {
max_replicas = 5
min_replicas = 1
cooldown_delay = "300"
}
load_balancer {
id = scaleway_lb.main.id
backend_ids = [scaleway_lb_backend.main.id]
private_network_id = scaleway_vpc_private_network.main.id
}
delete_servers_on_destroy = true
}

resource "scaleway_autoscaling_instance_policy" "up" {
instance_group_id = scaleway_autoscaling_instance_group.main.id
name = "scale-up-if-cpu-high"
action = "scale_up"
type = "flat_count"
value = 1
priority = 1

metric {
name = "cpu scale up"
managed_metric = "managed_metric_instance_cpu"
operator = "operator_greater_than"
aggregate = "aggregate_average"
sampling_range_min = 5
threshold = 70
}
}

resource "scaleway_autoscaling_instance_policy" "down" {
instance_group_id = scaleway_autoscaling_instance_group.main.id
name = "scale-down-if-cpu-low"
action = "scale_down"
type = "flat_count"
value = 1
priority = 2

metric {
name = "cpu scale down"
managed_metric = "managed_metric_instance_cpu"
operator = "operator_less_than"
aggregate = "aggregate_average"
sampling_range_min = 5
threshold = 40
}
}
```

## Argument Reference

The following arguments are supported:

- `template_id` - (Required) The ID of the Instance template to attach to the Instance group.
- `tags` - (Optional) The tags associated with the Instance group.
- `name` - (Optional) The Instance group name.
- `capacity` - (Optional) The specification of the minimum and maximum replicas for the Instance group, and the cooldown interval between two scaling events.
- `max_replicas` - The maximum count of Instances for the Instance group.
- `min_replicas` - The minimum count of Instances for the Instance group.
- `cooldown_delay` - Time (in seconds) after a scaling action during which requests to carry out a new scaling action will be denied.
- `load_balancer` - (Optional) The specification of the Load Balancer to link to the Instance group.
- `id` - The ID of the Load Balancer.
- `backend_ids` - The Load Balancer backend IDs.
- `private_network_id` - The ID of the Private Network attached to the Load Balancer.
- `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.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance group exists.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance group is associated with.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the Instance group.
- `created_at` - Date and time of Instance group's creation (RFC 3339 format).
- `updated_at` - Date and time of Instance group's last update (RFC 3339 format).

~> **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`

## Import

Autoscaling Instance groups can be imported using `{zone}/{id}`, e.g.

```bash
terraform import scaleway_autoscaling_instance_group.main fr-par-1/11111111-1111-1111-1111-111111111111
```
87 changes: 87 additions & 0 deletions docs/resources/autoscaling_instance_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
subcategory: "Autoscaling"
page_title: "Scaleway: scaleway_autoscaling_instance_policy"
---

# Resource: scaleway_autoscaling_instance_policy

Books and manages Autoscaling Instance policies.

## Example Usage

### Basic

```terraform
resource "scaleway_autoscaling_instance_policy" "up" {
instance_group_id = scaleway_autoscaling_instance_group.main.id
name = "scale-up-if-cpu-high"
action = "scale_up"
type = "flat_count"
value = 1
priority = 1

metric {
name = "cpu scale up"
managed_metric = "managed_metric_instance_cpu"
operator = "operator_greater_than"
aggregate = "aggregate_average"
sampling_range_min = 5
threshold = 70
}
}

resource "scaleway_autoscaling_instance_policy" "down" {
instance_group_id = scaleway_autoscaling_instance_group.main.id
name = "scale-down-if-cpu-low"
action = "scale_down"
type = "flat_count"
value = 1
priority = 2

metric {
name = "cpu scale down"
managed_metric = "managed_metric_instance_cpu"
operator = "operator_less_than"
aggregate = "aggregate_average"
sampling_range_min = 5
threshold = 40
}
}
```

## Argument Reference

The following arguments are supported:

- `instance_group_id` - (Required) The ID of the Instance group related to this policy.
- `name` - (Optional) The Instance policy name.
- `action` - (Required) The action to execute when the metric-based condition is met.
- `type` - (Required) How to use the number defined in `value` when determining by how many Instances to scale up/down.
- `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.
- `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.
- `metric` - (Optional) Cockpit metric to use when determining whether to trigger a scale up/down action.
- `name` - Name or description of the metric policy.
- `operator` - Operator used when comparing the threshold value of the chosen `metric` to the actual sampled and aggregated value.
- `aggregate` - How the values sampled for the `metric` should be aggregated.
- `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.
- `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
- `sampling_range_min` - The Interval of time, in minutes, during which metric is sampled.
- `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.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance policy exists.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance policy is associated with.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the Instance policy.

~> **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`

## Import

Autoscaling instance policies can be imported using `{zone}/{id}`, e.g.

```bash
terraform import scaleway_autoscaling_instance_policy.main fr-par-1/11111111-1111-1111-1111-111111111111
```
72 changes: 72 additions & 0 deletions docs/resources/autoscaling_instance_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
subcategory: "Autoscaling"
page_title: "Scaleway: scaleway_autoscaling_instance_template"
---

# Resource: scaleway_autoscaling_instance_template

Books and manages Autoscaling Instance templates.

## Example Usage

### Basic

```terraform
resource "scaleway_autoscaling_instance_template" "main" {
name = "asg-template"
commercial_type = "PLAY2-MICRO"
tags = ["terraform-test", "basic"]
volumes {
name = "as-volume"
volume_type = "sbs"
boot = true
from_snapshot {
snapshot_id = scaleway_block_snapshot.main.id
}
perf_iops = 5000
}
public_ips_v4_count = 1
private_network_ids = [scaleway_vpc_private_network.main.id]
}
```

## Argument Reference

The following arguments are supported:

- `commercial_type` - (Required) The name of Instance commercial type.
- `tags` - (Optional) The tags associated with the Instance template.
- `name` - (Optional) The Instance group template.
- `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.
- `volumes` - (Required) The template of Instance volume.
- `name` - The name of the volume.
- `perf_iops` - The maximum IO/s expected, according to the different options available in stock (`5000 | 15000`).
- `tags` - The list of tags assigned to the volume.
- `boot` - Force the Instance to boot on this volume.
- `volume_type` - The type of the volume.
- `security_group_id` - (Optional) The instance security group ID.
- `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.
- `public_ips_v4_count` - (Optional) The number of flexible IPv4 addresses to attach to the new Instance.
- `public_ips_v6_count` - (Optional) The number of flexible IPv6 addresses to attach to the new Instance.
- `private_network_ids` - (Optional) The private Network IDs to attach to the new Instance.
- `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.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Instance template exists.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the Instance template is associated with.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the Instance group.
- `created_at` - Date and time of Instance group's creation (RFC 3339 format).
- `updated_at` - Date and time of Instance group's last update (RFC 3339 format).

~> **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`

## Import

Autoscaling Instance templates can be imported using `{zone}/{id}`, e.g.

```bash
terraform import scaleway_autoscaling_instance_template.main fr-par-1/11111111-1111-1111-1111-111111111111
```
26 changes: 13 additions & 13 deletions internal/locality/regional/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ func NewID(region scw.Region, id string) ID {
}
}

func NewIDStrings(region scw.Region, ids []string) []string {
if ids == nil {
return nil
}

flattenedIDs := make([]string, len(ids))
for i, id := range ids {
flattenedIDs[i] = NewIDString(region, id)
}

return flattenedIDs
}

func (z ID) String() string {
return fmt.Sprintf("%s/%s", z.Region, z.ID)
}
Expand Down Expand Up @@ -68,16 +81,3 @@ func ParseID(regionalID string) (region scw.Region, id string, err error) {

return
}

func NewRegionalIDs(region scw.Region, ids []string) []string {
if ids == nil {
return nil
}

flattenedIDs := make([]string, len(ids))
for i, id := range ids {
flattenedIDs[i] = NewIDString(region, id)
}

return flattenedIDs
}
Loading
Loading