Skip to content

Commit 043f1d6

Browse files
authored
Add uri to user resources for MongoDB Flex and PostgreSQL Flex (#512)
* add uri to mongodb user resource * add uri to postgresflex user resource * update docs * extend warning about empty uri * extend warning about empty uri
1 parent a73706d commit 043f1d6

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

docs/resources/mongodbflex_user.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ resource "stackit_mongodbflex_user" "example" {
4242
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`,`user_id`".
4343
- `password` (String, Sensitive)
4444
- `port` (Number)
45+
- `uri` (String, Sensitive)
4546
- `user_id` (String) User ID.

docs/resources/postgresflex_user.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ resource "stackit_postgresflex_user" "example" {
3737
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`,`user_id`".
3838
- `password` (String, Sensitive)
3939
- `port` (Number)
40+
- `uri` (String, Sensitive)
4041
- `user_id` (String) User ID.

stackit/internal/services/mongodbflex/user/resource.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Model struct {
4242
Password types.String `tfsdk:"password"`
4343
Host types.String `tfsdk:"host"`
4444
Port types.Int64 `tfsdk:"port"`
45+
Uri types.String `tfsdk:"uri"`
4546
}
4647

4748
// NewUserResource is a helper function to simplify the provider implementation.
@@ -179,6 +180,10 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
179180
"port": schema.Int64Attribute{
180181
Computed: true,
181182
},
183+
"uri": schema.StringAttribute{
184+
Computed: true,
185+
Sensitive: true,
186+
},
182187
},
183188
}
184189
}
@@ -329,8 +334,8 @@ func (r *userResource) ImportState(ctx context.Context, req resource.ImportState
329334
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
330335
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), idParts[2])...)
331336
core.LogAndAddWarning(ctx, &resp.Diagnostics,
332-
"MongoDB Flex user imported with empty password",
333-
"The user password is not imported as it is only available upon creation of a new user. The password field will be empty.",
337+
"MongoDB Flex user imported with empty password and empty uri",
338+
"The user password and uri are not imported as they are only available upon creation of a new user. The password and uri fields will be empty.",
334339
)
335340
tflog.Info(ctx, "MongoDB Flex user state imported")
336341
}
@@ -380,6 +385,7 @@ func mapFieldsCreate(userResp *mongodbflex.CreateUserResponse, model *Model) err
380385
}
381386
model.Host = types.StringPointerValue(user.Host)
382387
model.Port = types.Int64PointerValue(user.Port)
388+
model.Uri = types.StringPointerValue(user.Uri)
383389
return nil
384390
}
385391

stackit/internal/services/mongodbflex/user/resource_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestMapFieldsCreate(t *testing.T) {
3636
Password: types.StringValue(""),
3737
Host: types.StringNull(),
3838
Port: types.Int64Null(),
39+
Uri: types.StringNull(),
3940
},
4041
true,
4142
},
@@ -54,6 +55,7 @@ func TestMapFieldsCreate(t *testing.T) {
5455
Password: utils.Ptr("password"),
5556
Host: utils.Ptr("host"),
5657
Port: utils.Ptr(int64(1234)),
58+
Uri: utils.Ptr("uri"),
5759
},
5860
},
5961
Model{
@@ -71,6 +73,7 @@ func TestMapFieldsCreate(t *testing.T) {
7173
Password: types.StringValue("password"),
7274
Host: types.StringValue("host"),
7375
Port: types.Int64Value(1234),
76+
Uri: types.StringValue("uri"),
7477
},
7578
true,
7679
},
@@ -85,6 +88,7 @@ func TestMapFieldsCreate(t *testing.T) {
8588
Password: utils.Ptr(""),
8689
Host: nil,
8790
Port: utils.Ptr(int64(2123456789)),
91+
Uri: nil,
8892
},
8993
},
9094
Model{
@@ -98,6 +102,7 @@ func TestMapFieldsCreate(t *testing.T) {
98102
Password: types.StringValue(""),
99103
Host: types.StringNull(),
100104
Port: types.Int64Value(2123456789),
105+
Uri: types.StringNull(),
101106
},
102107
true,
103108
},

stackit/internal/services/postgresflex/user/resource.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Model struct {
4646
Password types.String `tfsdk:"password"`
4747
Host types.String `tfsdk:"host"`
4848
Port types.Int64 `tfsdk:"port"`
49+
Uri types.String `tfsdk:"uri"`
4950
}
5051

5152
// NewUserResource is a helper function to simplify the provider implementation.
@@ -185,6 +186,10 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
185186
"port": schema.Int64Attribute{
186187
Computed: true,
187188
},
189+
"uri": schema.StringAttribute{
190+
Computed: true,
191+
Sensitive: true,
192+
},
188193
},
189194
}
190195
}
@@ -339,8 +344,8 @@ func (r *userResource) ImportState(ctx context.Context, req resource.ImportState
339344
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
340345
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), idParts[2])...)
341346
core.LogAndAddWarning(ctx, &resp.Diagnostics,
342-
"Postgresflex user imported with empty password",
343-
"The user password is not imported as it is only available upon creation of a new user. The password field will be empty.",
347+
"Postgresflex user imported with empty password and empty uri",
348+
"The user password and uri are not imported as they are only available upon creation of a new user. The password and uri fields will be empty.",
344349
)
345350
tflog.Info(ctx, "Postgresflex user state imported")
346351
}
@@ -389,6 +394,7 @@ func mapFieldsCreate(userResp *postgresflex.CreateUserResponse, model *Model) er
389394
}
390395
model.Host = types.StringPointerValue(user.Host)
391396
model.Port = types.Int64PointerValue(user.Port)
397+
model.Uri = types.StringPointerValue(user.Uri)
392398
return nil
393399
}
394400

stackit/internal/services/postgresflex/user/resource_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestMapFieldsCreate(t *testing.T) {
3535
Password: types.StringValue(""),
3636
Host: types.StringNull(),
3737
Port: types.Int64Null(),
38+
Uri: types.StringNull(),
3839
},
3940
true,
4041
},
@@ -52,6 +53,7 @@ func TestMapFieldsCreate(t *testing.T) {
5253
Password: utils.Ptr("password"),
5354
Host: utils.Ptr("host"),
5455
Port: utils.Ptr(int64(1234)),
56+
Uri: utils.Ptr("uri"),
5557
},
5658
},
5759
Model{
@@ -68,6 +70,7 @@ func TestMapFieldsCreate(t *testing.T) {
6870
Password: types.StringValue("password"),
6971
Host: types.StringValue("host"),
7072
Port: types.Int64Value(1234),
73+
Uri: types.StringValue("uri"),
7174
},
7275
true,
7376
},
@@ -81,6 +84,7 @@ func TestMapFieldsCreate(t *testing.T) {
8184
Password: utils.Ptr(""),
8285
Host: nil,
8386
Port: utils.Ptr(int64(2123456789)),
87+
Uri: nil,
8488
},
8589
},
8690
Model{
@@ -93,6 +97,7 @@ func TestMapFieldsCreate(t *testing.T) {
9397
Password: types.StringValue(""),
9498
Host: types.StringNull(),
9599
Port: types.Int64Value(2123456789),
100+
Uri: types.StringNull(),
96101
},
97102
true,
98103
},

0 commit comments

Comments
 (0)