Skip to content

Commit

Permalink
Merge pull request #64 from mfl-code/missing
Browse files Browse the repository at this point in the history
Handle Missing Namespace
  • Loading branch information
ganievs authored Aug 22, 2024
2 parents 65469b9 + 34f40b8 commit d1e5514
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions internal/provider/namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/hashicorp/terraform-plugin-framework/path"
Expand Down Expand Up @@ -208,7 +210,7 @@ func (r *NamespaceResource) Create(ctx context.Context, req resource.CreateReque
Namespace: data.Name.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read Namespace info, got error: %s", err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create Namespace info, got error: %s", err))
return
}

Expand Down Expand Up @@ -236,12 +238,19 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
namespace := state.Name.ValueString()
ns, err := client.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{
Namespace: state.Name.ValueString(),
Namespace: namespace,
})
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read Namespace info, got error: %s", err))
return
errCode := status.Code(err)
if errCode == codes.NotFound {
tflog.Warn(ctx, "Namespace not found", map[string]interface{}{"err": err, "namespace": namespace})
return
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read Namespace info, got error: %s", err))
return
}
}

tflog.Trace(ctx, "read a Temporal Namespace resource")
Expand All @@ -262,9 +271,6 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest,

// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
}

// Update modifies an existing Temporal namespace based on Terraform configuration changes.
Expand Down

0 comments on commit d1e5514

Please sign in to comment.