Skip to content

Commit f6f377e

Browse files
authored
feat(iam): add tags field (#2259)
* feat(iam): add tags field * update cassettes
1 parent 8b96c04 commit f6f377e

12 files changed

+514
-418
lines changed

docs/resources/iam_application.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ resource "scaleway_iam_application" "main" {
2020

2121
The following arguments are supported:
2222

23-
- `name` - .The name of the iam application.
24-
- `description` - The description of the iam application.
23+
- `name` - (Optional) The name of the iam application.
24+
- `description` - (Optional) The description of the iam application.
25+
- `tags` - (Optional) The tags associated with the application.
2526
- `organization_id` - (Defaults to [provider](../index.md#organization_d) `organization_id`) The ID of the organization the application is associated with.
2627

2728
## Attributes Reference

docs/resources/iam_group.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ resource "scaleway_iam_group" "with_users" {
6363

6464
- `description` - (Optional) The description of the IAM group.
6565

66+
- `tags` - (Optional) The tags associated with the group.
67+
6668
- `application_ids` - (Optional) The list of IDs of the applications attached to the group.
6769

6870
- `user_ids` - (Optional) The list of IDs of the users attached to the group.

docs/resources/iam_policy.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ resource "scaleway_iam_policy" "iam_tf_storage_policy" {
7676

7777
The following arguments are supported:
7878

79-
- `name` - .The name of the iam policy.
80-
- `description` - The description of the iam policy.
79+
- `name` - (Optional) The name of the iam policy.
80+
- `description` - (Optional) The description of the iam policy.
81+
- `tags` - (Optional) The tags associated with the iam policy.
8182
- `organization_id` - (Defaults to [provider](../index.md#organization_d) `organization_id`) The ID of the organization the policy is associated with.
8283
- `user_id` - ID of the User the policy will be linked to
8384
- `group_id` - ID of the Group the policy will be linked to

scaleway/resource_iam_application.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ func resourceScalewayIamApplication() *schema.Resource {
4646
Computed: true,
4747
Description: "Whether or not the application is editable.",
4848
},
49+
"tags": {
50+
Type: schema.TypeList,
51+
Elem: &schema.Schema{
52+
Type: schema.TypeString,
53+
},
54+
Optional: true,
55+
Description: "The tags associated with the application",
56+
},
4957
"organization_id": organizationIDOptionalSchema(),
5058
},
5159
}
@@ -57,6 +65,7 @@ func resourceScalewayIamApplicationCreate(ctx context.Context, d *schema.Resourc
5765
Name: expandOrGenerateString(d.Get("name"), "application"),
5866
Description: d.Get("description").(string),
5967
OrganizationID: d.Get("organization_id").(string),
68+
Tags: expandStrings(d.Get("tags")),
6069
}, scw.WithContext(ctx))
6170
if err != nil {
6271
return diag.FromErr(err)
@@ -85,6 +94,7 @@ func resourceScalewayIamApplicationRead(ctx context.Context, d *schema.ResourceD
8594
_ = d.Set("updated_at", flattenTime(app.UpdatedAt))
8695
_ = d.Set("organization_id", app.OrganizationID)
8796
_ = d.Set("editable", app.Editable)
97+
_ = d.Set("tags", flattenSliceString(app.Tags))
8898

8999
return nil
90100
}
@@ -106,6 +116,10 @@ func resourceScalewayIamApplicationUpdate(ctx context.Context, d *schema.Resourc
106116
req.Description = expandUpdatedStringPtr(d.Get("description"))
107117
hasChanged = true
108118
}
119+
if d.HasChange("tags") {
120+
req.Tags = expandUpdatedStringsPtr(d.Get("tags"))
121+
hasChanged = true
122+
}
109123

110124
if hasChanged {
111125
_, err := api.UpdateApplication(req, scw.WithContext(ctx))

scaleway/resource_iam_application_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,31 @@ func TestAccScalewayIamApplication_Basic(t *testing.T) {
6060
resource "scaleway_iam_application" "main" {
6161
name = "tf_tests_app_basic"
6262
description = "a description"
63+
tags = ["tf_tests", "tests"]
6364
}
6465
`,
6566
Check: resource.ComposeTestCheckFunc(
6667
testAccCheckScalewayIamApplicationExists(tt, "scaleway_iam_application.main"),
6768
resource.TestCheckResourceAttr("scaleway_iam_application.main", "name", "tf_tests_app_basic"),
6869
resource.TestCheckResourceAttr("scaleway_iam_application.main", "description", "a description"),
70+
resource.TestCheckResourceAttr("scaleway_iam_application.main", "tags.#", "2"),
71+
resource.TestCheckResourceAttr("scaleway_iam_application.main", "tags.0", "tf_tests"),
72+
resource.TestCheckResourceAttr("scaleway_iam_application.main", "tags.1", "tests"),
6973
),
7074
},
7175
{
7276
Config: `
7377
resource "scaleway_iam_application" "main" {
7478
name = "tf_tests_app_basic_rename"
7579
description = "another description"
80+
tags = []
7681
}
7782
`,
7883
Check: resource.ComposeTestCheckFunc(
7984
testAccCheckScalewayIamApplicationExists(tt, "scaleway_iam_application.main"),
8085
resource.TestCheckResourceAttr("scaleway_iam_application.main", "name", "tf_tests_app_basic_rename"),
8186
resource.TestCheckResourceAttr("scaleway_iam_application.main", "description", "another description"),
87+
resource.TestCheckResourceAttr("scaleway_iam_application.main", "tags.#", "0"),
8288
),
8389
},
8490
},

scaleway/resource_iam_group.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ func resourceScalewayIamGroup() *schema.Resource {
6565
Optional: true,
6666
Default: false,
6767
},
68+
"tags": {
69+
Type: schema.TypeList,
70+
Elem: &schema.Schema{
71+
Type: schema.TypeString,
72+
},
73+
Optional: true,
74+
Description: "The tags associated with the application",
75+
},
6876
"organization_id": organizationIDOptionalSchema(),
6977
},
7078
}
@@ -76,6 +84,7 @@ func resourceScalewayIamGroupCreate(ctx context.Context, d *schema.ResourceData,
7684
OrganizationID: d.Get("organization_id").(string),
7785
Name: expandOrGenerateString(d.Get("name"), "group"),
7886
Description: d.Get("description").(string),
87+
Tags: expandStrings(d.Get("tags")),
7988
}
8089
group, err := api.CreateGroup(req, scw.WithContext(ctx))
8190
if err != nil {
@@ -118,6 +127,7 @@ func resourceScalewayIamGroupRead(ctx context.Context, d *schema.ResourceData, m
118127
_ = d.Set("created_at", flattenTime(group.CreatedAt))
119128
_ = d.Set("updated_at", flattenTime(group.UpdatedAt))
120129
_ = d.Set("organization_id", group.OrganizationID)
130+
_ = d.Set("tags", flattenSliceString(group.Tags))
121131

122132
if !d.Get("external_membership").(bool) {
123133
_ = d.Set("user_ids", group.UserIDs)
@@ -137,11 +147,12 @@ func resourceScalewayIamGroupUpdate(ctx context.Context, d *schema.ResourceData,
137147
return diag.FromErr(err)
138148
}
139149

140-
if d.HasChanges("name", "description") {
150+
if d.HasChanges("name", "description", "tags") {
141151
_, err = api.UpdateGroup(&iam.UpdateGroupRequest{
142152
GroupID: group.ID,
143153
Name: expandUpdatedStringPtr(d.Get("name")),
144154
Description: expandUpdatedStringPtr(d.Get("description")),
155+
Tags: expandUpdatedStringsPtr(d.Get("tags")),
145156
}, scw.WithContext(ctx))
146157
if err != nil {
147158
return diag.FromErr(err)

scaleway/resource_iam_group_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,63 +58,76 @@ func TestAccScalewayIamGroup_Basic(t *testing.T) {
5858
Config: `
5959
resource "scaleway_iam_group" "main_basic" {
6060
name = "tf_tests_iam_group_basic"
61+
tags = ["tf_tests", "tests"]
6162
}
6263
`,
6364
Check: resource.ComposeTestCheckFunc(
6465
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main_basic"),
6566
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "name", "tf_tests_iam_group_basic"),
6667
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "description", ""),
68+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.#", "2"),
69+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.0", "tf_tests"),
70+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.1", "tests"),
6771
),
6872
},
6973
{
7074
Config: `
7175
resource "scaleway_iam_group" "main_basic" {
7276
name = "tf_tests_iam_group_basic"
7377
description = "basic description"
78+
tags = ["tf_tests"]
7479
}
7580
`,
7681
Check: resource.ComposeTestCheckFunc(
7782
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main_basic"),
7883
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "name", "tf_tests_iam_group_basic"),
7984
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "description", "basic description"),
85+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.#", "1"),
86+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.0", "tf_tests"),
8087
),
8188
},
8289
{
8390
Config: `
8491
resource "scaleway_iam_group" "main_basic" {
8592
name = "tf_tests_iam_group_basic_renamed"
8693
description = "basic description"
94+
tags = []
8795
}
8896
`,
8997
Check: resource.ComposeTestCheckFunc(
9098
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main_basic"),
9199
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "name", "tf_tests_iam_group_basic_renamed"),
92100
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "description", "basic description"),
101+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.#", "0"),
93102
),
94103
},
95104
{
96105
Config: `
97106
resource "scaleway_iam_group" "main_basic" {
98107
name = "tf_tests_iam_group_basic_renamed"
99108
description = "this is another description"
109+
tags = ["tf_tests"]
100110
}
101111
`,
102112
Check: resource.ComposeTestCheckFunc(
103113
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main_basic"),
104114
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "name", "tf_tests_iam_group_basic_renamed"),
105115
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "description", "this is another description"),
116+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.#", "1"),
117+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.0", "tf_tests"),
106118
),
107119
},
108120
{
109121
Config: `
110-
resource "scaleway_iam_group" "main" {
122+
resource "scaleway_iam_group" "main_basic" {
111123
name = "tf_tests_iam_group_basic_renamed"
112124
}
113125
`,
114126
Check: resource.ComposeTestCheckFunc(
115-
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main"),
116-
resource.TestCheckResourceAttr("scaleway_iam_group.main", "name", "tf_tests_iam_group_basic_renamed"),
117-
resource.TestCheckResourceAttr("scaleway_iam_group.main", "description", ""),
127+
testAccCheckScalewayIamGroupExists(tt, "scaleway_iam_group.main_basic"),
128+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "name", "tf_tests_iam_group_basic_renamed"),
129+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "description", ""),
130+
resource.TestCheckResourceAttr("scaleway_iam_group.main_basic", "tags.#", "0"),
118131
),
119132
},
120133
},

scaleway/resource_iam_policy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ func resourceScalewayIamPolicy() *schema.Resource {
107107
},
108108
},
109109
},
110+
"tags": {
111+
Type: schema.TypeList,
112+
Elem: &schema.Schema{
113+
Type: schema.TypeString,
114+
},
115+
Optional: true,
116+
Description: "The tags associated with the policy",
117+
},
110118
},
111119
}
112120
}
@@ -123,6 +131,7 @@ func resourceScalewayIamPolicyCreate(ctx context.Context, d *schema.ResourceData
123131
ApplicationID: expandStringPtr(d.Get("application_id")),
124132
NoPrincipal: expandBoolPtr(getBool(d, "no_principal")),
125133
OrganizationID: d.Get("organization_id").(string),
134+
Tags: expandStrings(d.Get("tags")),
126135
}, scw.WithContext(ctx))
127136
if err != nil {
128137
return diag.FromErr(err)
@@ -151,6 +160,7 @@ func resourceScalewayIamPolicyRead(ctx context.Context, d *schema.ResourceData,
151160
_ = d.Set("updated_at", flattenTime(pol.UpdatedAt))
152161
_ = d.Set("organization_id", pol.OrganizationID)
153162
_ = d.Set("editable", pol.Editable)
163+
_ = d.Set("tags", flattenSliceString(pol.Tags))
154164

155165
if pol.UserID != nil {
156166
_ = d.Set("user_id", flattenStringPtr(pol.UserID))
@@ -193,6 +203,10 @@ func resourceScalewayIamPolicyUpdate(ctx context.Context, d *schema.ResourceData
193203
hasUpdated = true
194204
req.Description = expandUpdatedStringPtr(d.Get("description"))
195205
}
206+
if d.HasChange("tags") {
207+
hasUpdated = true
208+
req.Tags = expandUpdatedStringsPtr(d.Get("tags"))
209+
}
196210
if d.HasChange("user_id") {
197211
hasUpdated = true
198212
req.UserID = expandStringPtr(d.Get("user_id"))

scaleway/resource_iam_policy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func TestAccScalewayIamPolicy_Basic(t *testing.T) {
8080
permission_set_names = ["ContainerRegistryReadOnly"]
8181
}
8282
provider = side
83+
tags = ["tf_tests", "tests"]
8384
}
8485
`, project.OrganizationID),
8586
Check: resource.ComposeTestCheckFunc(
@@ -89,6 +90,9 @@ func TestAccScalewayIamPolicy_Basic(t *testing.T) {
8990
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "no_principal", "true"),
9091
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "rule.0.permission_set_names.0", "AllProductsFullAccess"),
9192
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "rule.1.permission_set_names.0", "ContainerRegistryReadOnly"),
93+
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "tags.#", "2"),
94+
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "tags.0", "tf_tests"),
95+
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "tags.1", "tests"),
9296
),
9397
},
9498
{
@@ -111,6 +115,7 @@ func TestAccScalewayIamPolicy_Basic(t *testing.T) {
111115
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "no_principal", "true"),
112116
resource.TestCheckTypeSetElemNestedAttrs("scaleway_iam_policy.main", "rule.*", map[string]string{"organization_id": project.OrganizationID}),
113117
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "rule.0.permission_set_names.0", "AllProductsFullAccess"),
118+
resource.TestCheckResourceAttr("scaleway_iam_policy.main", "tags.#", "0"),
114119
),
115120
},
116121
},

0 commit comments

Comments
 (0)