Skip to content

Commit 74acf21

Browse files
committed
feat(vpc): add support for routes propagation
1 parent 22616d2 commit 74acf21

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

docs/data-sources/vpcs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ In addition to all arguments above, the following attributes are exported:
4242
- `updated_at` - Date and time of VPC's last update (RFC 3339 format).
4343
- `organization_id` - The Organization ID the VPC is associated with.
4444
- `project_id` - The ID of the Project the VPC is associated with.
45+
- `enable_routing` - Defines whether routing between Private Networks in the VPC is enabled.
46+
- `enable_custom_routes_propagation` - Defines whether the VPC advertises custom routes between its Private Networks.

docs/resources/vpc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The following arguments are supported:
3636
- `name` - (Optional) The name for the VPC. If not provided it will be randomly generated.
3737
- `tags` - (Optional) The tags to associate with the VPC.
3838
- `enable_routing` - (Optional) Enable routing between Private Networks in the VPC. Note that you will not be able to deactivate it afterwards.
39+
- `enable_custom_routes_propagation` - (Optional) Defines whether the VPC advertises custom routes between its Private Networks. Note that you will not be able to deactivate it afterwards.
3940
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) of the VPC.
4041
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the Project the VPC is associated with.
4142

docs/resources/vpc_private_network.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The following arguments are supported:
5252
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) of the Private Network.
5353
- `vpc_id` - (Optional) The VPC in which to create the Private Network.
5454
- `is_regional` - (Deprecated) Private Networks are now all necessarily regional.
55+
- `enable_default_route_propagation` - (Optional) Defines whether default v4 and v6 routes are propagated for this Private Network.
5556
- `zone` - (Deprecated) Use `region` instead.
5657

5758
## Attributes Reference

internal/services/vpc/private_network.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func ResourcePrivateNetwork() *schema.Resource {
159159
ForceNew: true,
160160
Description: "The VPC in which to create the private network",
161161
},
162+
"default_route_propagation_enabled": {
163+
Type: schema.TypeBool,
164+
Optional: true,
165+
Computed: true,
166+
Description: "Defines whether default v4 and v6 routes are propagated for this Private Network",
167+
},
162168
"project_id": account.ProjectIDSchema(),
163169
"zone": {
164170
Type: schema.TypeString,
@@ -197,10 +203,11 @@ func ResourceVPCPrivateNetworkCreate(ctx context.Context, d *schema.ResourceData
197203
}
198204

199205
req := &vpc.CreatePrivateNetworkRequest{
200-
Name: types.ExpandOrGenerateString(d.Get("name"), "pn"),
201-
Tags: types.ExpandStrings(d.Get("tags")),
202-
ProjectID: d.Get("project_id").(string),
203-
Region: region,
206+
Name: types.ExpandOrGenerateString(d.Get("name"), "pn"),
207+
Tags: types.ExpandStrings(d.Get("tags")),
208+
DefaultRoutePropagationEnabled: d.Get("enable_default_route_propagation").(bool),
209+
ProjectID: d.Get("project_id").(string),
210+
Region: region,
204211
}
205212

206213
if _, ok := d.GetOk("vpc_id"); ok {
@@ -258,6 +265,7 @@ func ResourceVPCPrivateNetworkRead(ctx context.Context, d *schema.ResourceData,
258265
_ = d.Set("created_at", types.FlattenTime(pn.CreatedAt))
259266
_ = d.Set("updated_at", types.FlattenTime(pn.UpdatedAt))
260267
_ = d.Set("tags", pn.Tags)
268+
_ = d.Set("enable_default_route_propagation", pn.DefaultRoutePropagationEnabled)
261269
_ = d.Set("region", region)
262270
_ = d.Set("is_regional", true)
263271
_ = d.Set("zone", zone)
@@ -276,10 +284,11 @@ func ResourceVPCPrivateNetworkUpdate(ctx context.Context, d *schema.ResourceData
276284
}
277285

278286
_, err = vpcAPI.UpdatePrivateNetwork(&vpc.UpdatePrivateNetworkRequest{
279-
PrivateNetworkID: ID,
280-
Region: region,
281-
Name: scw.StringPtr(d.Get("name").(string)),
282-
Tags: types.ExpandUpdatedStringsPtr(d.Get("tags")),
287+
PrivateNetworkID: ID,
288+
Region: region,
289+
Name: scw.StringPtr(d.Get("name").(string)),
290+
Tags: types.ExpandUpdatedStringsPtr(d.Get("tags")),
291+
DefaultRoutePropagationEnabled: types.ExpandBoolPtr(d.Get("enable_default_route_propagation").(bool)),
283292
}, scw.WithContext(ctx))
284293
if err != nil {
285294
return diag.FromErr(err)

internal/services/vpc/vpc.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func ResourceVPC() *schema.Resource {
4545
Computed: true,
4646
Description: "Enable routing between Private Networks in the VPC",
4747
},
48+
"enable_custom_routes_propagation": {
49+
Type: schema.TypeBool,
50+
Optional: true,
51+
Computed: true,
52+
Description: "Defines whether the VPC advertises custom routes between its Private Networks",
53+
},
4854
"project_id": account.ProjectIDSchema(),
4955
"region": regional.Schema(),
5056
// Computed elements
@@ -93,6 +99,16 @@ func ResourceVPCCreate(ctx context.Context, d *schema.ResourceData, m any) diag.
9399
return diag.FromErr(err)
94100
}
95101

102+
if _, ok := d.GetOk("enable_custom_routes_propagation"); ok {
103+
_, err = vpcAPI.EnableCustomRoutesPropagation(&vpc.EnableCustomRoutesPropagationRequest{
104+
Region: region,
105+
VpcID: res.ID,
106+
}, scw.WithContext(ctx))
107+
if err != nil {
108+
return diag.FromErr(err)
109+
}
110+
}
111+
96112
d.SetId(regional.NewIDString(region, res.ID))
97113

98114
return ResourceVPCRead(ctx, d, m)
@@ -125,6 +141,7 @@ func ResourceVPCRead(ctx context.Context, d *schema.ResourceData, m any) diag.Di
125141
_ = d.Set("updated_at", types.FlattenTime(res.UpdatedAt))
126142
_ = d.Set("is_default", res.IsDefault)
127143
_ = d.Set("enable_routing", res.RoutingEnabled)
144+
_ = d.Set("enable_custom_routes_propagation", res.CustomRoutesPropagationEnabled)
128145
_ = d.Set("region", region)
129146

130147
if len(res.Tags) > 0 {
@@ -177,6 +194,19 @@ func ResourceVPCUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.
177194
}
178195
}
179196

197+
if d.HasChange("enable_custom_routes_propagation") {
198+
enableCustomRoutesPropagation := d.Get("enable_custom_routes_propagation").(bool)
199+
if enableCustomRoutesPropagation {
200+
_, err = vpcAPI.EnableCustomRoutesPropagation(&vpc.EnableCustomRoutesPropagationRequest{
201+
Region: region,
202+
VpcID: ID,
203+
}, scw.WithContext(ctx))
204+
if err != nil {
205+
return diag.FromErr(err)
206+
}
207+
}
208+
}
209+
180210
return ResourceVPCRead(ctx, d, m)
181211
}
182212

0 commit comments

Comments
 (0)