Skip to content

Commit c4d7def

Browse files
committed
fix: use locality.ExpandID for deployment_id in user and database resources
1 parent 90e7b99 commit c4d7def

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

internal/services/datawarehouse/database.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
datawarehouseapi "github.com/scaleway/scaleway-sdk-go/api/datawarehouse/v1beta1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1315
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1416
)
1517

@@ -24,10 +26,11 @@ func ResourceDatabase() *schema.Resource {
2426
Schema: map[string]*schema.Schema{
2527
"region": regional.Schema(),
2628
"deployment_id": {
27-
Type: schema.TypeString,
28-
Required: true,
29-
ForceNew: true,
30-
Description: "ID of the Datawarehouse deployment to which this database belongs.",
29+
Type: schema.TypeString,
30+
Required: true,
31+
ForceNew: true,
32+
Description: "ID of the Datawarehouse deployment to which this database belongs.",
33+
DiffSuppressFunc: dsf.Locality,
3134
},
3235
"name": {
3336
Type: schema.TypeString,
@@ -45,10 +48,12 @@ func ResourceDatabase() *schema.Resource {
4548
}
4649

4750
func resourceDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
48-
api := NewAPI(meta)
51+
api, region, err := datawarehouseAPIWithRegion(d, meta)
52+
if err != nil {
53+
return diag.FromErr(err)
54+
}
4955

50-
region := scw.Region(d.Get("region").(string))
51-
deploymentID := d.Get("deployment_id").(string)
56+
deploymentID := locality.ExpandID(d.Get("deployment_id").(string))
5257
name := d.Get("name").(string)
5358

5459
req := &datawarehouseapi.CreateDatabaseRequest{
@@ -57,7 +62,7 @@ func resourceDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta an
5762
Name: name,
5863
}
5964

60-
_, err := api.CreateDatabase(req, scw.WithContext(ctx))
65+
_, err = api.CreateDatabase(req, scw.WithContext(ctx))
6166
if err != nil {
6267
return diag.FromErr(err)
6368
}

internal/services/datawarehouse/user.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
datawarehouseapi "github.com/scaleway/scaleway-sdk-go/api/datawarehouse/v1beta1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1315
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1416
)
1517

@@ -25,10 +27,11 @@ func ResourceUser() *schema.Resource {
2527
Schema: map[string]*schema.Schema{
2628
"region": regional.Schema(),
2729
"deployment_id": {
28-
Type: schema.TypeString,
29-
Required: true,
30-
ForceNew: true,
31-
Description: "ID of the Datawarehouse deployment to which this user belongs.",
30+
Type: schema.TypeString,
31+
Required: true,
32+
ForceNew: true,
33+
Description: "ID of the Datawarehouse deployment to which this user belongs.",
34+
DiffSuppressFunc: dsf.Locality,
3235
},
3336
"name": {
3437
Type: schema.TypeString,
@@ -53,9 +56,12 @@ func ResourceUser() *schema.Resource {
5356
}
5457

5558
func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
56-
api := NewAPI(meta)
57-
region := scw.Region(d.Get("region").(string))
58-
deploymentID := d.Get("deployment_id").(string)
59+
api, region, err := datawarehouseAPIWithRegion(d, meta)
60+
if err != nil {
61+
return diag.FromErr(err)
62+
}
63+
64+
deploymentID := locality.ExpandID(d.Get("deployment_id").(string))
5965
name := d.Get("name").(string)
6066
password := d.Get("password").(string)
6167
isAdmin := d.Get("is_admin").(bool)
@@ -68,7 +74,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta any) d
6874
IsAdmin: isAdmin,
6975
}
7076

71-
_, err := api.CreateUser(req, scw.WithContext(ctx))
77+
_, err = api.CreateUser(req, scw.WithContext(ctx))
7278
if err != nil {
7379
return diag.FromErr(err)
7480
}

0 commit comments

Comments
 (0)