From fc1e115ba1f8b02790b499f2dc0ad3d0485a5edd Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Fri, 22 Mar 2024 12:32:34 +0000 Subject: [PATCH 01/25] feat: resource tag create --- examples/resources/biganimal_tag/resource.tf | 20 ++++ pkg/api/api.go | 5 + pkg/api/tag_client.go | 63 ++++++++++ pkg/models/common/api/tag_request.go | 6 + pkg/models/common/api/tag_response.go | 7 ++ pkg/models/common/terraform/tag.go | 9 ++ pkg/provider/provider.go | 1 + pkg/provider/resource_tag.go | 120 +++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100644 examples/resources/biganimal_tag/resource.tf create mode 100644 pkg/api/tag_client.go create mode 100644 pkg/models/common/api/tag_request.go create mode 100644 pkg/models/common/api/tag_response.go create mode 100644 pkg/models/common/terraform/tag.go create mode 100644 pkg/provider/resource_tag.go diff --git a/examples/resources/biganimal_tag/resource.tf b/examples/resources/biganimal_tag/resource.tf new file mode 100644 index 00000000..e11d0a89 --- /dev/null +++ b/examples/resources/biganimal_tag/resource.tf @@ -0,0 +1,20 @@ +terraform { + required_providers { + biganimal = { + source = "EnterpriseDB/biganimal" + version = "0.8.1" + } + random = { + source = "hashicorp/random" + version = "3.6.0" + } + } +} + +resource "biganimal_tag" "tag" { + tag_name = "tag-name" + // The default colors to choose from are: + // magenta, red, orange, yellow, green, teal, blue, indigo, purple and grey + // you can also use a custom hex color code e.g. #e34545 + color = "blue" +} \ No newline at end of file diff --git a/pkg/api/api.go b/pkg/api/api.go index 9df4b531..fd0f36c7 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -55,6 +55,11 @@ func (api *API) CloudProviderClient() *CloudProviderClient { return c } +func (api *API) TagClient() *TagClient { + c := NewTagClient(*api) + return c +} + func BuildAPI(meta any) *API { api, ok := meta.(*API) if !ok { diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go new file mode 100644 index 00000000..9e4b8f5d --- /dev/null +++ b/pkg/api/tag_client.go @@ -0,0 +1,63 @@ +package api + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "time" + + "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" +) + +type TagClient struct { + API +} + +func NewTagClient(api API) *TagClient { + httpClient := http.Client{ + Timeout: 60 * time.Second, + } + + api.HTTPClient = httpClient + tc := TagClient{API: api} + return &tc +} + +func (tc TagClient) Create(ctx context.Context, tag api.TagRequest) (*string, error) { + response := struct { + Data struct { + TagId string `json:"tagId"` + } `json:"data"` + }{} + + b, err := json.Marshal(tag) + if err != nil { + return nil, err + } + + body, err := tc.doRequest(ctx, http.MethodPost, "tags", bytes.NewBuffer(b)) + if err != nil { + return nil, err + } + + err = json.Unmarshal(body, &response) + return &response.Data.TagId, err +} + +func (c ClusterClient) GetTags(ctx context.Context) ([]api.TagResponse, error) { + response := struct { + Data []api.TagResponse `json:"data"` + }{} + + url := fmt.Sprintf("api/v3/tags") + body, err := c.doRequest(ctx, http.MethodGet, url, nil) + if err != nil { + return response.Data, err + } + + err = json.Unmarshal(body, &response) + + return response.Data, err +} diff --git a/pkg/models/common/api/tag_request.go b/pkg/models/common/api/tag_request.go new file mode 100644 index 00000000..6bb29cda --- /dev/null +++ b/pkg/models/common/api/tag_request.go @@ -0,0 +1,6 @@ +package api + +type TagRequest struct { + Color *string `json:"color,omitempty"` + TagName string `json:"tagName"` +} diff --git a/pkg/models/common/api/tag_response.go b/pkg/models/common/api/tag_response.go new file mode 100644 index 00000000..bcc38585 --- /dev/null +++ b/pkg/models/common/api/tag_response.go @@ -0,0 +1,7 @@ +package api + +type TagResponse struct { + Color *string `json:"color,omitempty"` + TagId string `json:"tagId"` + TagName string `json:"tagName"` +} diff --git a/pkg/models/common/terraform/tag.go b/pkg/models/common/terraform/tag.go new file mode 100644 index 00000000..36788c20 --- /dev/null +++ b/pkg/models/common/terraform/tag.go @@ -0,0 +1,9 @@ +package terraform + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type Tag struct { + TagId types.String `tfsdk:"tag_id"` + TagName types.String `tfsdk:"tag_name"` + Color types.String `tfsdk:"color"` +} diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 048a9a8b..ad893575 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -203,5 +203,6 @@ func (b bigAnimalProvider) Resources(ctx context.Context) []func() resource.Reso NewPgdResource, NewRegionResource, NewClusterResource, + NewTagResource, } } diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go new file mode 100644 index 00000000..f9ab9510 --- /dev/null +++ b/pkg/provider/resource_tag.go @@ -0,0 +1,120 @@ +package provider + +import ( + "context" + + "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/api" + commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var ( + _ resource.Resource = &tagResource{} + _ resource.ResourceWithConfigure = &tagResource{} +) + +type TagResourceModel struct { + ID types.String `tfsdk:"id"` + TagId types.String `tfsdk:"tag_id"` + TagName types.String `tfsdk:"tag_name"` + Color types.String `tfsdk:"color"` + + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type tagResource struct { + client *api.TagClient +} + +func (tr *tagResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + tr.client = req.ProviderData.(*api.API).TagClient() +} + +func (tr *tagResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_tag" +} + +func (tf *tagResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "The PGD cluster data source describes a BigAnimal cluster. The data source requires your PGD cluster name.", + Blocks: map[string]schema.Block{ + "timeouts": timeouts.Block(ctx, + timeouts.Opts{Create: true, Delete: true, Update: true}), + }, + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "color": schema.StringAttribute{ + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + } +} + +func (tr *tagResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var config TagResourceModel + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tagId, err := tr.client.Create(ctx, commonApi.TagRequest{ + Color: config.Color.ValueStringPointer(), + TagName: config.TagName.ValueString(), + }) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error creating tag", err.Error()) + } + return + } + + config.TagId = types.StringPointerValue(tagId) + + resp.Diagnostics.Append(resp.State.Set(ctx, config)...) +} + +func (tr *tagResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +} + +func (tr *tagResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +} + +func (tr *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +} + +func (tr *tagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +} + +func NewTagResource() resource.Resource { + return &tagResource{} +} From b06819a48ac4ba58119af10dd791aee6a6c6d6cf Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Fri, 22 Mar 2024 12:40:56 +0000 Subject: [PATCH 02/25] fix: lint errors --- examples/resources/biganimal_tag/resource.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/resources/biganimal_tag/resource.tf b/examples/resources/biganimal_tag/resource.tf index e11d0a89..a5623033 100644 --- a/examples/resources/biganimal_tag/resource.tf +++ b/examples/resources/biganimal_tag/resource.tf @@ -17,4 +17,4 @@ resource "biganimal_tag" "tag" { // magenta, red, orange, yellow, green, teal, blue, indigo, purple and grey // you can also use a custom hex color code e.g. #e34545 color = "blue" -} \ No newline at end of file +} From bddbab4c2ea0a979ea510840e528a3f7761f45ed Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Fri, 22 Mar 2024 12:44:10 +0000 Subject: [PATCH 03/25] fix: lint errors --- examples/resources/biganimal_tag/resource.tf | 2 +- pkg/api/tag_client.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/resources/biganimal_tag/resource.tf b/examples/resources/biganimal_tag/resource.tf index a5623033..e5697413 100644 --- a/examples/resources/biganimal_tag/resource.tf +++ b/examples/resources/biganimal_tag/resource.tf @@ -16,5 +16,5 @@ resource "biganimal_tag" "tag" { // The default colors to choose from are: // magenta, red, orange, yellow, green, teal, blue, indigo, purple and grey // you can also use a custom hex color code e.g. #e34545 - color = "blue" + color = "blue" } diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index 9e4b8f5d..bf7ca927 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "fmt" "net/http" "time" @@ -51,8 +50,7 @@ func (c ClusterClient) GetTags(ctx context.Context) ([]api.TagResponse, error) { Data []api.TagResponse `json:"data"` }{} - url := fmt.Sprintf("api/v3/tags") - body, err := c.doRequest(ctx, http.MethodGet, url, nil) + body, err := c.doRequest(ctx, http.MethodGet, "tags", nil) if err != nil { return response.Data, err } From 07ba0795eb4506de2c61fd23f61f370f0b1f1337 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 28 Mar 2024 16:41:34 +0000 Subject: [PATCH 04/25] refactor: refactor tag client --- pkg/api/tag_client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index bf7ca927..4ad318d5 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -24,14 +24,14 @@ func NewTagClient(api API) *TagClient { return &tc } -func (tc TagClient) Create(ctx context.Context, tag api.TagRequest) (*string, error) { +func (tc TagClient) Create(ctx context.Context, tagReq api.TagRequest) (*string, error) { response := struct { Data struct { TagId string `json:"tagId"` } `json:"data"` }{} - b, err := json.Marshal(tag) + b, err := json.Marshal(tagReq) if err != nil { return nil, err } @@ -45,12 +45,12 @@ func (tc TagClient) Create(ctx context.Context, tag api.TagRequest) (*string, er return &response.Data.TagId, err } -func (c ClusterClient) GetTags(ctx context.Context) ([]api.TagResponse, error) { +func (tr TagClient) List(ctx context.Context) ([]api.TagResponse, error) { response := struct { Data []api.TagResponse `json:"data"` }{} - body, err := c.doRequest(ctx, http.MethodGet, "tags", nil) + body, err := tr.doRequest(ctx, http.MethodGet, "tags", nil) if err != nil { return response.Data, err } From 714a3657c9f25ffedfc5a20b9b437c842407f96e Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 28 Mar 2024 16:39:42 +0000 Subject: [PATCH 05/25] feat: tag update --- pkg/api/tag_client.go | 50 ++++++++++++++++++++++++++++--- pkg/provider/resource_tag.go | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index bf7ca927..0264be45 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "fmt" "net/http" "time" @@ -24,14 +25,14 @@ func NewTagClient(api API) *TagClient { return &tc } -func (tc TagClient) Create(ctx context.Context, tag api.TagRequest) (*string, error) { +func (tc TagClient) Create(ctx context.Context, tagReq api.TagRequest) (*string, error) { response := struct { Data struct { TagId string `json:"tagId"` } `json:"data"` }{} - b, err := json.Marshal(tag) + b, err := json.Marshal(tagReq) if err != nil { return nil, err } @@ -45,12 +46,53 @@ func (tc TagClient) Create(ctx context.Context, tag api.TagRequest) (*string, er return &response.Data.TagId, err } -func (c ClusterClient) GetTags(ctx context.Context) ([]api.TagResponse, error) { +func (tc TagClient) Get(ctx context.Context, tagId string) (api.TagResponse, error) { + response := struct { + Data api.TagResponse `json:"data"` + }{} + + url := fmt.Sprintf("tags/%s", tagId) + + body, err := tc.doRequest(ctx, http.MethodGet, url, nil) + if err != nil { + return response.Data, err + } + + err = json.Unmarshal(body, &response) + + return response.Data, err +} + +func (tc TagClient) Update(ctx context.Context, tagId string, tagReq api.TagRequest) (*string, error) { + response := struct { + Data struct { + TagId string `json:"tagId"` + } `json:"data"` + }{} + + url := fmt.Sprintf("tags/%s", tagId) + + b, err := json.Marshal(tagReq) + if err != nil { + return nil, err + } + + body, err := tc.doRequest(ctx, http.MethodPut, url, bytes.NewBuffer(b)) + if err != nil { + return nil, err + } + + err = json.Unmarshal(body, &response) + + return &response.Data.TagId, err +} + +func (tc TagClient) List(ctx context.Context) ([]api.TagResponse, error) { response := struct { Data []api.TagResponse `json:"data"` }{} - body, err := c.doRequest(ctx, http.MethodGet, "tags", nil) + body, err := tc.doRequest(ctx, http.MethodGet, "tags", nil) if err != nil { return response.Data, err } diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go index f9ab9510..bcc8fe2e 100644 --- a/pkg/provider/resource_tag.go +++ b/pkg/provider/resource_tag.go @@ -98,15 +98,72 @@ func (tr *tagResource) Create(ctx context.Context, req resource.CreateRequest, r return } + config.ID = types.StringPointerValue(tagId) config.TagId = types.StringPointerValue(tagId) resp.Diagnostics.Append(resp.State.Set(ctx, config)...) } func (tr *tagResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TagResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + err := tr.read(ctx, &state) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error reading tag", err.Error()) + } + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, state)...) +} + +func (tr *tagResource) read(ctx context.Context, resource *TagResourceModel) error { + tagResp, err := tr.client.Get(ctx, resource.TagId.ValueString()) + if err != nil { + return err + } + + resource.ID = types.StringValue(tagResp.TagId) + resource.TagId = types.StringValue(tagResp.TagId) + resource.TagName = types.StringValue(tagResp.TagName) + resource.Color = types.StringPointerValue(tagResp.Color) + return nil } func (tr *tagResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan TagResourceModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + _, err := tr.client.Update(ctx, plan.TagId.ValueString(), commonApi.TagRequest{ + Color: plan.Color.ValueStringPointer(), + TagName: plan.TagName.ValueString(), + }) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error updating tag", err.Error()) + } + return + } + + err = tr.read(ctx, &plan) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error reading tag", err.Error()) + } + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, plan)...) } func (tr *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { From bdf1710193b0680965bc539e91ad4da5c6dd8089 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 2 Apr 2024 11:12:30 +0100 Subject: [PATCH 06/25] refactor: refactor tag client --- pkg/api/tag_client.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index 4ad318d5..48ab0b34 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "fmt" "net/http" "time" @@ -45,12 +46,29 @@ func (tc TagClient) Create(ctx context.Context, tagReq api.TagRequest) (*string, return &response.Data.TagId, err } -func (tr TagClient) List(ctx context.Context) ([]api.TagResponse, error) { +func (tc TagClient) Get(ctx context.Context, tagId string) (api.TagResponse, error) { + response := struct { + Data api.TagResponse `json:"data"` + }{} + + url := fmt.Sprintf("tags/%s", tagId) + + body, err := tc.doRequest(ctx, http.MethodGet, url, nil) + if err != nil { + return response.Data, err + } + + err = json.Unmarshal(body, &response) + + return response.Data, err +} + +func (tc TagClient) List(ctx context.Context) ([]api.TagResponse, error) { response := struct { Data []api.TagResponse `json:"data"` }{} - body, err := tr.doRequest(ctx, http.MethodGet, "tags", nil) + body, err := tc.doRequest(ctx, http.MethodGet, "tags", nil) if err != nil { return response.Data, err } From cd08fe8342cd88ea6438287ac432430481ae657c Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 2 Apr 2024 11:20:51 +0100 Subject: [PATCH 07/25] feat: changed tag description --- pkg/provider/resource_tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go index f9ab9510..1fd14a8f 100644 --- a/pkg/provider/resource_tag.go +++ b/pkg/provider/resource_tag.go @@ -45,7 +45,7 @@ func (tr *tagResource) Metadata(ctx context.Context, req resource.MetadataReques func (tf *tagResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: "The PGD cluster data source describes a BigAnimal cluster. The data source requires your PGD cluster name.", + MarkdownDescription: "Tags will enable users to categorize and organize resources across types and improve the efficiency of resource retrieval", Blocks: map[string]schema.Block{ "timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Delete: true, Update: true}), From 6a0235e6b46b8e975d3585bf31a160d5b0aacbc0 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 2 Apr 2024 12:26:53 +0100 Subject: [PATCH 08/25] feat: tag import --- examples/resources/biganimal_tag/import.sh | 2 ++ pkg/provider/resource_tag.go | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 examples/resources/biganimal_tag/import.sh diff --git a/examples/resources/biganimal_tag/import.sh b/examples/resources/biganimal_tag/import.sh new file mode 100644 index 00000000..2189401d --- /dev/null +++ b/examples/resources/biganimal_tag/import.sh @@ -0,0 +1,2 @@ +# terraform import biganimal_tag. +terraform import biganimal_tag.tag abcdefgh-abcd-abcd-abcd-abcdefghijkl \ No newline at end of file diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go index 4e145cd4..78d92fc0 100644 --- a/pkg/provider/resource_tag.go +++ b/pkg/provider/resource_tag.go @@ -6,6 +6,7 @@ import ( "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/api" commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -170,6 +171,7 @@ func (tr *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, r } func (tr *tagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("tag_id"), req.ID)...) } func NewTagResource() resource.Resource { From 67263aba7d207d1e0b0e38d2881c82b9b13af089 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 2 Apr 2024 13:04:15 +0100 Subject: [PATCH 09/25] feat: lint error --- examples/resources/biganimal_tag/import.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/resources/biganimal_tag/import.sh b/examples/resources/biganimal_tag/import.sh index 2189401d..22ed2b5e 100644 --- a/examples/resources/biganimal_tag/import.sh +++ b/examples/resources/biganimal_tag/import.sh @@ -1,2 +1,2 @@ # terraform import biganimal_tag. -terraform import biganimal_tag.tag abcdefgh-abcd-abcd-abcd-abcdefghijkl \ No newline at end of file +terraform import biganimal_tag.tag abcdefgh-abcd-abcd-abcd-abcdefghijkl From e5a74f09abbd24101f42101e6880b65970c6ccb0 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Fri, 5 Apr 2024 18:20:40 +0100 Subject: [PATCH 10/25] feat: assign tags to resources --- pkg/api/tag_client.go | 12 ++-- pkg/models/cluster.go | 1 + .../common/api/{tag_response.go => tag.go} | 2 +- pkg/models/common/api/tag_request.go | 6 -- pkg/provider/resource_cluster.go | 60 +++++++++++++++++++ pkg/provider/resource_tag.go | 4 +- 6 files changed, 70 insertions(+), 15 deletions(-) rename pkg/models/common/api/{tag_response.go => tag.go} (82%) delete mode 100644 pkg/models/common/api/tag_request.go diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index 0264be45..c7abc496 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -25,7 +25,7 @@ func NewTagClient(api API) *TagClient { return &tc } -func (tc TagClient) Create(ctx context.Context, tagReq api.TagRequest) (*string, error) { +func (tc TagClient) Create(ctx context.Context, tagReq api.Tag) (*string, error) { response := struct { Data struct { TagId string `json:"tagId"` @@ -46,9 +46,9 @@ func (tc TagClient) Create(ctx context.Context, tagReq api.TagRequest) (*string, return &response.Data.TagId, err } -func (tc TagClient) Get(ctx context.Context, tagId string) (api.TagResponse, error) { +func (tc TagClient) Get(ctx context.Context, tagId string) (api.Tag, error) { response := struct { - Data api.TagResponse `json:"data"` + Data api.Tag `json:"data"` }{} url := fmt.Sprintf("tags/%s", tagId) @@ -63,7 +63,7 @@ func (tc TagClient) Get(ctx context.Context, tagId string) (api.TagResponse, err return response.Data, err } -func (tc TagClient) Update(ctx context.Context, tagId string, tagReq api.TagRequest) (*string, error) { +func (tc TagClient) Update(ctx context.Context, tagId string, tagReq api.Tag) (*string, error) { response := struct { Data struct { TagId string `json:"tagId"` @@ -87,9 +87,9 @@ func (tc TagClient) Update(ctx context.Context, tagId string, tagReq api.TagRequ return &response.Data.TagId, err } -func (tc TagClient) List(ctx context.Context) ([]api.TagResponse, error) { +func (tc TagClient) List(ctx context.Context) ([]api.Tag, error) { response := struct { - Data []api.TagResponse `json:"data"` + Data []api.Tag `json:"data"` }{} body, err := tc.doRequest(ctx, http.MethodGet, "tags", nil) diff --git a/pkg/models/cluster.go b/pkg/models/cluster.go index 13b8be00..efbc8e23 100644 --- a/pkg/models/cluster.go +++ b/pkg/models/cluster.go @@ -176,6 +176,7 @@ type Cluster struct { SuperuserAccess *bool `json:"superuserAccess,omitempty"` Extensions *[]ClusterExtension `json:"extensions,omitempty"` PgBouncer *PgBouncer `json:"pgBouncer,omitempty"` + Tags []commonApi.Tag `json:"tags,omitempty"` } // IsHealthy checks to see if the cluster has the right condition 'biganimal.com/deployed' diff --git a/pkg/models/common/api/tag_response.go b/pkg/models/common/api/tag.go similarity index 82% rename from pkg/models/common/api/tag_response.go rename to pkg/models/common/api/tag.go index bcc38585..1c501b13 100644 --- a/pkg/models/common/api/tag_response.go +++ b/pkg/models/common/api/tag.go @@ -1,6 +1,6 @@ package api -type TagResponse struct { +type Tag struct { Color *string `json:"color,omitempty"` TagId string `json:"tagId"` TagName string `json:"tagName"` diff --git a/pkg/models/common/api/tag_request.go b/pkg/models/common/api/tag_request.go deleted file mode 100644 index 6bb29cda..00000000 --- a/pkg/models/common/api/tag_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package api - -type TagRequest struct { - Color *string `json:"color,omitempty"` - TagName string `json:"tagName"` -} diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 5500270f..7e49b943 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -73,6 +73,7 @@ type ClusterResourceModel struct { Pgvector types.Bool `tfsdk:"pgvector"` PgBouncer *PgBouncerModel `tfsdk:"pg_bouncer"` Pause types.Bool `tfsdk:"pause"` + Tags []commonTerraform.Tag `tfsdk:"tags"` Timeouts timeouts.Value `tfsdk:"timeouts"` } @@ -462,6 +463,36 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest Optional: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, }, + "tags": schema.SetNestedAttribute{ + Description: "Assign existing tags or create tags to assign to this resource", + Optional: true, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tag_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "color": schema.StringAttribute{ + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + }, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + }, }, } } @@ -829,6 +860,25 @@ func (c *clusterResource) read(ctx context.Context, tfClusterResource *ClusterRe } } + tfClusterResource.AllowedIpRanges = []AllowedIpRangesResourceModel{} + if allowedIpRanges := apiCluster.AllowedIpRanges; allowedIpRanges != nil { + for _, ipRange := range *allowedIpRanges { + tfClusterResource.AllowedIpRanges = append(tfClusterResource.AllowedIpRanges, AllowedIpRangesResourceModel{ + CidrBlock: ipRange.CidrBlock, + Description: types.StringValue(ipRange.Description), + }) + } + } + + tfClusterResource.Tags = []commonTerraform.Tag{} + for _, v := range apiCluster.Tags { + tfClusterResource.Tags = append(tfClusterResource.Tags, commonTerraform.Tag{ + TagId: types.StringValue(v.TagId), + TagName: types.StringValue(v.TagName), + Color: basetypes.NewStringPointerValue(v.Color), + }) + } + return nil } @@ -1005,6 +1055,16 @@ func generateGenericClusterModel(clusterResource ClusterResourceModel) models.Cl } } + tags := []commonApi.Tag{} + for _, tag := range clusterResource.Tags { + tags = append(tags, commonApi.Tag{ + Color: tag.Color.ValueStringPointer(), + TagId: tag.TagId.ValueString(), + TagName: tag.TagName.ValueString(), + }) + } + cluster.Tags = tags + return cluster } diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go index 78d92fc0..34359689 100644 --- a/pkg/provider/resource_tag.go +++ b/pkg/provider/resource_tag.go @@ -88,7 +88,7 @@ func (tr *tagResource) Create(ctx context.Context, req resource.CreateRequest, r return } - tagId, err := tr.client.Create(ctx, commonApi.TagRequest{ + tagId, err := tr.client.Create(ctx, commonApi.Tag{ Color: config.Color.ValueStringPointer(), TagName: config.TagName.ValueString(), }) @@ -145,7 +145,7 @@ func (tr *tagResource) Update(ctx context.Context, req resource.UpdateRequest, r return } - _, err := tr.client.Update(ctx, plan.TagId.ValueString(), commonApi.TagRequest{ + _, err := tr.client.Update(ctx, plan.TagId.ValueString(), commonApi.Tag{ Color: plan.Color.ValueStringPointer(), TagName: plan.TagName.ValueString(), }) From 7931b8baac1e0e717d227cc167e1da7b0501d9d8 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 8 Apr 2024 19:32:01 +0100 Subject: [PATCH 11/25] fix: faraway replica assign tag --- .../biganimal_faraway_replica/aws/resource.tf | 28 +++++++------------ .../azure/resource.tf | 22 ++++++--------- .../cluster_and_faraway_replica/resource.tf | 22 ++++++--------- .../biganimal_faraway_replica/gcp/resource.tf | 28 +++++++------------ .../biganimal_faraway_replica/resource.tf | 28 +++++++------------ pkg/models/cluster.go | 10 +++++++ pkg/models/common/api/tag.go | 7 +++-- pkg/provider/resource_fareplica.go | 27 +++++++++++++++++- 8 files changed, 86 insertions(+), 86 deletions(-) diff --git a/examples/resources/biganimal_faraway_replica/aws/resource.tf b/examples/resources/biganimal_faraway_replica/aws/resource.tf index da86de7c..35b4b872 100644 --- a/examples/resources/biganimal_faraway_replica/aws/resource.tf +++ b/examples/resources/biganimal_faraway_replica/aws/resource.tf @@ -42,7 +42,7 @@ resource "biganimal_faraway_replica" "faraway_replica" { } backup_retention_period = "6d" - csp_auth = true + csp_auth = false instance_type = "aws:m5.large" // only following pg_config parameters are configurable for faraway replica @@ -59,27 +59,19 @@ resource "biganimal_faraway_replica" "faraway_replica" { value = "64" } - pg_config { - name = "max_prepared_transactions" - value = "0" - } - - pg_config { - name = "max_wal_senders" - value = "10" - } - - pg_config { - name = "max_worker_processes" - value = "32" - } - - storage { volume_type = "gp3" volume_properties = "gp3" size = "4 Gi" } private_networking = false - region = "eu-west-2" + region = "ap-south-1" + + #tags { + # tag_name = "test-tag-name-1" + # color = "blue" + #} + #tags { + # tag_name = "test-tag-name-2" + #} } diff --git a/examples/resources/biganimal_faraway_replica/azure/resource.tf b/examples/resources/biganimal_faraway_replica/azure/resource.tf index 212d7379..1cf914c7 100644 --- a/examples/resources/biganimal_faraway_replica/azure/resource.tf +++ b/examples/resources/biganimal_faraway_replica/azure/resource.tf @@ -45,7 +45,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { csp_auth = false instance_type = "azure:Standard_D2s_v3" - // only following pg_config parameters are configurable for faraway replica // max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes. // it is highly recommended setting these values to be equal to or greater than the source cluster's. @@ -59,25 +58,20 @@ resource "biganimal_faraway_replica" "faraway_replica" { name = "max_locks_per_transaction" value = "64" } - pg_config { - name = "max_prepared_transactions" - value = "0" - } - pg_config { - name = "max_wal_senders" - value = "10" - } - pg_config { - name = "max_worker_processes" - value = "32" - } storage { volume_type = "azurepremiumstorage" volume_properties = "P1" size = "4 Gi" } - private_networking = false region = "australiaeast" + + #tags { + # tag_name = "test-tag-name-1" + # color = "blue" + #} + #tags { + # tag_name = "test-tag-name-2" + #} } diff --git a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf index e3635613..5cc0997c 100644 --- a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf @@ -75,7 +75,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { csp_auth = false instance_type = "azure:Standard_D2s_v3" - // only following pg_config parameters are configurable for faraway replica // max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes. // it is highly recommended setting these values to be equal to or greater than the source cluster's. @@ -89,25 +88,20 @@ resource "biganimal_faraway_replica" "faraway_replica" { name = "max_locks_per_transaction" value = "64" } - pg_config { - name = "max_prepared_transactions" - value = "0" - } - pg_config { - name = "max_wal_senders" - value = "10" - } - pg_config { - name = "max_worker_processes" - value = "32" - } storage { volume_type = "azurepremiumstorage" volume_properties = "P1" size = "4 Gi" } - private_networking = false region = "centralindia" + + #tags { + # tag_name = "test-tag-name-1" + # color = "blue" + #} + #tags { + # tag_name = "test-tag-name-2" + #} } diff --git a/examples/resources/biganimal_faraway_replica/gcp/resource.tf b/examples/resources/biganimal_faraway_replica/gcp/resource.tf index 53214877..bcaa9093 100644 --- a/examples/resources/biganimal_faraway_replica/gcp/resource.tf +++ b/examples/resources/biganimal_faraway_replica/gcp/resource.tf @@ -42,7 +42,7 @@ resource "biganimal_faraway_replica" "faraway_replica" { } backup_retention_period = "6d" - csp_auth = true + csp_auth = false instance_type = "gcp:e2-highcpu-4" // only following pg_config parameters are configurable for faraway replica @@ -59,27 +59,19 @@ resource "biganimal_faraway_replica" "faraway_replica" { value = "64" } - pg_config { - name = "max_prepared_transactions" - value = "0" - } - - pg_config { - name = "max_wal_senders" - value = "10" - } - - pg_config { - name = "max_worker_processes" - value = "32" - } - - storage { volume_type = "pd-ssd" volume_properties = "pd-ssd" - size = "10 Gi" + size = "4 Gi" } private_networking = false region = "us-east1" + + #tags { + # tag_name = "test-tag-name-1" + # color = "blue" + #} + #tags { + # tag_name = "test-tag-name-2" + #} } diff --git a/examples/resources/biganimal_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/resource.tf index da86de7c..35b4b872 100644 --- a/examples/resources/biganimal_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/resource.tf @@ -42,7 +42,7 @@ resource "biganimal_faraway_replica" "faraway_replica" { } backup_retention_period = "6d" - csp_auth = true + csp_auth = false instance_type = "aws:m5.large" // only following pg_config parameters are configurable for faraway replica @@ -59,27 +59,19 @@ resource "biganimal_faraway_replica" "faraway_replica" { value = "64" } - pg_config { - name = "max_prepared_transactions" - value = "0" - } - - pg_config { - name = "max_wal_senders" - value = "10" - } - - pg_config { - name = "max_worker_processes" - value = "32" - } - - storage { volume_type = "gp3" volume_properties = "gp3" size = "4 Gi" } private_networking = false - region = "eu-west-2" + region = "ap-south-1" + + #tags { + # tag_name = "test-tag-name-1" + # color = "blue" + #} + #tags { + # tag_name = "test-tag-name-2" + #} } diff --git a/pkg/models/cluster.go b/pkg/models/cluster.go index efbc8e23..9a84c068 100644 --- a/pkg/models/cluster.go +++ b/pkg/models/cluster.go @@ -63,6 +63,15 @@ func NewCluster(d *schema.ResourceData) (*Cluster, error) { return nil, err } + tagKey := d.Get("tags") + tags := []commonApi.Tag{} + if tagKey != nil { + tags, err = utils.StructFromProps[[]commonApi.Tag](tagKey.(*schema.Set).List()) + if err != nil { + return nil, err + } + } + cluster := &Cluster{ ReplicaSourceClusterId: SourceId, ClusterType: ClusterType, @@ -101,6 +110,7 @@ func NewCluster(d *schema.ResourceData) (*Cluster, error) { }, ReadOnlyConnections: clusterRoConn, Storage: &storage, + Tags: tags, } return cluster, nil diff --git a/pkg/models/common/api/tag.go b/pkg/models/common/api/tag.go index 1c501b13..e87777fe 100644 --- a/pkg/models/common/api/tag.go +++ b/pkg/models/common/api/tag.go @@ -1,7 +1,8 @@ package api +// mapstructure annotations are used by faraway away replica only and should be removed once we migrate faraway replica resouce to terraform plugin framework type Tag struct { - Color *string `json:"color,omitempty"` - TagId string `json:"tagId"` - TagName string `json:"tagName"` + Color *string `json:"color,omitempty" mapstructure:"color"` + TagId string `json:"tagId" mapstructure:"tag_id"` + TagName string `json:"tagName" mapstructure:"tag_name"` } diff --git a/pkg/provider/resource_fareplica.go b/pkg/provider/resource_fareplica.go index 504f666e..82c3646a 100644 --- a/pkg/provider/resource_fareplica.go +++ b/pkg/provider/resource_fareplica.go @@ -215,6 +215,31 @@ func (c *FAReplicaResource) Schema() *schema.Resource { }, }, }, + "tags": { + Description: "Assign existing tags or create tags to assign to this resource", + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "tag_id": { + Description: "Tag ID", + Type: schema.TypeString, + Computed: true, + }, + "tag_name": { + Description: "Tag name", + Type: schema.TypeString, + Required: true, + }, + "color": { + Description: "Tag color", + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, }, } } @@ -288,7 +313,7 @@ func (c *FAReplicaResource) read(ctx context.Context, d *schema.ResourceData, me utils.SetOrPanic(d, "deleted_at", cluster.DeletedAt) // Computed utils.SetOrPanic(d, "expired_at", cluster.ExpiredAt) // Computed utils.SetOrPanic(d, "cluster_name", cluster.ClusterName) // Required - //utils.SetOrPanic(d, "first_recoverability_point_at", cluster.FirstRecoverabilityPointAt) // Computed + // utils.SetOrPanic(d, "first_recoverability_point_at", cluster.FirstRecoverabilityPointAt) // Computed utils.SetOrPanic(d, "instance_type", cluster.InstanceType) // Required utils.SetOrPanic(d, "logs_url", cluster.LogsUrl) // Computed utils.SetOrPanic(d, "metrics_url", cluster.MetricsUrl) // Computed From b04fa41be1d0fca449d212c3d64e9c417346a8de Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 9 Apr 2024 10:52:00 +0100 Subject: [PATCH 12/25] feat: tag in cluster examples --- examples/resources/biganimal_cluster/ha/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/aws/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/azure/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/bah_aws/resource.tf | 10 ++++++++++ .../single_node/bah_azure/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/bah_gcp/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/gcp/resource.tf | 10 ++++++++++ .../biganimal_cluster/single_node/resource.tf | 10 ++++++++++ 8 files changed, 80 insertions(+) diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index 4fb4af23..b7af6b28 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -96,6 +96,16 @@ resource "biganimal_cluster" "ha_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index 91bbb5ca..8ce16463 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -97,6 +97,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index e1361f94..e9efa43d 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -97,6 +97,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf index 95fb8eba..163dc2a8 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf @@ -95,6 +95,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf index 862e1548..0f8177ac 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf @@ -100,6 +100,16 @@ resource "biganimal_cluster" "single_node_cluster" { # pe_allowed_principal_ids = [ # # ex: "9334e5e6-7f47-aE61-5A4F-ee067daeEf4A" # ] + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf index 31cf82ac..87772b74 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf @@ -89,6 +89,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index fea0932b..d6909760 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -97,6 +97,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/resource.tf b/examples/resources/biganimal_cluster/single_node/resource.tf index e1361f94..e9efa43d 100644 --- a/examples/resources/biganimal_cluster/single_node/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/resource.tf @@ -97,6 +97,16 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] } output "password" { From 29ab3698fa300d320160a80a6ad6e919552b6f0e Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 9 Apr 2024 17:48:15 +0100 Subject: [PATCH 13/25] fix: plan modifier for cluster to merge plan with state so it can deal with existing tags when planning --- pkg/plan_modifier/assign_tags.go | 60 ++++++++++++++++++++++++++++++++ pkg/provider/resource_cluster.go | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 pkg/plan_modifier/assign_tags.go diff --git a/pkg/plan_modifier/assign_tags.go b/pkg/plan_modifier/assign_tags.go new file mode 100644 index 00000000..6febcec1 --- /dev/null +++ b/pkg/plan_modifier/assign_tags.go @@ -0,0 +1,60 @@ +package plan_modifier + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +func CustomAssignTags() planmodifier.Set { + return assignTagsModifier{} +} + +// assignTagsModifier implements the plan modifier. +type assignTagsModifier struct{} + +// Description returns a human-readable description of the plan modifier. +func (m assignTagsModifier) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m assignTagsModifier) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifySet implements the plan modification logic. +func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) { + state := req.StateValue + plan := resp.PlanValue + + newPlan := []attr.Value{} + + // This is on creation. + // Do nothing if there is no state value. + if req.StateValue.IsNull() { + return + } + + // This is on update and tags are not set in config so just plan for state + if req.PlanValue.IsUnknown() { + resp.PlanValue = basetypes.NewSetValueMust(req.ConfigValue.ElementType(ctx), state.Elements()) + return + } + + // This is for anything else ie update with tags set in config. + + // merge plan with state in newPlan + for _, v := range state.Elements() { + newPlan = append(newPlan, v) + } + + // merge plan with state in newPlan + for _, v := range plan.Elements() { + newPlan = append(newPlan, v) + } + + resp.PlanValue = basetypes.NewSetValueMust(req.ConfigValue.ElementType(ctx), newPlan) +} diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 7e49b943..1c92f0ec 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -490,7 +490,7 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest }, }, PlanModifiers: []planmodifier.Set{ - setplanmodifier.UseStateForUnknown(), + plan_modifier.CustomAssignTags(), }, }, }, From 7abe3a4109fab5e024a8727b5900b664325f299d Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Apr 2024 16:36:58 +0100 Subject: [PATCH 14/25] fix: cluster assign tags fix --- pkg/plan_modifier/assign_tags.go | 29 ++++++++++++++++------ pkg/provider/resource_cluster.go | 42 +++++++++++++++++++------------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/pkg/plan_modifier/assign_tags.go b/pkg/plan_modifier/assign_tags.go index 6febcec1..c84c4b9c 100644 --- a/pkg/plan_modifier/assign_tags.go +++ b/pkg/plan_modifier/assign_tags.go @@ -46,15 +46,30 @@ func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier. // This is for anything else ie update with tags set in config. - // merge plan with state in newPlan - for _, v := range state.Elements() { - newPlan = append(newPlan, v) - } + // merge plan into newPlan (plan is from config) and merge state in newPlan (state is from read) + newPlan = state.Elements() - // merge plan with state in newPlan - for _, v := range plan.Elements() { - newPlan = append(newPlan, v) + for _, planTag := range plan.Elements() { + existing := false + for _, newPlanElem := range newPlan { + if planTag.Equal(newPlanElem) { + existing = true + continue + } + } + if !existing { + newPlan = append(newPlan, planTag) + } } resp.PlanValue = basetypes.NewSetValueMust(req.ConfigValue.ElementType(ctx), newPlan) } + +func ContainsTag(s []attr.Value, e attr.Value) bool { + for _, a := range s { + if a == e { + return true + } + } + return false +} diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 1c92f0ec..621bf7f2 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -870,14 +870,7 @@ func (c *clusterResource) read(ctx context.Context, tfClusterResource *ClusterRe } } - tfClusterResource.Tags = []commonTerraform.Tag{} - for _, v := range apiCluster.Tags { - tfClusterResource.Tags = append(tfClusterResource.Tags, commonTerraform.Tag{ - TagId: types.StringValue(v.TagId), - TagName: types.StringValue(v.TagName), - Color: basetypes.NewStringPointerValue(v.Color), - }) - } + buildTFRsrcAssignTagsAs(&tfClusterResource.Tags, &apiCluster.Tags) return nil } @@ -1055,15 +1048,7 @@ func generateGenericClusterModel(clusterResource ClusterResourceModel) models.Cl } } - tags := []commonApi.Tag{} - for _, tag := range clusterResource.Tags { - tags = append(tags, commonApi.Tag{ - Color: tag.Color.ValueStringPointer(), - TagId: tag.TagId.ValueString(), - TagName: tag.TagName.ValueString(), - }) - } - cluster.Tags = tags + cluster.Tags = buildAPIReqAssignTags(clusterResource.Tags) return cluster } @@ -1106,3 +1091,26 @@ func StringSliceToSet(items *[]string) types.Set { return types.SetValueMust(types.StringType, eles) } + +func buildTFRsrcAssignTagsAs(tfRsrcTags *[]commonTerraform.Tag, apiRespTags *[]commonApi.Tag) { + *tfRsrcTags = []commonTerraform.Tag{} + for _, v := range *apiRespTags { + *tfRsrcTags = append(*tfRsrcTags, commonTerraform.Tag{ + TagId: types.StringValue(v.TagId), + TagName: types.StringValue(v.TagName), + Color: basetypes.NewStringPointerValue(v.Color), + }) + } +} + +func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag { + tags := []commonApi.Tag{} + for _, tag := range tfRsrcTags { + tags = append(tags, commonApi.Tag{ + Color: tag.Color.ValueStringPointer(), + TagId: tag.TagId.ValueString(), + TagName: tag.TagName.ValueString(), + }) + } + return tags +} From 496b51daa828c529306ae263cb895da14645c030 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Apr 2024 16:37:56 +0100 Subject: [PATCH 15/25] feat: pgd assign tags --- .../aws/bah_data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ .../biganimal_pgd/aws/data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ .../azure/bah_data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ .../azure/data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ .../gcp/bah_data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ .../biganimal_pgd/gcp/data_group/resource.tf | 9 +++++ .../resource.tf | 9 +++++ pkg/provider/resource_pgd.go | 39 +++++++++++++++++++ 13 files changed, 147 insertions(+) diff --git a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf index 86bca218..058f1ead 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf index f8187725..ace90e5f 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/aws/data_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_group/resource.tf index 19f2fb2f..ab3f6a16 100644 --- a/examples/resources/biganimal_pgd/aws/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf index df803266..68938000 100644 --- a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf index 04f57559..9f29cb6c 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf index 9360e071..c5fd3fb1 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/azure/data_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_group/resource.tf index 9c8d34b0..0ef27941 100644 --- a/examples/resources/biganimal_pgd/azure/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf index f13b410d..e0fa6335 100644 --- a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf index 62f2c6f3..5562473e 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf index 2aac33f9..84be2b8f 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf index 9789b4cd..ebc00f32 100644 --- a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf index 55b3a3d7..bd008c5d 100644 --- a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf @@ -32,6 +32,15 @@ resource "biganimal_pgd" "pgd_cluster" { project_id = var.project_id password = resource.random_password.password.result pause = false + #tags = [ + # { + # tag_name = "test-tag-1" + # color = "blue" + # }, + # { + # tag_name = "test-tag-2" + # }, + #] data_groups = [ { allowed_ip_ranges = [ diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index efc55ba0..93a3a4b0 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -97,6 +97,36 @@ func PgdSchema(ctx context.Context) schema.Schema { Optional: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, }, + "tags": schema.SetNestedAttribute{ + Description: "Assign existing tags or create tags to assign to this resource", + Optional: true, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tag_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "color": schema.StringAttribute{ + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + }, + PlanModifiers: []planmodifier.Set{ + plan_modifier.CustomAssignTags(), + }, + }, "data_groups": schema.SetNestedAttribute{ Description: "Cluster data groups.", Required: true, @@ -595,6 +625,7 @@ type PGD struct { Password *string `tfsdk:"password"` Timeouts timeouts.Value `tfsdk:"timeouts"` Pause types.Bool `tfsdk:"pause"` + Tags []commonTerraform.Tag `tfsdk:"tags"` DataGroups []terraform.DataGroup `tfsdk:"data_groups"` WitnessGroups []terraform.WitnessGroup `tfsdk:"witness_groups"` } @@ -614,6 +645,8 @@ func (p pgdResource) Create(ctx context.Context, req resource.CreateRequest, res Password: config.Password, } + clusterReqBody.Tags = buildAPIReqAssignTags(config.Tags) + clusterReqBody.Groups = &[]any{} for _, v := range config.DataGroups { @@ -812,6 +845,8 @@ func (p pgdResource) Read(ctx context.Context, req resource.ReadRequest, resp *r state.ClusterId = clusterResp.ClusterId state.ClusterName = clusterResp.ClusterName + buildTFRsrcAssignTagsAs(&state.Tags, &clusterResp.Tags) + buildTFGroupsAs(ctx, &resp.Diagnostics, resp.State, *clusterResp, &state) if resp.Diagnostics.HasError() { return @@ -898,6 +933,8 @@ func (p pgdResource) Update(ctx context.Context, req resource.UpdateRequest, res Password: plan.Password, } + clusterReqBody.Tags = buildAPIReqAssignTags(plan.Tags) + clusterReqBody.Groups = &[]any{} for _, v := range plan.DataGroups { @@ -1141,6 +1178,8 @@ func (p *pgdResource) retryFuncAs(ctx context.Context, diags *diag.Diagnostics, return retry.RetryableError(errors.New("instance not yet ready")) } + buildTFRsrcAssignTagsAs(&outPgdTfResource.Tags, &pgdResp.Tags) + return nil } } From cb47561d234eda963060fe8d059e6fb3a275e14a Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 15 Apr 2024 09:39:49 +0100 Subject: [PATCH 16/25] fix: lint fix --- pkg/plan_modifier/assign_tags.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/plan_modifier/assign_tags.go b/pkg/plan_modifier/assign_tags.go index c84c4b9c..9577fbb4 100644 --- a/pkg/plan_modifier/assign_tags.go +++ b/pkg/plan_modifier/assign_tags.go @@ -30,8 +30,6 @@ func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier. state := req.StateValue plan := resp.PlanValue - newPlan := []attr.Value{} - // This is on creation. // Do nothing if there is no state value. if req.StateValue.IsNull() { @@ -47,7 +45,7 @@ func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier. // This is for anything else ie update with tags set in config. // merge plan into newPlan (plan is from config) and merge state in newPlan (state is from read) - newPlan = state.Elements() + newPlan := state.Elements() for _, planTag := range plan.Elements() { existing := false From 702774003cd3d72278540668f374e26ed5245e28 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 15 Apr 2024 12:13:58 +0100 Subject: [PATCH 17/25] fix: examples --- examples/resources/biganimal_cluster/ha/resource.tf | 4 ++-- .../resources/biganimal_cluster/single_node/aws/resource.tf | 4 ++-- .../resources/biganimal_cluster/single_node/azure/resource.tf | 4 ++-- .../biganimal_cluster/single_node/bah_aws/resource.tf | 4 ++-- .../biganimal_cluster/single_node/bah_azure/resource.tf | 4 ++-- .../biganimal_cluster/single_node/bah_gcp/resource.tf | 4 ++-- .../resources/biganimal_cluster/single_node/gcp/resource.tf | 4 ++-- examples/resources/biganimal_cluster/single_node/resource.tf | 4 ++-- examples/resources/biganimal_faraway_replica/aws/resource.tf | 4 ++-- .../resources/biganimal_faraway_replica/azure/resource.tf | 4 ++-- .../cluster_and_faraway_replica/resource.tf | 4 ++-- examples/resources/biganimal_faraway_replica/gcp/resource.tf | 4 ++-- examples/resources/biganimal_faraway_replica/resource.tf | 4 ++-- .../resources/biganimal_pgd/aws/bah_data_group/resource.tf | 4 ++-- .../aws/bah_data_groups_with_witness_group/resource.tf | 4 ++-- examples/resources/biganimal_pgd/aws/data_group/resource.tf | 4 ++-- .../aws/data_groups_with_witness_group/resource.tf | 4 ++-- .../resources/biganimal_pgd/azure/bah_data_group/resource.tf | 4 ++-- .../azure/bah_data_groups_with_witness_group/resource.tf | 4 ++-- examples/resources/biganimal_pgd/azure/data_group/resource.tf | 4 ++-- .../azure/data_groups_with_witness_group/resource.tf | 4 ++-- .../resources/biganimal_pgd/gcp/bah_data_group/resource.tf | 4 ++-- .../gcp/bah_data_groups_with_witness_group/resource.tf | 4 ++-- examples/resources/biganimal_pgd/gcp/data_group/resource.tf | 4 ++-- .../gcp/data_groups_with_witness_group/resource.tf | 4 ++-- 25 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index b7af6b28..df7310ca 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -99,11 +99,11 @@ resource "biganimal_cluster" "ha_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index 8ce16463..e6862644 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -100,11 +100,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index e9efa43d..ed827ade 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -100,11 +100,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf index 163dc2a8..7d39010c 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf @@ -98,11 +98,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf index 0f8177ac..8a29c48a 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf @@ -103,11 +103,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf index 87772b74..1a142d20 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf @@ -92,11 +92,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index d6909760..be8975b3 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -100,11 +100,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_cluster/single_node/resource.tf b/examples/resources/biganimal_cluster/single_node/resource.tf index e9efa43d..ed827ade 100644 --- a/examples/resources/biganimal_cluster/single_node/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/resource.tf @@ -100,11 +100,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] } diff --git a/examples/resources/biganimal_faraway_replica/aws/resource.tf b/examples/resources/biganimal_faraway_replica/aws/resource.tf index 35b4b872..ff5cd77c 100644 --- a/examples/resources/biganimal_faraway_replica/aws/resource.tf +++ b/examples/resources/biganimal_faraway_replica/aws/resource.tf @@ -68,10 +68,10 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "ap-south-1" #tags { - # tag_name = "test-tag-name-1" + # tag_name = "ex-tag-name-1" # color = "blue" #} #tags { - # tag_name = "test-tag-name-2" + # tag_name = "ex-tag-name-2" #} } diff --git a/examples/resources/biganimal_faraway_replica/azure/resource.tf b/examples/resources/biganimal_faraway_replica/azure/resource.tf index 1cf914c7..7d0ca3b6 100644 --- a/examples/resources/biganimal_faraway_replica/azure/resource.tf +++ b/examples/resources/biganimal_faraway_replica/azure/resource.tf @@ -68,10 +68,10 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "australiaeast" #tags { - # tag_name = "test-tag-name-1" + # tag_name = "ex-tag-name-1" # color = "blue" #} #tags { - # tag_name = "test-tag-name-2" + # tag_name = "ex-tag-name-2" #} } diff --git a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf index 5cc0997c..5538ca50 100644 --- a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf @@ -98,10 +98,10 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "centralindia" #tags { - # tag_name = "test-tag-name-1" + # tag_name = "ex-tag-name-1" # color = "blue" #} #tags { - # tag_name = "test-tag-name-2" + # tag_name = "ex-tag-name-2" #} } diff --git a/examples/resources/biganimal_faraway_replica/gcp/resource.tf b/examples/resources/biganimal_faraway_replica/gcp/resource.tf index bcaa9093..7e4a5fa8 100644 --- a/examples/resources/biganimal_faraway_replica/gcp/resource.tf +++ b/examples/resources/biganimal_faraway_replica/gcp/resource.tf @@ -68,10 +68,10 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "us-east1" #tags { - # tag_name = "test-tag-name-1" + # tag_name = "ex-tag-name-1" # color = "blue" #} #tags { - # tag_name = "test-tag-name-2" + # tag_name = "ex-tag-name-2" #} } diff --git a/examples/resources/biganimal_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/resource.tf index 35b4b872..ff5cd77c 100644 --- a/examples/resources/biganimal_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/resource.tf @@ -68,10 +68,10 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "ap-south-1" #tags { - # tag_name = "test-tag-name-1" + # tag_name = "ex-tag-name-1" # color = "blue" #} #tags { - # tag_name = "test-tag-name-2" + # tag_name = "ex-tag-name-2" #} } diff --git a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf index 058f1ead..773c0cdc 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf index ace90e5f..8fc9b199 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/aws/data_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_group/resource.tf index ab3f6a16..f32b7aea 100644 --- a/examples/resources/biganimal_pgd/aws/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf index 68938000..b7a51c27 100644 --- a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf index 9f29cb6c..77104f59 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf index c5fd3fb1..63cbe011 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/data_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_group/resource.tf index 0ef27941..274cba75 100644 --- a/examples/resources/biganimal_pgd/azure/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf index e0fa6335..20234548 100644 --- a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf index 5562473e..1bcdde17 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf index 84be2b8f..ea2d64ac 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf index ebc00f32..6c077fa3 100644 --- a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf index bd008c5d..dab934ca 100644 --- a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "test-tag-1" + # tag_name = "ex-tag-name-1" # color = "blue" # }, # { - # tag_name = "test-tag-2" + # tag_name = "ex-tag-name-2" # }, #] data_groups = [ From e4e58c8793ed2910396e97a7ea802e8e59266db7 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 15 Apr 2024 12:16:06 +0100 Subject: [PATCH 18/25] feat: project tags assign --- .../resources/biganimal_project/resource.tf | 9 +++ pkg/api/project_client.go | 18 +++-- pkg/models/project.go | 3 + pkg/provider/common.go | 31 +++++++++ pkg/provider/resource_cluster.go | 25 +------ pkg/provider/resource_pgd.go | 4 +- pkg/provider/resource_project.go | 66 ++++++++++++++++--- 7 files changed, 117 insertions(+), 39 deletions(-) create mode 100644 pkg/provider/common.go diff --git a/examples/resources/biganimal_project/resource.tf b/examples/resources/biganimal_project/resource.tf index 71d834fb..b417d587 100644 --- a/examples/resources/biganimal_project/resource.tf +++ b/examples/resources/biganimal_project/resource.tf @@ -17,6 +17,15 @@ resource "random_pet" "project_name" { resource "biganimal_project" "this" { project_name = format("TF %s", title(random_pet.project_name.id)) + #tags = [ + # { + # tag_name = "ex-tag-name-1" + # color = "blue" + # }, + # { + # tag_name = "ex-tag-name-2" + # }, + #] } output "project_name" { diff --git a/pkg/api/project_client.go b/pkg/api/project_client.go index 9babbba5..24df3591 100644 --- a/pkg/api/project_client.go +++ b/pkg/api/project_client.go @@ -23,14 +23,18 @@ func NewProjectClient(api API) *ProjectClient { return &c } -func (c ProjectClient) Create(ctx context.Context, projectName string) (string, error) { +func (c ProjectClient) Create(ctx context.Context, model any) (string, error) { response := struct { Data struct { ProjectId string `json:"projectId"` } `json:"data"` }{} - project := map[string]string{"projectName": projectName} + projectRs := model.(models.Project) + project := map[string]interface{}{ + "projectName": projectRs.ProjectName, + "tags": projectRs.Tags, + } b, err := json.Marshal(project) if err != nil { @@ -81,17 +85,21 @@ func (c ProjectClient) List(ctx context.Context, query string) ([]*models.Projec err = json.Unmarshal(body, &response) return response.Data, err - } -func (c ProjectClient) Update(ctx context.Context, projectId, projectName string) (string, error) { +func (c ProjectClient) Update(ctx context.Context, projectId, model any) (string, error) { response := struct { Data struct { ProjectId string `json:"projectId"` } `json:"data"` }{} - project := map[string]string{"projectName": projectName} + projectRs := model.(models.Project) + project := map[string]interface{}{ + "projectName": projectRs.ProjectName, + "tags": projectRs.Tags, + } + b, err := json.Marshal(project) if err != nil { return "", err diff --git a/pkg/models/project.go b/pkg/models/project.go index 3bedf48c..299da15d 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -1,5 +1,7 @@ package models +import commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" + type CloudProvider struct { CloudProviderId string `json:"cloudProviderId,omitempty" tfsdk:"cloud_provider_id"` CloudProviderName string `json:"cloudProviderName,omitempty" tfsdk:"cloud_provider_name"` @@ -11,6 +13,7 @@ type Project struct { UserCount int `json:"userCount,omitempty" tfsdk:"user_count"` ClusterCount int `json:"clusterCount,omitempty" tfsdk:"cluster_count"` CloudProviders []CloudProvider `json:"cloudProviders" tfsdk:"cloud_providers"` + Tags []commonApi.Tag `json:"tags,omitempty"` } // Check the return value, if ProjectName is also needed diff --git a/pkg/provider/common.go b/pkg/provider/common.go new file mode 100644 index 00000000..448dd679 --- /dev/null +++ b/pkg/provider/common.go @@ -0,0 +1,31 @@ +package provider + +import ( + commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" + commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +func buildTFRsrcAssignTagsAs(tfRsrcTagsOut *[]commonTerraform.Tag, apiRespTags []commonApi.Tag) { + *tfRsrcTagsOut = []commonTerraform.Tag{} + for _, v := range apiRespTags { + *tfRsrcTagsOut = append(*tfRsrcTagsOut, commonTerraform.Tag{ + TagId: types.StringValue(v.TagId), + TagName: types.StringValue(v.TagName), + Color: basetypes.NewStringPointerValue(v.Color), + }) + } +} + +func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag { + tags := []commonApi.Tag{} + for _, tag := range tfRsrcTags { + tags = append(tags, commonApi.Tag{ + Color: tag.Color.ValueStringPointer(), + TagId: tag.TagId.ValueString(), + TagName: tag.TagName.ValueString(), + }) + } + return tags +} diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 621bf7f2..86056e9f 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -870,7 +870,7 @@ func (c *clusterResource) read(ctx context.Context, tfClusterResource *ClusterRe } } - buildTFRsrcAssignTagsAs(&tfClusterResource.Tags, &apiCluster.Tags) + buildTFRsrcAssignTagsAs(&tfClusterResource.Tags, apiCluster.Tags) return nil } @@ -1091,26 +1091,3 @@ func StringSliceToSet(items *[]string) types.Set { return types.SetValueMust(types.StringType, eles) } - -func buildTFRsrcAssignTagsAs(tfRsrcTags *[]commonTerraform.Tag, apiRespTags *[]commonApi.Tag) { - *tfRsrcTags = []commonTerraform.Tag{} - for _, v := range *apiRespTags { - *tfRsrcTags = append(*tfRsrcTags, commonTerraform.Tag{ - TagId: types.StringValue(v.TagId), - TagName: types.StringValue(v.TagName), - Color: basetypes.NewStringPointerValue(v.Color), - }) - } -} - -func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag { - tags := []commonApi.Tag{} - for _, tag := range tfRsrcTags { - tags = append(tags, commonApi.Tag{ - Color: tag.Color.ValueStringPointer(), - TagId: tag.TagId.ValueString(), - TagName: tag.TagName.ValueString(), - }) - } - return tags -} diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index 93a3a4b0..73b761e9 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -845,7 +845,7 @@ func (p pgdResource) Read(ctx context.Context, req resource.ReadRequest, resp *r state.ClusterId = clusterResp.ClusterId state.ClusterName = clusterResp.ClusterName - buildTFRsrcAssignTagsAs(&state.Tags, &clusterResp.Tags) + buildTFRsrcAssignTagsAs(&state.Tags, clusterResp.Tags) buildTFGroupsAs(ctx, &resp.Diagnostics, resp.State, *clusterResp, &state) if resp.Diagnostics.HasError() { @@ -1178,7 +1178,7 @@ func (p *pgdResource) retryFuncAs(ctx context.Context, diags *diag.Diagnostics, return retry.RetryableError(errors.New("instance not yet ready")) } - buildTFRsrcAssignTagsAs(&outPgdTfResource.Tags, &pgdResp.Tags) + buildTFRsrcAssignTagsAs(&outPgdTfResource.Tags, pgdResp.Tags) return nil } diff --git a/pkg/provider/resource_project.go b/pkg/provider/resource_project.go index db9ef614..fc52372c 100644 --- a/pkg/provider/resource_project.go +++ b/pkg/provider/resource_project.go @@ -6,6 +6,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/api" + "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models" + commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform" + "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/plan_modifier" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -94,6 +97,36 @@ func (p projectResource) Schema(ctx context.Context, req resource.SchemaRequest, }, }, }, + "tags": schema.SetNestedAttribute{ + Description: "Assign existing tags or create tags to assign to this resource", + Optional: true, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tag_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "color": schema.StringAttribute{ + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + }, + PlanModifiers: []planmodifier.Set{ + plan_modifier.CustomAssignTags(), + }, + }, }, } } @@ -113,12 +146,13 @@ type cloudProvider struct { } type Project struct { - ID *string `tfsdk:"id"` - ProjectID *string `tfsdk:"project_id"` - ProjectName *string `tfsdk:"project_name"` - UserCount *int `tfsdk:"user_count"` - ClusterCount *int `tfsdk:"cluster_count"` - CloudProviders []cloudProvider `tfsdk:"cloud_providers"` + ID *string `tfsdk:"id"` + ProjectID *string `tfsdk:"project_id"` + ProjectName *string `tfsdk:"project_name"` + UserCount *int `tfsdk:"user_count"` + ClusterCount *int `tfsdk:"cluster_count"` + CloudProviders []cloudProvider `tfsdk:"cloud_providers"` + Tags []commonTerraform.Tag `tfsdk:"tags"` } // Create creates the resource and sets the initial Terraform state. @@ -130,7 +164,12 @@ func (p projectResource) Create(ctx context.Context, req resource.CreateRequest, return } - projectId, err := p.client.Create(ctx, *config.ProjectName) + projectReqModel := models.Project{ + ProjectName: *config.ProjectName, + Tags: buildAPIReqAssignTags(config.Tags), + } + + projectId, err := p.client.Create(ctx, projectReqModel) if err != nil { resp.Diagnostics.AddError("Error creating project", "Could not create project, unexpected error: "+err.Error()) return @@ -154,6 +193,8 @@ func (p projectResource) Create(ctx context.Context, req resource.CreateRequest, }) } + buildTFRsrcAssignTagsAs(&config.Tags, project.Tags) + diags = resp.State.Set(ctx, &config) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -188,6 +229,8 @@ func (p projectResource) Read(ctx context.Context, req resource.ReadRequest, res }) } + buildTFRsrcAssignTagsAs(&state.Tags, project.Tags) + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -204,12 +247,19 @@ func (p projectResource) Update(ctx context.Context, req resource.UpdateRequest, return } - _, err := p.client.Update(ctx, *plan.ProjectID, *plan.ProjectName) + projectReqModel := models.Project{ + ProjectName: *plan.ProjectName, + Tags: buildAPIReqAssignTags(plan.Tags), + } + + _, err := p.client.Update(ctx, *plan.ProjectID, projectReqModel) if err != nil { resp.Diagnostics.AddError("Error updating project", "Could not update project, unexpected error: "+err.Error()) return } + buildTFRsrcAssignTagsAs(&plan.Tags, projectReqModel.Tags) + diags = resp.State.Set(ctx, &plan) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { From 0364ce9a7ea02724b816bcbacfaa592139d1e231 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 15 Apr 2024 15:36:01 +0100 Subject: [PATCH 19/25] fix: planmodifier to use state so it can assign and remove correctly --- pkg/plan_modifier/assign_tags.go | 6 +++--- pkg/provider/resource_cluster.go | 2 +- pkg/provider/resource_pgd.go | 2 +- pkg/provider/resource_project.go | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/plan_modifier/assign_tags.go b/pkg/plan_modifier/assign_tags.go index 9577fbb4..9a300add 100644 --- a/pkg/plan_modifier/assign_tags.go +++ b/pkg/plan_modifier/assign_tags.go @@ -36,14 +36,14 @@ func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier. return } - // This is on update and tags are not set in config so just plan for state + // Below is everything else ie update with tags set in config. + + // This is on update and tags are not set in config so just use state as plan if req.PlanValue.IsUnknown() { resp.PlanValue = basetypes.NewSetValueMust(req.ConfigValue.ElementType(ctx), state.Elements()) return } - // This is for anything else ie update with tags set in config. - // merge plan into newPlan (plan is from config) and merge state in newPlan (state is from read) newPlan := state.Elements() diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 86056e9f..2a549140 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -490,7 +490,7 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest }, }, PlanModifiers: []planmodifier.Set{ - plan_modifier.CustomAssignTags(), + setplanmodifier.UseStateForUnknown(), }, }, }, diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index 73b761e9..278669d1 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -124,7 +124,7 @@ func PgdSchema(ctx context.Context) schema.Schema { }, }, PlanModifiers: []planmodifier.Set{ - plan_modifier.CustomAssignTags(), + setplanmodifier.UseStateForUnknown(), }, }, "data_groups": schema.SetNestedAttribute{ diff --git a/pkg/provider/resource_project.go b/pkg/provider/resource_project.go index fc52372c..a33b89dd 100644 --- a/pkg/provider/resource_project.go +++ b/pkg/provider/resource_project.go @@ -8,7 +8,6 @@ import ( "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/api" "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models" commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform" - "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/plan_modifier" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -124,7 +123,7 @@ func (p projectResource) Schema(ctx context.Context, req resource.SchemaRequest, }, }, PlanModifiers: []planmodifier.Set{ - plan_modifier.CustomAssignTags(), + setplanmodifier.UseStateForUnknown(), }, }, }, From c1655096464bd746eb31830f289d364dd5b2e8aa Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 19 Aug 2024 16:34:34 +0100 Subject: [PATCH 20/25] fix: custom plan modifier --- pkg/provider/resource_cluster.go | 2 +- pkg/provider/resource_pgd.go | 2 +- pkg/provider/resource_project.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 59809bbf..730af685 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -530,7 +530,7 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest }, }, PlanModifiers: []planmodifier.Set{ - setplanmodifier.UseStateForUnknown(), + plan_modifier.CustomAssignTags(), }, }, "transparent_data_encryption": schema.SingleNestedAttribute{ diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index 79c46cf7..0191b6ae 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -125,7 +125,7 @@ func PgdSchema(ctx context.Context) schema.Schema { }, }, PlanModifiers: []planmodifier.Set{ - setplanmodifier.UseStateForUnknown(), + plan_modifier.CustomAssignTags(), }, }, "data_groups": schema.ListNestedAttribute{ diff --git a/pkg/provider/resource_project.go b/pkg/provider/resource_project.go index a33b89dd..fc52372c 100644 --- a/pkg/provider/resource_project.go +++ b/pkg/provider/resource_project.go @@ -8,6 +8,7 @@ import ( "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/api" "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models" commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform" + "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/plan_modifier" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -123,7 +124,7 @@ func (p projectResource) Schema(ctx context.Context, req resource.SchemaRequest, }, }, PlanModifiers: []planmodifier.Set{ - setplanmodifier.UseStateForUnknown(), + plan_modifier.CustomAssignTags(), }, }, }, From 3ce5ec99b8a2e71ef155eddf314ff25689f42e61 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 21 Aug 2024 13:01:32 +0100 Subject: [PATCH 21/25] feat: tag analytics cluster --- pkg/api/beacon_analytics_client.go | 21 ---- pkg/provider/data_source_analytics_cluster.go | 2 +- pkg/provider/resource_analytics_cluster.go | 99 +++++++++++++------ 3 files changed, 68 insertions(+), 54 deletions(-) delete mode 100644 pkg/api/beacon_analytics_client.go diff --git a/pkg/api/beacon_analytics_client.go b/pkg/api/beacon_analytics_client.go deleted file mode 100644 index 48768613..00000000 --- a/pkg/api/beacon_analytics_client.go +++ /dev/null @@ -1,21 +0,0 @@ -package api - -import ( - "net/http" - "time" -) - -type BeaconAnalyticsClient struct { - API -} - -func NewBeaconAnalyticsClient(api API) *BeaconAnalyticsClient { - httpClient := http.Client{ - Timeout: clientTimeoutSeconds * time.Second, - } - - api.HTTPClient = httpClient - c := BeaconAnalyticsClient{API: api} - - return &c -} diff --git a/pkg/provider/data_source_analytics_cluster.go b/pkg/provider/data_source_analytics_cluster.go index 6a8d6a12..046c6ac7 100644 --- a/pkg/provider/data_source_analytics_cluster.go +++ b/pkg/provider/data_source_analytics_cluster.go @@ -205,7 +205,7 @@ func (r *analyticsClusterDataSource) Read(ctx context.Context, req datasource.Re return } - if err := read(ctx, r.client, &data.analyticsClusterResourceModel); err != nil { + if err := readAnalyticsCluster(ctx, r.client, &data.analyticsClusterResourceModel); err != nil { if !appendDiagFromBAErr(err, &resp.Diagnostics) { resp.Diagnostics.AddError("Error reading cluster", err.Error()) } diff --git a/pkg/provider/resource_analytics_cluster.go b/pkg/provider/resource_analytics_cluster.go index 99f305a9..2d313e73 100644 --- a/pkg/provider/resource_analytics_cluster.go +++ b/pkg/provider/resource_analytics_cluster.go @@ -59,6 +59,7 @@ type analyticsClusterResourceModel struct { ServiceAccountIds types.Set `tfsdk:"service_account_ids"` PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"` Pause types.Bool `tfsdk:"pause"` + Tags []commonTerraform.Tag `tfsdk:"tags"` Timeouts timeouts.Value `tfsdk:"timeouts"` } @@ -270,6 +271,36 @@ func (r *analyticsClusterResource) Schema(ctx context.Context, req resource.Sche Optional: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, }, + "tags": schema.SetNestedAttribute{ + Description: "Assign existing tags or create tags to assign to this resource", + Optional: true, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tag_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "tag_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "color": schema.StringAttribute{ + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + }, + PlanModifiers: []planmodifier.Set{ + plan_modifier.CustomAssignTags(), + }, + }, }, } } @@ -335,7 +366,7 @@ func (r *analyticsClusterResource) Create(ctx context.Context, req resource.Crea } // after cluster is in the correct state (healthy/paused) then get the cluster and save into state - if err := read(ctx, r.client, &config); err != nil { + if err := readAnalyticsCluster(ctx, r.client, &config); err != nil { if !appendDiagFromBAErr(err, &resp.Diagnostics) { resp.Diagnostics.AddError("Error reading cluster", err.Error()) } @@ -445,11 +476,13 @@ func generateAnalyticsClusterModelCreate(ctx context.Context, client *api.Cluste } } + cluster.Tags = buildAPIReqAssignTags(clusterResource.Tags) + return cluster, nil } -func read(ctx context.Context, client *api.ClusterClient, tfClusterResource *analyticsClusterResourceModel) error { - apiCluster, err := client.Read(ctx, tfClusterResource.ProjectId, *tfClusterResource.ClusterId) +func readAnalyticsCluster(ctx context.Context, client *api.ClusterClient, tfClusterResource *analyticsClusterResourceModel) error { + responseCluster, err := client.Read(ctx, tfClusterResource.ProjectId, *tfClusterResource.ClusterId) if err != nil { return err } @@ -460,29 +493,29 @@ func read(ctx context.Context, client *api.ClusterClient, tfClusterResource *ana } tfClusterResource.ID = types.StringValue(fmt.Sprintf("%s/%s", tfClusterResource.ProjectId, *tfClusterResource.ClusterId)) - tfClusterResource.ClusterId = apiCluster.ClusterId - tfClusterResource.ClusterName = types.StringPointerValue(apiCluster.ClusterName) - tfClusterResource.Phase = apiCluster.Phase - tfClusterResource.CloudProvider = types.StringValue(apiCluster.Provider.CloudProviderId) - tfClusterResource.Region = types.StringValue(apiCluster.Region.Id) - tfClusterResource.InstanceType = types.StringValue(apiCluster.InstanceType.InstanceTypeId) - tfClusterResource.ResizingPvc = StringSliceToList(apiCluster.ResizingPvc) + tfClusterResource.ClusterId = responseCluster.ClusterId + tfClusterResource.ClusterName = types.StringPointerValue(responseCluster.ClusterName) + tfClusterResource.Phase = responseCluster.Phase + tfClusterResource.CloudProvider = types.StringValue(responseCluster.Provider.CloudProviderId) + tfClusterResource.Region = types.StringValue(responseCluster.Region.Id) + tfClusterResource.InstanceType = types.StringValue(responseCluster.InstanceType.InstanceTypeId) + tfClusterResource.ResizingPvc = StringSliceToList(responseCluster.ResizingPvc) tfClusterResource.ConnectionUri = types.StringPointerValue(&connection.PgUri) - tfClusterResource.CspAuth = types.BoolPointerValue(apiCluster.CSPAuth) - tfClusterResource.LogsUrl = apiCluster.LogsUrl - tfClusterResource.MetricsUrl = apiCluster.MetricsUrl - tfClusterResource.BackupRetentionPeriod = types.StringPointerValue(apiCluster.BackupRetentionPeriod) - tfClusterResource.PgVersion = types.StringValue(apiCluster.PgVersion.PgVersionId) - tfClusterResource.PgType = types.StringValue(apiCluster.PgType.PgTypeId) - tfClusterResource.PrivateNetworking = types.BoolPointerValue(apiCluster.PrivateNetworking) - - if apiCluster.FirstRecoverabilityPointAt != nil { - firstPointAt := apiCluster.FirstRecoverabilityPointAt.String() + tfClusterResource.CspAuth = types.BoolPointerValue(responseCluster.CSPAuth) + tfClusterResource.LogsUrl = responseCluster.LogsUrl + tfClusterResource.MetricsUrl = responseCluster.MetricsUrl + tfClusterResource.BackupRetentionPeriod = types.StringPointerValue(responseCluster.BackupRetentionPeriod) + tfClusterResource.PgVersion = types.StringValue(responseCluster.PgVersion.PgVersionId) + tfClusterResource.PgType = types.StringValue(responseCluster.PgType.PgTypeId) + tfClusterResource.PrivateNetworking = types.BoolPointerValue(responseCluster.PrivateNetworking) + + if responseCluster.FirstRecoverabilityPointAt != nil { + firstPointAt := responseCluster.FirstRecoverabilityPointAt.String() tfClusterResource.FirstRecoverabilityPointAt = &firstPointAt } tfClusterResource.AllowedIpRanges = []AllowedIpRangesResourceModel{} - if allowedIpRanges := apiCluster.AllowedIpRanges; allowedIpRanges != nil { + if allowedIpRanges := responseCluster.AllowedIpRanges; allowedIpRanges != nil { for _, ipRange := range *allowedIpRanges { tfClusterResource.AllowedIpRanges = append(tfClusterResource.AllowedIpRanges, AllowedIpRangesResourceModel{ CidrBlock: ipRange.CidrBlock, @@ -491,26 +524,28 @@ func read(ctx context.Context, client *api.ClusterClient, tfClusterResource *ana } } - if pt := apiCluster.CreatedAt; pt != nil { + if pt := responseCluster.CreatedAt; pt != nil { tfClusterResource.CreatedAt = types.StringValue(pt.String()) } - if apiCluster.MaintenanceWindow != nil { + if responseCluster.MaintenanceWindow != nil { tfClusterResource.MaintenanceWindow = &commonTerraform.MaintenanceWindow{ - IsEnabled: apiCluster.MaintenanceWindow.IsEnabled, - StartDay: types.Int64PointerValue(utils.ToPointer(int64(*apiCluster.MaintenanceWindow.StartDay))), - StartTime: types.StringPointerValue(apiCluster.MaintenanceWindow.StartTime), + IsEnabled: responseCluster.MaintenanceWindow.IsEnabled, + StartDay: types.Int64PointerValue(utils.ToPointer(int64(*responseCluster.MaintenanceWindow.StartDay))), + StartTime: types.StringPointerValue(responseCluster.MaintenanceWindow.StartTime), } } - if apiCluster.PeAllowedPrincipalIds != nil { - tfClusterResource.PeAllowedPrincipalIds = StringSliceToSet(utils.ToValue(&apiCluster.PeAllowedPrincipalIds)) + if responseCluster.PeAllowedPrincipalIds != nil { + tfClusterResource.PeAllowedPrincipalIds = StringSliceToSet(utils.ToValue(&responseCluster.PeAllowedPrincipalIds)) } - if apiCluster.ServiceAccountIds != nil { - tfClusterResource.ServiceAccountIds = StringSliceToSet(utils.ToValue(&apiCluster.ServiceAccountIds)) + if responseCluster.ServiceAccountIds != nil { + tfClusterResource.ServiceAccountIds = StringSliceToSet(utils.ToValue(&responseCluster.ServiceAccountIds)) } + buildTFRsrcAssignTagsAs(&tfClusterResource.Tags, responseCluster.Tags) + return nil } @@ -522,7 +557,7 @@ func (r *analyticsClusterResource) Read(ctx context.Context, req resource.ReadRe return } - if err := read(ctx, r.client, &state); err != nil { + if err := readAnalyticsCluster(ctx, r.client, &state); err != nil { if !appendDiagFromBAErr(err, &resp.Diagnostics) { resp.Diagnostics.AddError("Error reading cluster", err.Error()) } @@ -628,7 +663,7 @@ func (r *analyticsClusterResource) Update(ctx context.Context, req resource.Upda } } - if err := read(ctx, r.client, &plan); err != nil { + if err := readAnalyticsCluster(ctx, r.client, &plan); err != nil { if !appendDiagFromBAErr(err, &resp.Diagnostics) { resp.Diagnostics.AddError("Error reading cluster", err.Error()) } From 79f979ae62d42453ea8f158bdd9368c4c107b693 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 22 Aug 2024 17:45:16 +0100 Subject: [PATCH 22/25] feat: examples and datasource --- .../biganimal_analytics_cluster/aws/resource.tf | 10 ++++++++++ pkg/provider/data_source_analytics_cluster.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/examples/resources/biganimal_analytics_cluster/aws/resource.tf b/examples/resources/biganimal_analytics_cluster/aws/resource.tf index f8b5e123..64c8b463 100644 --- a/examples/resources/biganimal_analytics_cluster/aws/resource.tf +++ b/examples/resources/biganimal_analytics_cluster/aws/resource.tf @@ -32,6 +32,16 @@ resource "biganimal_analytics_cluster" "analytics_cluster" { project_id = var.project_id pause = false + #tags = [ + # { + # tag_name = "wai-tag-3" + # color = "blue" + # }, + # { + # tag_name = "wai-tag-4" + # }, + #] + allowed_ip_ranges = [ { cidr_block = "127.0.0.1/32" diff --git a/pkg/provider/data_source_analytics_cluster.go b/pkg/provider/data_source_analytics_cluster.go index 046c6ac7..f54b1c88 100644 --- a/pkg/provider/data_source_analytics_cluster.go +++ b/pkg/provider/data_source_analytics_cluster.go @@ -193,6 +193,23 @@ func (r *analyticsClusterDataSource) Schema(ctx context.Context, req datasource. "Pausing a high availability cluster shuts down all cluster nodes", Optional: true, }, + "tags": schema.SetNestedAttribute{ + Description: "Assign existing tags or create tags to assign to this resource", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tag_id": schema.StringAttribute{ + Computed: true, + }, + "tag_name": schema.StringAttribute{ + Computed: true, + }, + "color": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, }, } } From 008cbda96aa973d8efd577b0de754171052dad6c Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Fri, 23 Aug 2024 10:18:07 +0100 Subject: [PATCH 23/25] fix: change example tag name --- .../resources/biganimal_analytics_cluster/aws/resource.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/resources/biganimal_analytics_cluster/aws/resource.tf b/examples/resources/biganimal_analytics_cluster/aws/resource.tf index 64c8b463..293f1821 100644 --- a/examples/resources/biganimal_analytics_cluster/aws/resource.tf +++ b/examples/resources/biganimal_analytics_cluster/aws/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_analytics_cluster" "analytics_cluster" { #tags = [ # { - # tag_name = "wai-tag-3" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "wai-tag-4" + # tag_name = "" # }, #] From 332a6cba5ce27d84994c5c463e3eb66977fb1eb9 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 9 Sep 2024 13:11:19 +0100 Subject: [PATCH 24/25] fix: data source description changes for analytics and faraway replica cluster --- pkg/provider/data_source_analytics_cluster.go | 2 +- pkg/provider/data_source_fareplica.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/provider/data_source_analytics_cluster.go b/pkg/provider/data_source_analytics_cluster.go index f54b1c88..c1309f2a 100644 --- a/pkg/provider/data_source_analytics_cluster.go +++ b/pkg/provider/data_source_analytics_cluster.go @@ -194,7 +194,7 @@ func (r *analyticsClusterDataSource) Schema(ctx context.Context, req datasource. Optional: true, }, "tags": schema.SetNestedAttribute{ - Description: "Assign existing tags or create tags to assign to this resource", + Description: "show tags associated with this resource", Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ diff --git a/pkg/provider/data_source_fareplica.go b/pkg/provider/data_source_fareplica.go index 662d7426..64d5af08 100644 --- a/pkg/provider/data_source_fareplica.go +++ b/pkg/provider/data_source_fareplica.go @@ -255,7 +255,7 @@ func (c *FAReplicaData) Schema(ctx context.Context, req datasource.SchemaRequest Computed: true, }, "tags": schema.SetNestedAttribute{ - Description: "Assign existing tags or create tags to assign to this resource", + Description: "show tags associated with this resource", Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ From 697088f4e9201d024a9e7271f527bd473601ddf6 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 7 Oct 2024 08:21:21 +0100 Subject: [PATCH 25/25] fix: example naming --- .../resources/biganimal_analytics_cluster/aws/resource.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/resources/biganimal_analytics_cluster/aws/resource.tf b/examples/resources/biganimal_analytics_cluster/aws/resource.tf index 293f1821..3fc59d8e 100644 --- a/examples/resources/biganimal_analytics_cluster/aws/resource.tf +++ b/examples/resources/biganimal_analytics_cluster/aws/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_analytics_cluster" "analytics_cluster" { #tags = [ # { - # tag_name = "" + # tag_name = "ex-tag-name" # color = "blue" # }, # { - # tag_name = "" + # tag_name = "ex-tag-name" # }, #]