Skip to content

Commit 430d4ca

Browse files
authored
fix(s2s_vpn): correctly read zone from vpn gw config (#3609)
* fix(s2s_vpn): correctly read zone from vpn gw config * lint
1 parent 6209930 commit 430d4ca

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

internal/locality/zonal/schemas.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,3 @@ func Schema() *schema.Schema {
3636
DiffSuppressFunc: locality.SuppressSDKNullAssignment,
3737
}
3838
}
39-
40-
func OptionalSchema() *schema.Schema {
41-
return &schema.Schema{
42-
Type: schema.TypeString,
43-
Optional: true,
44-
Computed: true,
45-
Description: "The zone you want to attach the resource to",
46-
ValidateDiagFunc: verify.ValidateStringInSliceWithWarning(AllZones(), "zone"),
47-
DiffSuppressFunc: locality.SuppressSDKNullAssignment,
48-
}
49-
}

internal/services/s2svpn/vpn_gateway.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"context"
55
_ "time"
66

7+
"github.com/hashicorp/go-cty/cty"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
s2svpn "github.com/scaleway/scaleway-sdk-go/api/s2s_vpn/v1alpha1"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
15+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1416
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
1517
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
1618
)
@@ -115,7 +117,7 @@ func vpnGatewaySchema() map[string]*schema.Schema {
115117
Computed: true,
116118
Description: "The date and time of the last update of the VPN gateway",
117119
},
118-
"zone": zonal.OptionalSchema(),
120+
"zone": zonal.Schema(),
119121
"region": regional.Schema(),
120122
"project_id": account.ProjectIDSchema(),
121123
"organization_id": {
@@ -132,7 +134,12 @@ func ResourceVPNGatewayCreate(ctx context.Context, d *schema.ResourceData, m any
132134
return diag.FromErr(err)
133135
}
134136

135-
zone := scw.Zone(d.Get("zone").(string))
137+
var zonePtr *scw.Zone
138+
139+
if rawZone, ok := meta.GetRawConfigForKey(d, "zone", cty.String); ok && rawZone != nil && rawZone != "" {
140+
zone := scw.Zone(rawZone.(string))
141+
zonePtr = &zone
142+
}
136143

137144
req := &s2svpn.CreateVpnGatewayRequest{
138145
Region: region,
@@ -143,7 +150,7 @@ func ResourceVPNGatewayCreate(ctx context.Context, d *schema.ResourceData, m any
143150
PrivateNetworkID: regional.ExpandID(d.Get("private_network_id").(string)).ID,
144151
IpamPrivateIPv4ID: types.ExpandStringPtr(d.Get("ipam_private_ipv4_id").(string)),
145152
IpamPrivateIPv6ID: types.ExpandStringPtr(d.Get("ipam_private_ipv6_id").(string)),
146-
Zone: &zone,
153+
Zone: zonePtr,
147154
PublicConfig: expandVPNGatewayPublicConfig(d.Get("public_config")),
148155
}
149156

0 commit comments

Comments
 (0)