Skip to content

Commit c463b43

Browse files
authored
fix(baremetal): compute mapping_id in private_network server (#3056)
* fix(baremetal): compute mapping id in private network * fix(doc): add example in vpc_route and add information about mapping_id in baremetal * fix(doc): update baremetal_server datasource
1 parent ac2139c commit c463b43

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

docs/data-sources/baremetal_server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ In addition to all above arguments, the following attributes are exported:
3535

3636
- `id` - The ID of the server.
3737

38+
The `scaleway_baremetal_server` data source exports certain attributes once the baremetal server information is retrieved. These attributes can be referenced in other parts of your Terraform configuration. The exported attributes are those that come from the `scaleway_baremetal_server` [resource](../resources/baremetal_server.md)
39+
3840
~> **Important:** Baremetal servers' IDs are [zoned](../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`

docs/resources/baremetal_server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ In addition to all arguments above, the following attributes are exported:
316316
- `os_name` - The name of the os.
317317
- `private_network` - The private networks attached to the server.
318318
- `id` - The ID of the private network.
319+
- `mapping_id` - The ID of the Server-to-Private Network mapping.
319320
- `vlan` - The VLAN ID associated to the private network.
320321
- `status` - The private network status.
321322
- `created_at` - The date and time of the creation of the private network.

docs/resources/vpc_route.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ For more information, see [the main documentation](https://www.scaleway.com/en/d
1010

1111
## Example Usage
1212

13-
### Basic
13+
### With Instance
1414

1515
```terraform
1616
resource "scaleway_vpc" "vpc01" {
@@ -45,6 +45,64 @@ resource "scaleway_vpc_route" "rt01" {
4545
}
4646
```
4747

48+
### With Baremetal
49+
50+
```terraform
51+
resource "scaleway_vpc" "vpc01" {
52+
name = "tf-vpc-vpn"
53+
}
54+
55+
resource "scaleway_vpc_private_network" "pn01" {
56+
name = "tf-pn-vpn"
57+
ipv4_subnet {
58+
subnet = "172.16.64.0/22"
59+
}
60+
vpc_id = scaleway_vpc.vpc01.id
61+
}
62+
63+
data "scaleway_baremetal_os" "my_os" {
64+
zone = "fr-par-2"
65+
name = "Ubuntu"
66+
version = "22.04 LTS (Jammy Jellyfish)"
67+
}
68+
69+
data "scaleway_baremetal_offer" "my_offer" {
70+
zone = "fr-par-2"
71+
name = "EM-B112X-SSD"
72+
}
73+
74+
data "scaleway_baremetal_option" "private_network" {
75+
zone = "fr-par-2"
76+
name = "Private Network"
77+
}
78+
79+
data "scaleway_iam_ssh_key" "my_key" {
80+
name = "main"
81+
}
82+
83+
resource "scaleway_baremetal_server" "my_server" {
84+
zone = "fr-par-2"
85+
offer = data.scaleway_baremetal_offer.my_offer.offer_id
86+
os = data.scaleway_baremetal_os.my_os.os_id
87+
ssh_key_ids = [data.scaleway_iam_ssh_key.my_key.id]
88+
89+
options {
90+
id = data.scaleway_baremetal_option.private_network.option_id
91+
}
92+
private_network {
93+
id = scaleway_vpc_private_network.pn01.id
94+
}
95+
}
96+
97+
resource "scaleway_vpc_route" "rt01" {
98+
vpc_id = scaleway_vpc.vpc01.id
99+
description = "tf-route-vpn"
100+
tags = ["tf", "route"]
101+
destination = "10.0.0.0/24"
102+
nexthop_resource_id = scaleway_baremetal_server.my_server.private_network.0.mapping_id
103+
}
104+
```
105+
48106
## Argument Reference
49107

50108
The following arguments are supported:

internal/services/baremetal/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,18 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
217217
Schema: map[string]*schema.Schema{
218218
"id": {
219219
Type: schema.TypeString,
220-
Description: "The private network ID",
220+
Description: "The ID of the private network to associate with the server",
221221
Required: true,
222222
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
223223
StateFunc: func(i interface{}) string {
224224
return locality.ExpandID(i.(string))
225225
},
226226
},
227+
"mapping_id": {
228+
Type: schema.TypeString,
229+
Description: "The ID of the Server-to-Private Network mapping",
230+
Computed: true,
231+
},
227232
"ipam_ip_ids": {
228233
Type: schema.TypeList,
229234
Optional: true,

internal/services/baremetal/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func flattenPrivateNetworks(region scw.Region, privateNetworks []*baremetalV3.Se
195195
for _, privateNetwork := range privateNetworks {
196196
flattenedPrivateNetworks = append(flattenedPrivateNetworks, map[string]interface{}{
197197
"id": regional.NewIDString(region, privateNetwork.PrivateNetworkID),
198+
"mapping_id": regional.NewIDString(region, privateNetwork.ID),
198199
"ipam_ip_ids": regional.NewRegionalIDs(region, privateNetwork.IpamIPIDs),
199200
"vlan": types.FlattenUint32Ptr(privateNetwork.Vlan),
200201
"status": privateNetwork.Status,

0 commit comments

Comments
 (0)