Skip to content

Commit 4891e62

Browse files
authored
feat(flexibleip): add mac address resource (#2093)
* feat(flexibleip): add mac address resource * fix * add doc + fixes * update cassette * update cassettes * fix * add descriptions in tests
1 parent 0744c87 commit 4891e62

11 files changed

+11716
-15
lines changed
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
subcategory: "Elastic Metal"
3+
page_title: "Scaleway: scaleway_flexible_ip_mac_address"
4+
---
5+
6+
# scaleway_flexible_ip_mac_address
7+
8+
Creates and manages Scaleway Flexible IP Mac Addresses.
9+
For more information, see [the documentation](https://developers.scaleway.com/en/products/flexible-ip/api).
10+
11+
## Examples
12+
13+
### Basic
14+
15+
```hcl
16+
resource "scaleway_flexible_ip" "main" {}
17+
18+
resource "scaleway_flexible_ip_mac_address" "main" {
19+
flexible_ip_id = scaleway_flexible_ip.main.id
20+
type = "kvm"
21+
}
22+
```
23+
24+
### Duplicate on many other flexible IPs
25+
26+
```hcl
27+
data "scaleway_baremetal_offer" "my_offer" {
28+
name = "EM-B112X-SSD"
29+
}
30+
31+
resource "scaleway_baremetal_server" "base" {
32+
name = "TestAccScalewayBaremetalServer_WithoutInstallConfig"
33+
offer = data.scaleway_baremetal_offer.my_offer.offer_id
34+
install_config_afterward = true
35+
}
36+
37+
resource "scaleway_flexible_ip" "ip01" {
38+
server_id = scaleway_baremetal_server.base.id
39+
}
40+
41+
resource "scaleway_flexible_ip" "ip02" {
42+
server_id = scaleway_baremetal_server.base.id
43+
}
44+
45+
resource "scaleway_flexible_ip" "ip03" {
46+
server_id = scaleway_baremetal_server.base.id
47+
}
48+
49+
resource "scaleway_flexible_ip_mac_address" "main" {
50+
flexible_ip_id = scaleway_flexible_ip.ip01.id
51+
type = "kvm"
52+
flexible_ip_ids_to_duplicate = [
53+
scaleway_flexible_ip.ip02.id,
54+
scaleway_flexible_ip.ip03.id
55+
]
56+
}
57+
```
58+
59+
## Arguments Reference
60+
61+
The following arguments are supported:
62+
63+
- `flexible_ip_id`: (Required) The ID of the flexible IP for which to generate a virtual MAC.
64+
- `type`: (Required) The type of the virtual MAC.
65+
- `flexible_ip_ids_to_duplicate` - (Optional) The IDs of the flexible IPs on which to duplicate the virtual MAC.
66+
~> **Important:** The flexible IPs need to be attached to the same server for the operation to work.
67+
68+
## Attributes Reference
69+
70+
In addition to all arguments above, the following attributes are exported:
71+
72+
- `id` - The ID of the Flexible IP Mac Address
73+
74+
~> **Important:** Flexible IP Mac Addresses' 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`
75+
76+
- `address` - The Virtual MAC address.
77+
- `zone` - The zone of the Virtual Mac Address.
78+
- `status` - The Virtual MAC status.
79+
- `created_at` - The date at which the Virtual Mac Address was created (RFC 3339 format).
80+
- `updated_at` - The date at which the Virtual Mac Address was last updated (RFC 3339 format).
81+
82+
## Import
83+
84+
Flexible IP Mac Addresses can be imported using the `{zone}/{id}`, e.g.
85+
86+
```bash
87+
$ terraform import scaleway_flexible_ip_mac_address.main fr-par-1/11111111-1111-1111-1111-111111111111
88+
```

scaleway/helpers.go

+9
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,12 @@ func retryWhenAWSErrCodeNotEquals[T any](ctx context.Context, codes []string, co
10701070
return !tfawserr.ErrCodeEquals(err, codes...)
10711071
})
10721072
}
1073+
1074+
func sliceContainsString(slice []string, str string) bool {
1075+
for _, v := range slice {
1076+
if v == str {
1077+
return true
1078+
}
1079+
}
1080+
return false
1081+
}

scaleway/helpers_webhosting.go

-9
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,3 @@ func waitForHosting(ctx context.Context, api *webhosting.API, region scw.Region,
9494
RetryInterval: &retryInterval,
9595
}, scw.WithContext(ctx))
9696
}
97-
98-
func containsTag(tags []string, tag string) bool {
99-
for _, t := range tags {
100-
if t == tag {
101-
return true
102-
}
103-
}
104-
return false
105-
}

scaleway/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
9898
"scaleway_domain_record": resourceScalewayDomainRecord(),
9999
"scaleway_domain_zone": resourceScalewayDomainZone(),
100100
"scaleway_flexible_ip": resourceScalewayFlexibleIP(),
101+
"scaleway_flexible_ip_mac_address": resourceScalewayFlexibleIPMACAddress(),
101102
"scaleway_function": resourceScalewayFunction(),
102103
"scaleway_function_cron": resourceScalewayFunctionCron(),
103104
"scaleway_function_domain": resourceScalewayFunctionDomain(),

scaleway/resource_flexible_ip.go

-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ func resourceScalewayFlexibleIP() *schema.Resource {
4848
Optional: true,
4949
Description: "The baremetal server associated with this flexible IP",
5050
},
51-
"mac_address": {
52-
Type: schema.TypeString,
53-
Computed: true,
54-
Description: "The MAC address of the server associated with this flexible IP",
55-
},
5651
"tags": {
5752
Type: schema.TypeList,
5853
Elem: &schema.Schema{

0 commit comments

Comments
 (0)