From 6b5da43bb495c1844c027ceeafb5c746f94dc554 Mon Sep 17 00:00:00 2001 From: Shamil Ganiev Date: Wed, 27 Dec 2023 12:56:48 +0400 Subject: [PATCH] bump go version update ns update and read --- .gitignore | 20 ++++++++++++ GNUmakefile | 2 +- docker-compose/.env | 11 +++++++ docs/resources/namespace.md | 1 + .../provider-install-verification/main.tf | 2 +- .../resources/temporal_namespace/import.sh | 0 .../resources/temporal_namespace/resource.tf | 1 + go.mod | 2 +- internal/provider/namespace_resource.go | 32 +++++++------------ 9 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 docker-compose/.env mode change 100644 => 100755 examples/resources/temporal_namespace/import.sh diff --git a/.gitignore b/.gitignore index 9b8a46e..decf122 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,23 @@ +# Binaries for programs and plugins +bin/* +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + # Local .terraform directories **/.terraform/* diff --git a/GNUmakefile b/GNUmakefile index 51de027..87e48f4 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,7 +6,7 @@ testacc: .PHONY: build build: - go build -o bin/temporal-provider-temporal . + go build -o bin/terraform-provider-temporal . .PHONY: install install: diff --git a/docker-compose/.env b/docker-compose/.env new file mode 100644 index 0000000..f55ca1a --- /dev/null +++ b/docker-compose/.env @@ -0,0 +1,11 @@ +COMPOSE_PROJECT_NAME=temporal +CASSANDRA_VERSION=3.11.9 +ELASTICSEARCH_VERSION=7.16.2 +MYSQL_VERSION=8 +TEMPORAL_VERSION=1.22.3 +TEMPORAL_UI_VERSION=2.21.0 +POSTGRESQL_VERSION=13 +POSTGRES_PASSWORD=temporal +POSTGRES_USER=temporal +POSTGRES_DEFAULT_PORT=5432 +OPENSEARCH_VERSION=2.5.0 diff --git a/docs/resources/namespace.md b/docs/resources/namespace.md index c94465e..f5bab15 100644 --- a/docs/resources/namespace.md +++ b/docs/resources/namespace.md @@ -17,6 +17,7 @@ Temporal Namespace resource resource "temporal_namespace" "example" { name = "example" description = "This is example namespace" + owner_email = "admin@example.com" } ``` diff --git a/examples/provider-install-verification/main.tf b/examples/provider-install-verification/main.tf index 5b948bf..20320f7 100644 --- a/examples/provider-install-verification/main.tf +++ b/examples/provider-install-verification/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { temporal = { - source = "hashicorp.com/platacard/temporal" + source = "hashicorp/platacard/temporal" } } } diff --git a/examples/resources/temporal_namespace/import.sh b/examples/resources/temporal_namespace/import.sh old mode 100644 new mode 100755 diff --git a/examples/resources/temporal_namespace/resource.tf b/examples/resources/temporal_namespace/resource.tf index b863423..0169bbd 100644 --- a/examples/resources/temporal_namespace/resource.tf +++ b/examples/resources/temporal_namespace/resource.tf @@ -2,5 +2,6 @@ resource "temporal_namespace" "example" { name = "example" description = "This is example namespace" + owner_email = "admin@example.com" } diff --git a/go.mod b/go.mod index 2fa52d3..d196d2a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module terraform-provider-temporal -go 1.19 +go 1.20 require ( github.com/hashicorp/terraform-plugin-docs v0.16.0 diff --git a/internal/provider/namespace_resource.go b/internal/provider/namespace_resource.go index 634f001..281e6d9 100644 --- a/internal/provider/namespace_resource.go +++ b/internal/provider/namespace_resource.go @@ -190,6 +190,7 @@ func (r *NamespaceResource) Create(ctx context.Context, req resource.CreateReque HistoryArchivalUri: data.HistoryArchivalUri.ValueString(), IsGlobalNamespace: data.IsGlobalNamespace.ValueBool(), } + _, err := client.RegisterNamespace(ctx, request) if err != nil { if _, ok := err.(*serviceerror.NamespaceAlreadyExists); !ok { @@ -224,17 +225,17 @@ func (r *NamespaceResource) Create(ctx context.Context, req resource.CreateReque // Read is responsible for reading the current state of a Temporal namespace. // It fetches the current configuration of the namespace and updates the Terraform state. func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data NamespaceResourceModel + var state NamespaceResourceModel client := workflowservice.NewWorkflowServiceClient(r.client) // Read Terraform prior state data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } ns, err := client.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ - Namespace: data.Name.ValueString(), + Namespace: state.Name.ValueString(), }) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read Namespace info, got error: %s", err)) @@ -243,9 +244,9 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest, tflog.Trace(ctx, "read a Temporal Namespace resource") - data = NamespaceResourceModel{ - Name: types.StringValue(ns.NamespaceInfo.GetName()), + data := &NamespaceResourceModel{ Id: types.StringValue(ns.NamespaceInfo.GetId()), + Name: state.Name, Description: types.StringValue(ns.NamespaceInfo.GetDescription()), OwnerEmail: types.StringValue(ns.NamespaceInfo.GetOwnerEmail()), Retention: types.Int64Value(int64(ns.Config.WorkflowExecutionRetentionTtl.Hours() / 24)), @@ -258,7 +259,7 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest, } // Set refreshed state - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) if resp.Diagnostics.HasError() { return } @@ -309,25 +310,14 @@ func (r *NamespaceResource) Update(ctx context.Context, req resource.UpdateReque } } + data.Id = types.StringValue(ns.NamespaceInfo.GetId()) + data.ActiveClusterName = types.StringValue(ns.GetReplicationConfig().GetActiveClusterName()) + tflog.Info(ctx, fmt.Sprintf("The namespace: %s is successfully registered", data.Name)) tflog.Trace(ctx, "created a resource") - data = NamespaceResourceModel{ - Name: types.StringValue(ns.NamespaceInfo.GetName()), - Id: types.StringValue(ns.NamespaceInfo.GetId()), - Description: types.StringValue(ns.NamespaceInfo.GetDescription()), - OwnerEmail: types.StringValue(ns.NamespaceInfo.GetOwnerEmail()), - Retention: types.Int64Value(int64(ns.Config.WorkflowExecutionRetentionTtl.Hours() / 24)), - ActiveClusterName: types.StringValue(ns.GetReplicationConfig().GetActiveClusterName()), - HistoryArchivalState: types.StringValue(enums.ArchivalState_name[int32(ns.Config.GetHistoryArchivalState())]), - HistoryArchivalUri: types.StringValue(ns.Config.GetHistoryArchivalUri()), - VisibilityArchivalState: types.StringValue(enums.ArchivalState_name[int32(ns.Config.GetVisibilityArchivalState())]), - VisibilityArchivalUri: types.StringValue(ns.Config.GetVisibilityArchivalUri()), - IsGlobalNamespace: types.BoolValue(ns.GetIsGlobalNamespace()), - } - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) if resp.Diagnostics.HasError() { return }