Skip to content

Commit 99bb02a

Browse files
Copilottobio
andcommitted
Add solution field support to Kibana space resource and data source
Co-authored-by: tobio <[email protected]>
1 parent f394a54 commit 99bb02a

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

internal/kibana/space.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func ResourceSpace() *schema.Resource {
6161
Optional: true,
6262
ValidateFunc: validation.StringMatch(regexp.MustCompile("^data:image/"), "must be a valid data-URL encoded image"),
6363
},
64+
"solution": {
65+
Description: "The solution view for the space. Valid options are `security`, `oblt`, `es`, or `classic`.",
66+
Type: schema.TypeString,
67+
Optional: true,
68+
ValidateFunc: validation.StringInSlice([]string{"security", "oblt", "es", "classic"}, false),
69+
},
6470
}
6571

6672
return &schema.Resource{
@@ -120,6 +126,10 @@ func resourceSpaceUpsert(ctx context.Context, d *schema.ResourceData, meta inter
120126
space.ImageURL = imageUrl.(string)
121127
}
122128

129+
if solution, ok := d.GetOk("solution"); ok {
130+
space.Solution = solution.(string)
131+
}
132+
123133
var spaceResponse *kbapi.KibanaSpace
124134

125135
if d.IsNewResource() {
@@ -182,6 +192,9 @@ func resourceSpaceRead(ctx context.Context, d *schema.ResourceData, meta interfa
182192
if err := d.Set("color", space.Color); err != nil {
183193
return diag.FromErr(err)
184194
}
195+
if err := d.Set("solution", space.Solution); err != nil {
196+
return diag.FromErr(err)
197+
}
185198

186199
return diags
187200
}

internal/kibana/space_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ func TestAccResourceSpace(t *testing.T) {
3939
resource.TestCheckResourceAttrSet("elasticstack_kibana_space.test_space", "image_url"),
4040
),
4141
},
42+
{
43+
Config: testAccResourceSpaceWithSolution(spaceId),
44+
Check: resource.ComposeTestCheckFunc(
45+
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "space_id", spaceId),
46+
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "name", fmt.Sprintf("Solution %s", spaceId)),
47+
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "description", "Test Space with Solution"),
48+
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "solution", "security"),
49+
),
50+
},
4251
{
4352
Config: testAccResourceSpaceCreate(spaceId),
4453
Check: resource.ComposeTestCheckFunc(
@@ -83,6 +92,21 @@ resource "elasticstack_kibana_space" "test_space" {
8392
`, id, fmt.Sprintf("Updated %s", id))
8493
}
8594

95+
func testAccResourceSpaceWithSolution(id string) string {
96+
return fmt.Sprintf(`
97+
provider "elasticstack" {
98+
kibana {}
99+
}
100+
101+
resource "elasticstack_kibana_space" "test_space" {
102+
space_id = "%s"
103+
name = "%s"
104+
description = "Test Space with Solution"
105+
solution = "security"
106+
}
107+
`, id, fmt.Sprintf("Solution %s", id))
108+
}
109+
86110
func checkResourceSpaceDestroy(s *terraform.State) error {
87111
client, err := clients.NewAcceptanceTestingClient()
88112
if err != nil {

internal/kibana/spaces/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ type model struct {
1717
Initials types.String `tfsdk:"initials"`
1818
Color types.String `tfsdk:"color"`
1919
ImageUrl types.String `tfsdk:"image_url"`
20+
Solution types.String `tfsdk:"solution"`
2021
}

internal/kibana/spaces/read.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
2727
Initials: types.StringValue(space.Initials),
2828
Color: types.StringValue(space.Color),
2929
ImageUrl: types.StringValue(space.ImageURL),
30+
Solution: types.StringValue(space.Solution),
3031
}
3132

3233
disabledFeatures, diags := types.ListValueFrom(ctx, types.StringType, space.DisabledFeatures)

internal/kibana/spaces/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func (d *dataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp
5151
Description: "The data-URL encoded image to display in the space avatar.",
5252
Optional: true,
5353
},
54+
"solution": schema.StringAttribute{
55+
Description: "The solution view for the space. Valid options are `security`, `oblt`, `es`, or `classic`.",
56+
Optional: true,
57+
},
5458
},
5559
},
5660
},

libs/go-kibana-rest/kbapi/api.kibana_spaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type KibanaSpace struct {
2323
Initials string `json:"initials,omitempty"`
2424
Color string `json:"color,omitempty"`
2525
ImageURL string `json:"imageUrl,omitempty"`
26+
Solution string `json:"solution,omitempty"`
2627
}
2728

2829
// KibanaSpaces is the list of KibanaSpace object

libs/go-kibana-rest/kbapi/api.kibana_spaces_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (s *KBAPITestSuite) TestKibanaSpaces() {
2222
ID: "test",
2323
Name: "test",
2424
Description: "My test",
25+
Solution: "security",
2526
}
2627
kibanaSpace, err = s.KibanaSpaces.Create(kibanaSpace)
2728
assert.NoError(s.T(), err)

0 commit comments

Comments
 (0)