Skip to content

Commit ab53e8f

Browse files
Copilottobio
andcommitted
Fix space ID handling in toModelV0 function
Co-authored-by: tobio <[email protected]>
1 parent 11d2ab5 commit ab53e8f

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

internal/kibana/synthetics/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (r *Resource) Create(ctx context.Context, request resource.CreateRequest, r
3434
return
3535
}
3636

37-
plan, diags = plan.toModelV0(ctx, result)
37+
plan, diags = plan.toModelV0(ctx, result, namespace)
3838
response.Diagnostics.Append(diags...)
3939
if response.Diagnostics.HasError() {
4040
return

internal/kibana/synthetics/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (r *Resource) Read(ctx context.Context, request resource.ReadRequest, respo
4242
return
4343
}
4444

45-
state, diags = state.toModelV0(ctx, result)
45+
state, diags = state.toModelV0(ctx, result, namespace)
4646
response.Diagnostics.Append(diags...)
4747
if response.Diagnostics.HasError() {
4848
return

internal/kibana/synthetics/schema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func stringToInt64(v string) (int64, error) {
583583
return res, err
584584
}
585585

586-
func (v *tfModelV0) toModelV0(ctx context.Context, api *kbapi.SyntheticsMonitor) (*tfModelV0, diag.Diagnostics) {
586+
func (v *tfModelV0) toModelV0(ctx context.Context, api *kbapi.SyntheticsMonitor, spaceID string) (*tfModelV0, diag.Diagnostics) {
587587
var schedule int64
588588
var err error
589589
dg := diag.Diagnostics{}
@@ -657,7 +657,7 @@ func (v *tfModelV0) toModelV0(ctx context.Context, api *kbapi.SyntheticsMonitor)
657657
}
658658

659659
resourceID := clients.CompositeId{
660-
ClusterId: api.Namespace,
660+
ClusterId: spaceID,
661661
ResourceId: string(api.Id),
662662
}
663663

@@ -669,7 +669,7 @@ func (v *tfModelV0) toModelV0(ctx context.Context, api *kbapi.SyntheticsMonitor)
669669
return &tfModelV0{
670670
ID: types.StringValue(resourceID.String()),
671671
Name: types.StringValue(api.Name),
672-
SpaceID: types.StringValue(api.Namespace),
672+
SpaceID: types.StringValue(spaceID),
673673
Namespace: types.StringValue(api.Namespace),
674674
Schedule: types.Int64Value(schedule),
675675
Locations: v.Locations,

internal/kibana/synthetics/schema_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ func TestToModelV0(t *testing.T) {
406406
for _, tt := range testcases {
407407
t.Run(tt.name, func(t *testing.T) {
408408
ctx := context.Background()
409-
model, diag := tt.expected.toModelV0(ctx, &tt.input)
409+
expectedSpaceID := tt.expected.SpaceID.ValueString()
410+
model, diag := tt.expected.toModelV0(ctx, &tt.input, expectedSpaceID)
410411
assert.False(t, diag.HasError())
411412
assert.Equal(t, &tt.expected, model)
412413
})
@@ -831,7 +832,8 @@ func TestToModelV0MergeAttributes(t *testing.T) {
831832
for _, tt := range testcases {
832833
t.Run(tt.name, func(t *testing.T) {
833834
ctx := context.Background()
834-
actual, diag := tt.state.toModelV0(ctx, &tt.input)
835+
expectedSpaceID := tt.expected.SpaceID.ValueString()
836+
actual, diag := tt.state.toModelV0(ctx, &tt.input, expectedSpaceID)
835837
assert.False(t, diag.HasError())
836838
assert.NotNil(t, actual)
837839
assert.Equal(t, &tt.expected, actual)

internal/kibana/synthetics/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (r *Resource) Update(ctx context.Context, request resource.UpdateRequest, r
4141
return
4242
}
4343

44-
plan, diags = plan.toModelV0(ctx, result)
44+
plan, diags = plan.toModelV0(ctx, result, namespace)
4545
response.Diagnostics.Append(diags...)
4646
if response.Diagnostics.HasError() {
4747
return

0 commit comments

Comments
 (0)