From 043f1d6331434b408434a64c85da33a7ee7d4528 Mon Sep 17 00:00:00 2001 From: GokceGK <161626272+GokceGK@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:41:49 +0200 Subject: [PATCH] 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 --- docs/resources/mongodbflex_user.md | 1 + docs/resources/postgresflex_user.md | 1 + stackit/internal/services/mongodbflex/user/resource.go | 10 ++++++++-- .../services/mongodbflex/user/resource_test.go | 5 +++++ .../internal/services/postgresflex/user/resource.go | 10 ++++++++-- .../services/postgresflex/user/resource_test.go | 5 +++++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/resources/mongodbflex_user.md b/docs/resources/mongodbflex_user.md index 0510c8a3..517c718b 100644 --- a/docs/resources/mongodbflex_user.md +++ b/docs/resources/mongodbflex_user.md @@ -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. diff --git a/docs/resources/postgresflex_user.md b/docs/resources/postgresflex_user.md index b3c9dd56..577901c4 100644 --- a/docs/resources/postgresflex_user.md +++ b/docs/resources/postgresflex_user.md @@ -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. diff --git a/stackit/internal/services/mongodbflex/user/resource.go b/stackit/internal/services/mongodbflex/user/resource.go index 90f38a67..0d0a191d 100644 --- a/stackit/internal/services/mongodbflex/user/resource.go +++ b/stackit/internal/services/mongodbflex/user/resource.go @@ -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 } diff --git a/stackit/internal/services/mongodbflex/user/resource_test.go b/stackit/internal/services/mongodbflex/user/resource_test.go index ef780f5c..69dcc396 100644 --- a/stackit/internal/services/mongodbflex/user/resource_test.go +++ b/stackit/internal/services/mongodbflex/user/resource_test.go @@ -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, }, diff --git a/stackit/internal/services/postgresflex/user/resource.go b/stackit/internal/services/postgresflex/user/resource.go index fc0ad9ca..9c0dc824 100644 --- a/stackit/internal/services/postgresflex/user/resource.go +++ b/stackit/internal/services/postgresflex/user/resource.go @@ -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 } diff --git a/stackit/internal/services/postgresflex/user/resource_test.go b/stackit/internal/services/postgresflex/user/resource_test.go index 6f834d84..0126b86d 100644 --- a/stackit/internal/services/postgresflex/user/resource_test.go +++ b/stackit/internal/services/postgresflex/user/resource_test.go @@ -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, },