Skip to content

Commit c935501

Browse files
Release v1.17 (#146)
* Re-review. Mostly formatting changes. * Update CHANGELOG.
1 parent ea2cbe2 commit c935501

File tree

11 files changed

+53
-35
lines changed

11 files changed

+53
-35
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
## 1.17
2+
3+
#### FEATURES
4+
- Add `dependencytrack_user` resource to manage a Managed User.
5+
- Add `dependencytrack_user_team` resource to manage team membership for a managed user.
6+
- Add `dependencytrack_user_permission` resource to manage permissions for a managed user.
7+
- Add `dependencytrack_components` datasource to retrieve the components within a project.
8+
9+
#### DEPENDENCIES
10+
- `github.com/DependencyTrack/client-go` `v0.17.1-0.20250928165948-bd03e361a95f` -> `0.18.0`
11+
112
## 1.16.3
213

314
#### FIXES
4-
- `permissions` in `dependencytrack_team_permissions` no longer needs to be sorted - `https://github.com/SolarFactories/terraform-provider-dependencytrack/issues/117`
15+
- `permissions` in `dependencytrack_team_permissions` no longer needs to be sorted
16+
- https://github.com/SolarFactories/terraform-provider-dependencytrack/issues/117
517

618
#### MISC
719
- Update `docker_compose` to use `latest-alpine` tag for `apiserver`, rather than defaulting to `latest`.

docs/resources/user.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ resource "dependencytrack_user" "example" {
3333
### Optional
3434

3535
- `force_password_change` (Boolean) Whether the User Must change their password on next login.
36-
- `password` (String, Sensitive) Updated password to set for the user.
36+
- `password` (String, Sensitive) Updated password to set for the User.
3737
- `password_expires` (Boolean) Whether the User's password expires. Interval set by DependencyTrack.
3838
- `suspended` (Boolean) Whether the User Account is Suspended.
3939

4040
### Read-Only
4141

42-
- `id` (String) User's username.
42+
- `id` (String) Username of the User.
4343

4444
## Import
4545

docs/resources/user_team.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Manages a team membership for a user.
1616
resource "dependencytrack_team" "example" {
1717
name = "Example"
1818
}
19+
1920
resource "dependencytrack_user" "example" {
2021
username = "Example"
2122
fullname = "Example User"

examples/resources/dependencytrack_user_team/resource.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
resource "dependencytrack_team" "example" {
22
name = "Example"
33
}
4+
45
resource "dependencytrack_user" "example" {
56
username = "Example"
67
fullname = "Example User"

internal/provider/components_data_source_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ resource "dependencytrack_component" "test" {
2222
classifier = "FILE"
2323
hashes = {}
2424
}
25-
2625
data "dependencytrack_components" "test" {
2726
project = dependencytrack_project.test.id
2827
depends_on = [
2928
dependencytrack_component.test
3029
]
3130
}
32-
3331
`,
3432
Check: resource.ComposeAggregateTestCheckFunc(
3533
resource.TestCheckResourceAttr("data.dependencytrack_components.test", "components.#", "1"),

internal/provider/oidc_group_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *oidcGroupResource) Read(ctx context.Context, req resource.ReadRequest,
117117
if err != nil {
118118
resp.Diagnostics.AddError(
119119
"Unable to get updated oidc group",
120-
"Error with reading oidc group: "+id.String()+", in original error: "+err.Error(),
120+
"Error with reading oidc groups, with original error: "+err.Error(),
121121
)
122122
return
123123
}

internal/provider/user_permission_resource.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,20 @@ func (r *userPermissionResource) Create(ctx context.Context, req resource.Create
7575
"username": username,
7676
"permission": permission.Name,
7777
})
78-
user, err := r.client.Permission.AddPermissionToUser(ctx, permission, username)
7978

79+
user, err := r.client.Permission.AddPermissionToUser(ctx, permission, username)
8080
if err != nil {
8181
resp.Diagnostics.AddError(
8282
"Error creating user permission",
83-
"Unexpected error: "+err.Error(),
83+
"Error from: "+err.Error(),
8484
)
8585
return
8686
}
87+
8788
state := userPermissionResourceModel{
8889
Username: types.StringValue(user.Username),
8990
Permission: types.StringValue(permission.Name),
9091
}
91-
9292
diags = resp.State.Set(ctx, state)
9393
resp.Diagnostics.Append(diags...)
9494
if resp.Diagnostics.HasError() {
@@ -140,13 +140,13 @@ func (r *userPermissionResource) Read(ctx context.Context, req resource.ReadRequ
140140
)
141141
return
142142
}
143+
144+
// Update state.
143145
state = userPermissionResourceModel{
144146
Username: types.StringValue(user.Username),
145147
Permission: types.StringValue(permission.Name),
146148
}
147-
148-
// Update state.
149-
diags = resp.State.Set(ctx, &state)
149+
diags = resp.State.Set(ctx, state)
150150
resp.Diagnostics.Append(diags...)
151151
if resp.Diagnostics.HasError() {
152152
return

internal/provider/user_resource.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (*userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
5151
Description: "Manages a Managed User.",
5252
Attributes: map[string]schema.Attribute{
5353
"id": schema.StringAttribute{
54-
Description: "User's username.",
54+
Description: "Username of the User.",
5555
Computed: true,
5656
PlanModifiers: []planmodifier.String{
5757
stringplanmodifier.UseStateForUnknown(),
@@ -88,7 +88,7 @@ func (*userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
8888
Computed: true,
8989
},
9090
"password": schema.StringAttribute{
91-
Description: "Updated password to set for the user.",
91+
Description: "Updated password to set for the User.",
9292
Sensitive: true,
9393
Computed: true,
9494
Optional: true,
@@ -200,13 +200,6 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
200200
)
201201
return
202202
}
203-
if user == nil {
204-
resp.Diagnostics.AddError(
205-
"Unable to locate managed user",
206-
"Could not find managed user with username: "+username,
207-
)
208-
return
209-
}
210203
newState := userResourceModel{
211204
ID: types.StringValue(user.Username),
212205
Username: types.StringValue(user.Username),
@@ -219,14 +212,14 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
219212
}
220213

221214
// Update state.
222-
diags = resp.State.Set(ctx, &newState)
215+
diags = resp.State.Set(ctx, newState)
223216
resp.Diagnostics.Append(diags...)
224217
if resp.Diagnostics.HasError() {
225218
return
226219
}
227220
tflog.Debug(ctx, "Read Managed User", map[string]any{
228221
"id": state.ID.ValueString(),
229-
"username": state.ID.ValueString(),
222+
"username": state.Username.ValueString(),
230223
"fullname": state.Fullname.ValueString(),
231224
"email": state.Email.ValueString(),
232225
"password": state.Password.ValueString(),
@@ -322,7 +315,14 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
322315

323316
// Execute.
324317
tflog.Debug(ctx, "Deleting Managed User", map[string]any{
325-
"id": user.Username,
318+
"id": user.Username,
319+
"username": state.Username.ValueString(),
320+
"fullname": state.Fullname.ValueString(),
321+
"email": state.Email.ValueString(),
322+
"password": state.Password.ValueString(),
323+
"suspended": state.Suspended.ValueBool(),
324+
"force_password_change": state.ForcePasswordChange.ValueBool(),
325+
"password_expires": state.PasswordExpires.ValueBool(),
326326
})
327327
err := r.client.User.DeleteManaged(ctx, user)
328328
if err != nil {
@@ -333,7 +333,14 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
333333
return
334334
}
335335
tflog.Debug(ctx, "Deleted Managed User", map[string]any{
336-
"id": state.ID.ValueString(),
336+
"id": state.ID.ValueString(),
337+
"username": state.Username.ValueString(),
338+
"fullname": state.Fullname.ValueString(),
339+
"email": state.Email.ValueString(),
340+
"password": state.Password.ValueString(),
341+
"suspended": state.Suspended.ValueBool(),
342+
"force_password_change": state.ForcePasswordChange.ValueBool(),
343+
"password_expires": state.PasswordExpires.ValueBool(),
337344
})
338345
}
339346

internal/provider/user_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "dependencytrack_user" "test" {
2121
}
2222
`,
2323
Check: resource.ComposeAggregateTestCheckFunc(
24-
resource.TestCheckResourceAttrSet("dependencytrack_user.test", "id"),
24+
resource.TestCheckResourceAttr("dependencytrack_user.test", "id", "Test_Username"),
2525
resource.TestCheckResourceAttr("dependencytrack_user.test", "username", "Test_Username"),
2626
resource.TestCheckResourceAttr("dependencytrack_user.test", "fullname", "Test_Fullname"),
2727
resource.TestCheckResourceAttr("dependencytrack_user.test", "email", "Test_Email@example.com"),
@@ -49,7 +49,7 @@ resource "dependencytrack_user" "test" {
4949
}
5050
`,
5151
Check: resource.ComposeAggregateTestCheckFunc(
52-
resource.TestCheckResourceAttrSet("dependencytrack_user.test", "id"),
52+
resource.TestCheckResourceAttr("dependencytrack_user.test", "id", "Test_Username"),
5353
resource.TestCheckResourceAttr("dependencytrack_user.test", "username", "Test_Username"),
5454
resource.TestCheckResourceAttr("dependencytrack_user.test", "fullname", "Test_Fullname_With_Change"),
5555
resource.TestCheckResourceAttr("dependencytrack_user.test", "email", "Test_Email@example.com"),

internal/provider/user_team_resource.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *userTeamResource) Create(ctx context.Context, req resource.CreateReques
9393
Username: types.StringValue(user.Username),
9494
TeamID: types.StringValue(team.String()),
9595
}
96-
diags = resp.State.Set(ctx, &state)
96+
diags = resp.State.Set(ctx, state)
9797
resp.Diagnostics.Append(diags...)
9898
if resp.Diagnostics.HasError() {
9999
return
@@ -137,9 +137,7 @@ func (r *userTeamResource) Read(ctx context.Context, req resource.ReadRequest, r
137137
)
138138
return
139139
}
140-
team, err := Find(user.Teams, func(team dtrack.Team) bool {
141-
return team.UUID == teamID
142-
})
140+
team, err := Find(user.Teams, func(team dtrack.Team) bool { return team.UUID == teamID })
143141
if err != nil {
144142
resp.Diagnostics.AddError(
145143
"Within Read, unable to identify user team membership",
@@ -152,7 +150,7 @@ func (r *userTeamResource) Read(ctx context.Context, req resource.ReadRequest, r
152150
Username: types.StringValue(user.Username),
153151
TeamID: types.StringValue(team.UUID.String()),
154152
}
155-
diags = resp.State.Set(ctx, &state)
153+
diags = resp.State.Set(ctx, state)
156154
resp.Diagnostics.Append(diags...)
157155
if resp.Diagnostics.HasError() {
158156
return
@@ -166,7 +164,6 @@ func (r *userTeamResource) Read(ctx context.Context, req resource.ReadRequest, r
166164
func (*userTeamResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
167165
// Nothing to Update. This resource only has Create, Delete actions.
168166
// Verifies that stored state is conformant to model.
169-
170167
var plan userTeamResourceModel
171168
diags := req.Plan.Get(ctx, &plan)
172169
resp.Diagnostics.Append(diags...)

0 commit comments

Comments
 (0)