Skip to content

Commit 7143c71

Browse files
authored
fix(iam_user): use default organization id when available (#1385)
1 parent b9b8015 commit 7143c71

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

scaleway/data_source_iam_user.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ func dataSourceScalewayIamUser() *schema.Resource {
2828
ValidateFunc: validationEmail(),
2929
ConflictsWith: []string{"user_id"},
3030
},
31-
32-
// Default organization_id will be available on a major release. Please check #1337
3331
"organization_id": {
3432
Type: schema.TypeString,
3533
Description: "The organization_id you want to attach the resource to",
36-
Required: true,
34+
Optional: true,
3735
},
3836
},
3937
}
@@ -56,7 +54,7 @@ func dataSourceScalewayIamUserRead(ctx context.Context, d *schema.ResourceData,
5654
organizationID = res.OrganizationID
5755
} else {
5856
res, err := iamAPI.ListUsers(&iam.ListUsersRequest{
59-
OrganizationID: expandStringPtr(d.Get("organization_id")),
57+
OrganizationID: getOrganizationID(meta, d),
6058
}, scw.WithAllPages(), scw.WithContext(ctx))
6159
if err != nil {
6260
return diag.FromErr(err)

scaleway/helpers_iam.go

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ func iamAPI(m interface{}) *iam.API {
1515
return iam.NewAPI(meta.scwClient)
1616
}
1717

18+
func getOrganizationID(m interface{}, d *schema.ResourceData) *string {
19+
meta := m.(*Meta)
20+
21+
orgID, orgIDExist := d.GetOk("organization_id")
22+
23+
if orgIDExist {
24+
return expandStringPtr(orgID)
25+
}
26+
27+
defaultOrgID, defaultOrgIDExists := meta.scwClient.GetDefaultOrganizationID()
28+
if defaultOrgIDExists {
29+
return expandStringPtr(defaultOrgID)
30+
}
31+
32+
return nil
33+
}
34+
1835
func expandPermissionSetNames(rawPermissions interface{}) *[]string {
1936
permissions := []string{}
2037
permissionSet := rawPermissions.(*schema.Set)

0 commit comments

Comments
 (0)