Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/namespace import #11

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/*

Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions docker-compose/.env
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docs/resources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Temporal Namespace resource
resource "temporal_namespace" "example" {
name = "example"
description = "This is example namespace"
owner_email = "[email protected]"
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
temporal = {
source = "hashicorp.com/platacard/temporal"
source = "hashicorp/platacard/temporal"
}
}
}
Expand Down
Empty file modified examples/resources/temporal_namespace/import.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions examples/resources/temporal_namespace/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
resource "temporal_namespace" "example" {
name = "example"
description = "This is example namespace"
owner_email = "[email protected]"
}

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module terraform-provider-temporal

go 1.19
go 1.20

require (
github.com/hashicorp/terraform-plugin-docs v0.16.0
Expand Down
32 changes: 11 additions & 21 deletions internal/provider/namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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)),
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading