@@ -3,6 +3,7 @@ package iam
33import (
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