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
This commit is contained in:
GokceGK 2024-08-23 09:41:49 +02:00 committed by GitHub
parent a73706d82f
commit 043f1d6331
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 4 deletions

View file

@ -42,4 +42,5 @@ resource "stackit_mongodbflex_user" "example" {
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`,`user_id`".
- `password` (String, Sensitive)
- `port` (Number)
- `uri` (String, Sensitive)
- `user_id` (String) User ID.

View file

@ -37,4 +37,5 @@ resource "stackit_postgresflex_user" "example" {
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`,`user_id`".
- `password` (String, Sensitive)
- `port` (Number)
- `uri` (String, Sensitive)
- `user_id` (String) User ID.

View file

@ -42,6 +42,7 @@ type Model struct {
Password types.String `tfsdk:"password"`
Host types.String `tfsdk:"host"`
Port types.Int64 `tfsdk:"port"`
Uri types.String `tfsdk:"uri"`
}
// NewUserResource is a helper function to simplify the provider implementation.
@ -179,6 +180,10 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
"port": schema.Int64Attribute{
Computed: true,
},
"uri": schema.StringAttribute{
Computed: true,
Sensitive: true,
},
},
}
}
@ -329,8 +334,8 @@ func (r *userResource) ImportState(ctx context.Context, req resource.ImportState
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), idParts[2])...)
core.LogAndAddWarning(ctx, &resp.Diagnostics,
"MongoDB Flex user imported with empty password",
"The user password is not imported as it is only available upon creation of a new user. The password field will be empty.",
"MongoDB Flex user imported with empty password and empty uri",
"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.",
)
tflog.Info(ctx, "MongoDB Flex user state imported")
}
@ -380,6 +385,7 @@ func mapFieldsCreate(userResp *mongodbflex.CreateUserResponse, model *Model) err
}
model.Host = types.StringPointerValue(user.Host)
model.Port = types.Int64PointerValue(user.Port)
model.Uri = types.StringPointerValue(user.Uri)
return nil
}

View file

@ -36,6 +36,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue(""),
Host: types.StringNull(),
Port: types.Int64Null(),
Uri: types.StringNull(),
},
true,
},
@ -54,6 +55,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: utils.Ptr("password"),
Host: utils.Ptr("host"),
Port: utils.Ptr(int64(1234)),
Uri: utils.Ptr("uri"),
},
},
Model{
@ -71,6 +73,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue("password"),
Host: types.StringValue("host"),
Port: types.Int64Value(1234),
Uri: types.StringValue("uri"),
},
true,
},
@ -85,6 +88,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: utils.Ptr(""),
Host: nil,
Port: utils.Ptr(int64(2123456789)),
Uri: nil,
},
},
Model{
@ -98,6 +102,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue(""),
Host: types.StringNull(),
Port: types.Int64Value(2123456789),
Uri: types.StringNull(),
},
true,
},

View file

@ -46,6 +46,7 @@ type Model struct {
Password types.String `tfsdk:"password"`
Host types.String `tfsdk:"host"`
Port types.Int64 `tfsdk:"port"`
Uri types.String `tfsdk:"uri"`
}
// NewUserResource is a helper function to simplify the provider implementation.
@ -185,6 +186,10 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
"port": schema.Int64Attribute{
Computed: true,
},
"uri": schema.StringAttribute{
Computed: true,
Sensitive: true,
},
},
}
}
@ -339,8 +344,8 @@ func (r *userResource) ImportState(ctx context.Context, req resource.ImportState
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), idParts[2])...)
core.LogAndAddWarning(ctx, &resp.Diagnostics,
"Postgresflex user imported with empty password",
"The user password is not imported as it is only available upon creation of a new user. The password field will be empty.",
"Postgresflex user imported with empty password and empty uri",
"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.",
)
tflog.Info(ctx, "Postgresflex user state imported")
}
@ -389,6 +394,7 @@ func mapFieldsCreate(userResp *postgresflex.CreateUserResponse, model *Model) er
}
model.Host = types.StringPointerValue(user.Host)
model.Port = types.Int64PointerValue(user.Port)
model.Uri = types.StringPointerValue(user.Uri)
return nil
}

View file

@ -35,6 +35,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue(""),
Host: types.StringNull(),
Port: types.Int64Null(),
Uri: types.StringNull(),
},
true,
},
@ -52,6 +53,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: utils.Ptr("password"),
Host: utils.Ptr("host"),
Port: utils.Ptr(int64(1234)),
Uri: utils.Ptr("uri"),
},
},
Model{
@ -68,6 +70,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue("password"),
Host: types.StringValue("host"),
Port: types.Int64Value(1234),
Uri: types.StringValue("uri"),
},
true,
},
@ -81,6 +84,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: utils.Ptr(""),
Host: nil,
Port: utils.Ptr(int64(2123456789)),
Uri: nil,
},
},
Model{
@ -93,6 +97,7 @@ func TestMapFieldsCreate(t *testing.T) {
Password: types.StringValue(""),
Host: types.StringNull(),
Port: types.Int64Value(2123456789),
Uri: types.StringNull(),
},
true,
},