Skip to content

Commit 1f3e11c

Browse files
committed
feat: data source user tags
1 parent 2f27cc6 commit 1f3e11c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/data-sources/iam_user.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ data "scaleway_iam_user" "find_by_email" {
3636
In addition to all above arguments, the following attributes are exported:
3737

3838
- `id` - The ID of the IAM user.
39+
- `tags` - The tags associated with the user.
40+

internal/services/iam/user_data_source.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package iam
33
import (
44
"context"
55
"fmt"
6+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -30,6 +31,14 @@ func DataSourceUser() *schema.Resource {
3031
ValidateDiagFunc: verify.IsEmail(),
3132
ConflictsWith: []string{"user_id"},
3233
},
34+
"tags": {
35+
Type: schema.TypeList,
36+
Elem: &schema.Schema{
37+
Type: schema.TypeString,
38+
},
39+
Optional: true,
40+
Description: "The tags associated with the user",
41+
},
3342
"organization_id": {
3443
Type: schema.TypeString,
3544
Description: "The organization_id you want to attach the resource to",
@@ -44,6 +53,7 @@ func DataSourceIamUserRead(ctx context.Context, d *schema.ResourceData, m interf
4453
iamAPI := NewAPI(m)
4554

4655
var email, organizationID string
56+
var tags []string
4757
userID, ok := d.GetOk("user_id")
4858
if ok {
4959
userID = d.Get("user_id")
@@ -55,6 +65,7 @@ func DataSourceIamUserRead(ctx context.Context, d *schema.ResourceData, m interf
5565
}
5666
email = res.Email
5767
organizationID = res.OrganizationID
68+
tags = res.Tags
5869
} else {
5970
res, err := iamAPI.ListUsers(&iam.ListUsersRequest{
6071
OrganizationID: account.GetOrganizationID(m, d),
@@ -70,7 +81,7 @@ func DataSourceIamUserRead(ctx context.Context, d *schema.ResourceData, m interf
7081
if userID != "" {
7182
return diag.Errorf("more than 1 user found with the same email %s", d.Get("email"))
7283
}
73-
userID, email = user.ID, user.Email
84+
userID, email, tags = user.ID, user.Email, user.Tags
7485
}
7586
}
7687
if userID == "" {
@@ -86,6 +97,7 @@ func DataSourceIamUserRead(ctx context.Context, d *schema.ResourceData, m interf
8697

8798
_ = d.Set("user_id", userID)
8899
_ = d.Set("email", email)
100+
_ = d.Set("tags", types.FlattenSliceString(tags))
89101
_ = d.Set("organization_id", organizationID)
90102

91103
return nil

0 commit comments

Comments
 (0)