Skip to content

Commit dcb8391

Browse files
committed
handle private location id w/o namespace
1 parent f40d508 commit dcb8391

File tree

1 file changed

+14
-8
lines changed
  • internal/kibana/synthetics/private_location

1 file changed

+14
-8
lines changed

internal/kibana/synthetics/private_location/read.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/disaster37/go-kibana-rest/v8/kbapi"
88
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/synthetics"
99
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
"strings"
1011
)
1112

1213
func (r *Resource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) {
@@ -23,22 +24,27 @@ func (r *Resource) Read(ctx context.Context, request resource.ReadRequest, respo
2324
return
2425
}
2526

26-
compositeId, dg := synthetics.GetCompositeId(state.ID.ValueString())
27-
response.Diagnostics.Append(dg...)
28-
if response.Diagnostics.HasError() {
29-
return
30-
}
27+
resourceId := state.ID.ValueString()
28+
namespace := state.SpaceID.ValueString()
29+
if strings.Contains(resourceId, "/") {
30+
compositeId, dg := synthetics.GetCompositeId(state.ID.ValueString())
31+
response.Diagnostics.Append(dg...)
32+
if response.Diagnostics.HasError() {
33+
return
34+
}
3135

32-
namespace := compositeId.ClusterId
33-
result, err := kibanaClient.KibanaSynthetics.PrivateLocation.Get(ctx, compositeId.ResourceId, namespace)
36+
resourceId = compositeId.ResourceId
37+
namespace = compositeId.ClusterId
38+
}
39+
result, err := kibanaClient.KibanaSynthetics.PrivateLocation.Get(ctx, resourceId, namespace)
3440
if err != nil {
3541
var apiError *kbapi.APIError
3642
if errors.As(err, &apiError) && apiError.Code == 404 {
3743
response.State.RemoveResource(ctx)
3844
return
3945
}
4046

41-
response.Diagnostics.AddError(fmt.Sprintf("Failed to get private location `%s`, namespace %s", compositeId, namespace), err.Error())
47+
response.Diagnostics.AddError(fmt.Sprintf("Failed to get private location `%s`, namespace %s", resourceId, namespace), err.Error())
4248
return
4349
}
4450

0 commit comments

Comments
 (0)