Skip to content

Commit 7b2f1d0

Browse files
committed
Set space from composite id / add import test
1 parent 3980a35 commit 7b2f1d0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

internal/kibana/security_exception_list/acc_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ func TestAccResourceExceptionList(t *testing.T) {
6161
resource.TestCheckResourceAttr("elasticstack_kibana_security_exception_list.test", "tags.1", "updated"),
6262
),
6363
},
64+
{ // Import
65+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minExceptionListAPISupport),
66+
ProtoV6ProviderFactories: acctest.Providers,
67+
ConfigDirectory: acctest.NamedTestCaseDirectory("update"),
68+
ConfigVariables: config.Variables{
69+
"list_id": config.StringVariable("test-exception-list"),
70+
"name": config.StringVariable("Test Exception List Updated"),
71+
"description": config.StringVariable("Updated description"),
72+
"type": config.StringVariable("detection"),
73+
"namespace_type": config.StringVariable("single"),
74+
"tags": config.ListVariable(config.StringVariable("test"), config.StringVariable("updated")),
75+
},
76+
ResourceName: "elasticstack_kibana_security_exception_list.test",
77+
ImportState: true,
78+
ImportStateVerify: true,
79+
},
6480
},
6581
})
6682
}
@@ -131,6 +147,22 @@ func TestAccResourceExceptionListWithSpace(t *testing.T) {
131147
resource.TestCheckResourceAttr(resourceName, "tags.2", "updated"),
132148
),
133149
},
150+
{ // Import
151+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minExceptionListAPISupport),
152+
ConfigDirectory: acctest.NamedTestCaseDirectory("update"),
153+
ConfigVariables: config.Variables{
154+
"space_id": config.StringVariable(spaceID),
155+
"list_id": config.StringVariable("test-exception-list-space"),
156+
"name": config.StringVariable("Test Exception List in Space Updated"),
157+
"description": config.StringVariable("Updated description in space"),
158+
"type": config.StringVariable("detection"),
159+
"namespace_type": config.StringVariable("single"),
160+
"tags": config.ListVariable(config.StringVariable("test"), config.StringVariable("space"), config.StringVariable("updated")),
161+
},
162+
ResourceName: resourceName,
163+
ImportState: true,
164+
ImportStateVerify: true,
165+
},
134166
},
135167
})
136168
}

internal/kibana/security_exception_list/read.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
88
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
99
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
1011
)
1112

1213
func (r *ExceptionListResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
@@ -31,6 +32,10 @@ func (r *ExceptionListResource) Read(ctx context.Context, req resource.ReadReque
3132
return
3233
}
3334

35+
if !compIdDiags.HasError() {
36+
state.SpaceID = types.StringValue(compId.ClusterId)
37+
}
38+
3439
// Read by resource ID from composite ID
3540
id := kbapi.SecurityExceptionsAPIExceptionListId(compId.ResourceId)
3641
params := &kbapi.ReadExceptionListParams{

0 commit comments

Comments
 (0)