Skip to content

Commit 0c8a2b0

Browse files
committed
Merge branch 'main' into kibana-synthetics-http-and-tcp-monitors
2 parents e16ba84 + 7773917 commit 0c8a2b0

File tree

13 files changed

+306
-2
lines changed

13 files changed

+306
-2
lines changed

.buildkite/hooks/pre-command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "terraform-provider-elasticstack-release" ]]
1212
export GPG_PRIVATE_SECRET=$(scripts/retry.sh 5 vault kv get -field gpg_private ${RELEASE_VAULT_PATH})
1313
export GPG_PASSPHRASE_SECRET=$(scripts/retry.sh 5 vault kv get -field gpg_passphrase ${RELEASE_VAULT_PATH})
1414
export GPG_FINGERPRINT_SECRET=$(scripts/retry.sh 5 vault kv get -field gpg_fingerprint ${RELEASE_VAULT_PATH})
15-
export GITHUB_TOKEN=$(scripts/retry.sh 5 vault kv get -field gh_personal_access_token ${RELEASE_VAULT_PATH})
15+
export GITHUB_TOKEN="${VAULT_GITHUB_TOKEN}"
1616
fi

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## [Unreleased]
22
- Add support for Kibana synthetics http and tcp monitors ([#699](https://github.com/elastic/terraform-provider-elasticstack/pull/699))
33

4+
- Add `elasticstack_kibana_spaces` data source ([#682](https://github.com/elastic/terraform-provider-elasticstack/pull/682))
5+
46
## [0.11.5] - 2024-08-12
57

68
- Fix setting `id` for Fleet outputs and servers ([#666](https://github.com/elastic/terraform-provider-elasticstack/pull/666))

docs/data-sources/kibana_spaces.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
subcategory: "Kibana"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_kibana_spaces Data Source"
5+
description: |-
6+
Retrieve all Kibana spaces. See https://www.elastic.co/guide/en/kibana/master/spaces-api-get-all.html
7+
---
8+
9+
# Data Source: elasticstack_kibana_spaces
10+
11+
Use this data source to retrieve and get information about all existing Kibana spaces.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "elasticstack" {
17+
elasticsearch {}
18+
kibana {}
19+
}
20+
21+
data "elasticstack_kibana_spaces" "all_spaces" {
22+
23+
}
24+
```
25+
26+
<!-- schema generated by tfplugindocs -->
27+
## Schema
28+
29+
### Read-Only
30+
31+
- `id` (String) Generated ID for the spaces.
32+
- `spaces` (Attributes List) The list of spaces. (see [below for nested schema](#nestedatt--spaces))
33+
34+
<a id="nestedatt--spaces"></a>
35+
### Nested Schema for `spaces`
36+
37+
Required:
38+
39+
- `name` (String) The display name for the space.
40+
41+
Optional:
42+
43+
- `description` (String) The description for the space.
44+
- `disabled_features` (List of String) The list of disabled features for the space. To get a list of available feature IDs, use the Features API (https://www.elastic.co/guide/en/kibana/master/features-api-get.html).
45+
- `image_url` (String) The data-URL encoded image to display in the space avatar.
46+
47+
Read-Only:
48+
49+
- `color` (String) The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name.
50+
- `id` (String) Internal identifier of the resource.
51+
- `initials` (String) The initials shown in the space avatar. By default, the initials are automatically generated from the space name. Initials must be 1 or 2 characters.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
provider "elasticstack" {
3+
elasticsearch {}
4+
kibana {}
5+
}
6+
7+
data "elasticstack_kibana_spaces" "all_spaces" {
8+
9+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/hashicorp/terraform-plugin-log v0.9.0
1818
github.com/hashicorp/terraform-plugin-mux v0.16.0
1919
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
20+
github.com/hashicorp/terraform-plugin-testing v1.9.0
2021
github.com/mitchellh/mapstructure v1.5.0
2122
github.com/oapi-codegen/runtime v1.1.1
2223
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQs
102102
github.com/hashicorp/terraform-plugin-mux v0.16.0/go.mod h1:PF79mAsPc8CpusXPfEVa4X8PtkB+ngWoiUClMrNZlYo=
103103
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE=
104104
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg=
105+
github.com/hashicorp/terraform-plugin-testing v1.9.0 h1:xOsQRqqlHKXpFq6etTxih3ubdK3HVDtfE1IY7Rpd37o=
106+
github.com/hashicorp/terraform-plugin-testing v1.9.0/go.mod h1:fhhVx/8+XNJZTD5o3b4stfZ6+q7z9+lIWigIYdT6/44=
105107
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
106108
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
107109
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=

internal/kibana/spaces/data_source.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package spaces
2+
3+
import (
4+
"context"
5+
6+
"github.com/disaster37/go-kibana-rest/v8/kbapi"
7+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
8+
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
)
10+
11+
// Ensure the implementation satisfies the expected interfaces.
12+
var (
13+
_ datasource.DataSource = &dataSource{}
14+
_ datasource.DataSourceWithConfigure = &dataSource{}
15+
)
16+
17+
// NewDataSource is a helper function to simplify the provider implementation.
18+
func NewDataSource() datasource.DataSource {
19+
return &dataSource{}
20+
}
21+
22+
// dataSource is the data source implementation.
23+
type dataSource struct {
24+
client *kbapi.KibanaSpacesAPI
25+
}
26+
27+
// Metadata returns the data source type name.
28+
func (d *dataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
29+
resp.TypeName = req.ProviderTypeName + "_kibana_spaces"
30+
}
31+
32+
// Configure adds the provider configured client to the data source.
33+
func (d *dataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
34+
// Add a nil check when handling ProviderData because Terraform
35+
// sets that data after it calls the ConfigureProvider RPC.
36+
if req.ProviderData == nil {
37+
return
38+
}
39+
40+
client, diags := clients.ConvertProviderData(req.ProviderData)
41+
resp.Diagnostics.Append(diags...)
42+
if resp.Diagnostics.HasError() {
43+
return
44+
}
45+
46+
kibanaClient, err := client.GetKibanaClient()
47+
if err != nil {
48+
resp.Diagnostics.AddError("unable to get Kibana client", err.Error())
49+
return
50+
}
51+
52+
d.client = kibanaClient.KibanaSpaces
53+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package spaces_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccSpacesDataSource(t *testing.T) {
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { acctest.PreCheck(t) },
13+
ProtoV6ProviderFactories: acctest.Providers,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccSpacesDataSourceConfig,
17+
Check: resource.ComposeAggregateTestCheckFunc(
18+
resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.id", "default"),
19+
resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.name", "Default"),
20+
resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.description", "This is your default space!"),
21+
),
22+
},
23+
},
24+
})
25+
}
26+
27+
const testAccSpacesDataSourceConfig = `
28+
provider "elasticstack" {
29+
elasticsearch {}
30+
kibana {}
31+
}
32+
33+
data "elasticstack_kibana_spaces" "all_spaces" {
34+
35+
}
36+
`

internal/kibana/spaces/models.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package spaces
2+
3+
import "github.com/hashicorp/terraform-plugin-framework/types"
4+
5+
// dataSourceModel maps the data source schema data.
6+
type dataSourceModel struct {
7+
ID types.String `tfsdk:"id"`
8+
Spaces []model `tfsdk:"spaces"`
9+
}
10+
11+
// model maps spaces schema data.
12+
type model struct {
13+
ID types.String `tfsdk:"id"`
14+
Name types.String `tfsdk:"name"`
15+
Description types.String `tfsdk:"description"`
16+
DisabledFeatures types.List `tfsdk:"disabled_features"`
17+
Initials types.String `tfsdk:"initials"`
18+
Color types.String `tfsdk:"color"`
19+
ImageUrl types.String `tfsdk:"image_url"`
20+
}

internal/kibana/spaces/read.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package spaces
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/hashicorp/terraform-plugin-framework/types"
8+
)
9+
10+
// Read refreshes the Terraform state with the latest data.
11+
func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
12+
var state dataSourceModel
13+
14+
// Call client API
15+
spaces, err := d.client.List()
16+
if err != nil {
17+
resp.Diagnostics.AddError("unable to list spaces", err.Error())
18+
return
19+
}
20+
21+
// Map response body to model
22+
for _, space := range spaces {
23+
spaceState := model{
24+
ID: types.StringValue(space.ID),
25+
Name: types.StringValue(space.Name),
26+
Description: types.StringValue(space.Description),
27+
Initials: types.StringValue(space.Initials),
28+
Color: types.StringValue(space.Color),
29+
ImageUrl: types.StringValue(space.ImageURL),
30+
}
31+
32+
disabledFeatures, diags := types.ListValueFrom(ctx, types.StringType, space.DisabledFeatures)
33+
if diags.HasError() {
34+
resp.Diagnostics.Append(diags...)
35+
return
36+
}
37+
38+
spaceState.DisabledFeatures = disabledFeatures
39+
40+
state.Spaces = append(state.Spaces, spaceState)
41+
}
42+
43+
state.ID = types.StringValue("spaces")
44+
45+
// Set state
46+
diags := resp.State.Set(ctx, &state)
47+
resp.Diagnostics.Append(diags...)
48+
if resp.Diagnostics.HasError() {
49+
return
50+
}
51+
}

internal/kibana/spaces/schema.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package spaces
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
8+
"github.com/hashicorp/terraform-plugin-framework/types"
9+
)
10+
11+
// Schema defines the schema for the data source.
12+
func (d *dataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
13+
resp.Schema = schema.Schema{
14+
Description: "Manages Kibana spaces",
15+
Attributes: map[string]schema.Attribute{
16+
"id": schema.StringAttribute{
17+
Description: "Generated ID for the spaces.",
18+
Computed: true,
19+
},
20+
"spaces": schema.ListNestedAttribute{
21+
Description: "The list of spaces.",
22+
Computed: true,
23+
NestedObject: schema.NestedAttributeObject{
24+
Attributes: map[string]schema.Attribute{
25+
"id": schema.StringAttribute{
26+
Description: "Internal identifier of the resource.",
27+
Computed: true,
28+
},
29+
"name": schema.StringAttribute{
30+
Description: "The display name for the space.",
31+
Required: true,
32+
},
33+
"description": schema.StringAttribute{
34+
Description: "The description for the space.",
35+
Optional: true,
36+
},
37+
"disabled_features": schema.ListAttribute{
38+
Description: "The list of disabled features for the space. To get a list of available feature IDs, use the Features API (https://www.elastic.co/guide/en/kibana/master/features-api-get.html).",
39+
ElementType: types.StringType,
40+
Optional: true,
41+
},
42+
"initials": schema.StringAttribute{
43+
Description: "The initials shown in the space avatar. By default, the initials are automatically generated from the space name. Initials must be 1 or 2 characters.",
44+
Computed: true,
45+
},
46+
"color": schema.StringAttribute{
47+
Description: "The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name.",
48+
Computed: true,
49+
},
50+
"image_url": schema.StringAttribute{
51+
Description: "The data-URL encoded image to display in the space avatar.",
52+
Optional: true,
53+
},
54+
},
55+
},
56+
},
57+
},
58+
}
59+
}

provider/plugin_framework.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/elastic/terraform-provider-elasticstack/internal/clients/config"
88
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/data_view"
99
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/import_saved_objects"
10+
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/spaces"
1011
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/synthetics"
1112
"github.com/elastic/terraform-provider-elasticstack/internal/kibana/synthetics/private_location"
1213
"github.com/elastic/terraform-provider-elasticstack/internal/schema"
@@ -66,7 +67,9 @@ func (p *Provider) Configure(ctx context.Context, req fwprovider.ConfigureReques
6667
}
6768

6869
func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
69-
return []func() datasource.DataSource{}
70+
return []func() datasource.DataSource{
71+
spaces.NewDataSource,
72+
}
7073
}
7174

7275
func (p *Provider) Resources(ctx context.Context) []func() resource.Resource {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
subcategory: "Kibana"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_kibana_spaces Data Source"
5+
description: |-
6+
Retrieve all Kibana spaces. See https://www.elastic.co/guide/en/kibana/master/spaces-api-get-all.html
7+
---
8+
9+
# Data Source: elasticstack_kibana_spaces
10+
11+
Use this data source to retrieve and get information about all existing Kibana spaces.
12+
13+
## Example Usage
14+
15+
{{ tffile "examples/data-sources/elasticstack_kibana_spaces/data-source.tf" }}
16+
17+
{{ .SchemaMarkdown | trimspace }}

0 commit comments

Comments
 (0)