55 "fmt"
66 "time"
77
8+ "google.golang.org/grpc/codes"
9+ "google.golang.org/grpc/status"
810 "google.golang.org/protobuf/types/known/durationpb"
911
1012 "github.com/hashicorp/terraform-plugin-framework/path"
@@ -208,7 +210,7 @@ func (r *NamespaceResource) Create(ctx context.Context, req resource.CreateReque
208210 Namespace : data .Name .ValueString (),
209211 })
210212 if err != nil {
211- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to read Namespace info, got error: %s" , err ))
213+ resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to create Namespace info, got error: %s" , err ))
212214 return
213215 }
214216
@@ -236,12 +238,20 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest,
236238 if resp .Diagnostics .HasError () {
237239 return
238240 }
241+ namespace := state .Name .ValueString ()
239242 ns , err := client .DescribeNamespace (ctx , & workflowservice.DescribeNamespaceRequest {
240- Namespace : state . Name . ValueString () ,
243+ Namespace : namespace ,
241244 })
242245 if err != nil {
243- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to read Namespace info, got error: %s" , err ))
244- return
246+ errCode := status .Code (err )
247+ if errCode == codes .NotFound {
248+ tflog .Warn (ctx , "Namespace not found" , map [string ]interface {}{"err" : err , "namespace" : namespace })
249+ resp .State .RemoveResource (ctx )
250+ return
251+ } else {
252+ resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to read Namespace info, got error: %s" , err ))
253+ return
254+ }
245255 }
246256
247257 tflog .Trace (ctx , "read a Temporal Namespace resource" )
@@ -262,9 +272,6 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest,
262272
263273 // Set refreshed state
264274 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
265- if resp .Diagnostics .HasError () {
266- return
267- }
268275}
269276
270277// Update modifies an existing Temporal namespace based on Terraform configuration changes.
0 commit comments