Skip to content

Commit 6944441

Browse files
authored
fix: Add zone parameter to scaleway_instance_private_nic data source for multi-zone deployments (#72)
The scaleway_instance_private_nic data source was missing the zone parameter, which could cause issues when deploying instances across multiple zones. This fix ensures the private NIC data source uses the same zone as the instance. Signed-off-by: marc <[email protected]>
1 parent d9289e1 commit 6944441

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

examples/multi-zones/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Multi-Zones Instance Deployment Example
2+
3+
This example demonstrates how to deploy instances across multiple Scaleway availability zones using the `terraform-scaleway-instance` module.
4+
5+
## Overview
6+
7+
This configuration creates two instances in different availability zones (`fr-par-1` and `fr-par-2`) with their respective security groups. This example showcases the module's ability to handle multi-zone deployments correctly, particularly with the fix for the `scaleway_instance_private_nic` data source that now properly includes the zone parameter.
8+
9+
## Architecture
10+
11+
- **Instance 0**: Deployed in `fr-par-1` zone
12+
- **Instance 1**: Deployed in `fr-par-2` zone
13+
- **Security Groups**: One per zone to ensure proper network isolation
14+
- **Instance Type**: PLAY2-NANO (2 vCPU, 8GB RAM)
15+
- **Image**: Debian Bookworm
16+
17+
## Key Features
18+
19+
### Zone-Aware Configuration
20+
21+
The example uses a local configuration to define instances across zones:
22+
23+
```hcl
24+
locals {
25+
instances = {
26+
"0" = {
27+
name = "instance-0"
28+
zone = "fr-par-1"
29+
}
30+
"1" = {
31+
name = "instance-1"
32+
zone = "fr-par-2"
33+
}
34+
}
35+
}
36+
```
37+
38+
### Dynamic Security Group Creation
39+
40+
Security groups are created dynamically for each unique zone:
41+
42+
```hcl
43+
resource "scaleway_instance_security_group" "instances_security_group" {
44+
for_each = local.unique_zones
45+
46+
zone = each.value
47+
# ... other configuration
48+
}
49+
```
50+
51+
## Usage
52+
53+
1. Initialize Terraform:
54+
```bash
55+
terraform init
56+
```
57+
58+
2. Plan the deployment:
59+
```bash
60+
terraform plan
61+
```
62+
63+
3. Apply the configuration:
64+
```bash
65+
terraform apply
66+
```
67+
68+
## Files
69+
70+
- `main.tf`: Main configuration with instance and security group definitions
71+
- `versions.tf`: Terraform and provider version constraints
72+
73+
This example validates that the module correctly handles multi-zone deployments and demonstrates best practices for zone-aware infrastructure deployment on Scaleway.

examples/multi-zones/main.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
locals {
2+
instances = {
3+
"0" = {
4+
name = "instance-0"
5+
zone = "fr-par-1"
6+
}
7+
"1" = {
8+
name = "instance-1"
9+
zone = "fr-par-2"
10+
}
11+
}
12+
unique_zones = toset([
13+
for instance in local.instances : instance.zone
14+
])
15+
}
16+
17+
module "instances" {
18+
source = "../../"
19+
20+
for_each = local.instances
21+
22+
instance_type = "PLAY2-NANO" # 2 vCPU, 8GB RAM
23+
image = "debian_bookworm"
24+
25+
# Network
26+
private_networks = []
27+
security_group_id = scaleway_instance_security_group.instances_security_group[each.value.zone].id
28+
zone = each.value.zone
29+
30+
additional_volume_ids = null
31+
32+
# Naming
33+
hostname = each.value.name
34+
35+
# IPs
36+
enable_ipv6 = false
37+
enable_public_ipv4 = true
38+
}
39+
40+
resource "scaleway_instance_security_group" "instances_security_group" {
41+
for_each = local.unique_zones
42+
43+
name = "instance-sg"
44+
45+
# Default policies - drop everything except explicitly allowed
46+
inbound_default_policy = "drop"
47+
outbound_default_policy = "accept"
48+
zone = each.value
49+
50+
inbound_rule {
51+
action = "accept"
52+
port = 22
53+
ip_range = "0.0.0.0/22"
54+
}
55+
56+
# Outbound rules - allow all traffic out
57+
outbound_rule {
58+
action = "accept"
59+
port_range = "1-65535"
60+
ip_range = "0.0.0.0/0"
61+
}
62+
63+
outbound_rule {
64+
action = "accept"
65+
protocol = "UDP"
66+
port_range = "1-65535"
67+
ip_range = "0.0.0.0/0"
68+
}
69+
}

examples/multi-zones/versions.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
scaleway = {
4+
source = "scaleway/scaleway"
5+
version = "~> 2.59"
6+
}
7+
}
8+
required_version = "~> 1.10"
9+
}
10+
11+
provider "scaleway" {}

ipv4.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ data "scaleway_instance_private_nic" "this" {
3434

3535
server_id = scaleway_instance_server.this.id
3636
private_network_id = var.private_networks[count.index]
37+
zone = var.zone
3738
}
3839

3940

0 commit comments

Comments
 (0)