Skip to content

Commit 9d620f2

Browse files
authored
Don't require elasticsearch for Kibana resources (#425)
* Don't require elasticsearch for Kibana resources * Fix acctest cleanup * Try and decode the space id as a composite it
1 parent 1107e32 commit 9d620f2

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

internal/kibana/space.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,7 @@ func resourceSpaceUpsert(ctx context.Context, d *schema.ResourceData, meta inter
121121
}
122122
}
123123

124-
id, diags := client.ID(ctx, spaceResponse.ID)
125-
if diags.HasError() {
126-
return diags
127-
}
128-
129-
d.SetId(id.String())
124+
d.SetId(spaceResponse.ID)
130125

131126
return resourceSpaceRead(ctx, d, meta)
132127
}
@@ -136,11 +131,10 @@ func resourceSpaceRead(ctx context.Context, d *schema.ResourceData, meta interfa
136131
if diags.HasError() {
137132
return diags
138133
}
139-
compId, diags := clients.CompositeIdFromStr(d.Id())
140-
if diags.HasError() {
141-
return diags
134+
id := d.Id()
135+
if compId, diags := clients.CompositeIdFromStr(id); diags == nil {
136+
id = compId.ResourceId
142137
}
143-
id := compId.ResourceId
144138

145139
kibana, err := client.GetKibanaClient()
146140
if err != nil {
@@ -184,17 +178,17 @@ func resourceSpaceDelete(ctx context.Context, d *schema.ResourceData, meta inter
184178
if diags.HasError() {
185179
return diags
186180
}
187-
compId, diags := clients.CompositeIdFromStr(d.Id())
188-
if diags.HasError() {
189-
return diags
181+
id := d.Id()
182+
if compId, diags := clients.CompositeIdFromStr(id); diags == nil {
183+
id = compId.ResourceId
190184
}
191185

192186
kibana, err := client.GetKibanaClient()
193187
if err != nil {
194188
return diag.FromErr(err)
195189
}
196190

197-
err = kibana.KibanaSpaces.Delete(compId.ResourceId)
191+
err = kibana.KibanaSpaces.Delete(id)
198192
if err != nil {
199193
return diag.FromErr(err)
200194
}

internal/kibana/space_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func TestAccResourceSpace(t *testing.T) {
4444
func testAccResourceSpaceCreate(id string) string {
4545
return fmt.Sprintf(`
4646
provider "elasticstack" {
47-
elasticsearch {}
4847
kibana {}
4948
}
5049
@@ -59,7 +58,6 @@ resource "elasticstack_kibana_space" "test_space" {
5958
func testAccResourceSpaceUpdate(id string) string {
6059
return fmt.Sprintf(`
6160
provider "elasticstack" {
62-
elasticsearch {}
6361
kibana {}
6462
}
6563
@@ -82,19 +80,18 @@ func checkResourceSpaceDestroy(s *terraform.State) error {
8280
if rs.Type != "elasticstack_kibana_space" {
8381
continue
8482
}
85-
compId, _ := clients.CompositeIdFromStr(rs.Primary.ID)
8683

8784
kibanaClient, err := client.GetKibanaClient()
8885
if err != nil {
8986
return err
9087
}
91-
res, err := kibanaClient.KibanaSpaces.Get(compId.ResourceId)
88+
res, err := kibanaClient.KibanaSpaces.Get(rs.Primary.ID)
9289
if err != nil {
9390
return err
9491
}
9592

9693
if res != nil {
97-
return fmt.Errorf("Space (%s) still exists", compId.ResourceId)
94+
return fmt.Errorf("Space (%s) still exists", rs.Primary.ID)
9895
}
9996
}
10097
return nil

0 commit comments

Comments
 (0)