From 277f08e133fd6b2f2be238ab0623ba9892ad8482 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Mon, 15 Jul 2024 17:57:34 +0200 Subject: [PATCH 01/11] Spaces Data Source --- internal/kibana/spaces_data_source.go | 131 +++++++++++++++++++++ internal/kibana/spaces_data_source_test.go | 43 +++++++ 2 files changed, 174 insertions(+) create mode 100644 internal/kibana/spaces_data_source.go create mode 100644 internal/kibana/spaces_data_source_test.go diff --git a/internal/kibana/spaces_data_source.go b/internal/kibana/spaces_data_source.go new file mode 100644 index 000000000..63bb4fb73 --- /dev/null +++ b/internal/kibana/spaces_data_source.go @@ -0,0 +1,131 @@ +package kibana + +import ( + "context" + "fmt" + + "github.com/disaster37/go-kibana-rest/v8/kbapi" + "github.com/elastic/terraform-provider-elasticstack/internal/clients" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceSpace() *schema.Resource { + var spacesSchema = map[string]*schema.Schema{ + "search": { + Description: "Search spaces by name.", + Type: schema.TypeString, + Optional: true, + }, + "spaces": { + Description: "The list of spaces.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Description: "Internal identifier of the resource.", + Type: schema.TypeString, + Computed: true, + }, + "space_id": { + Description: "The space ID that is part of the Kibana URL when inside the space.", + Type: schema.TypeString, + Required: true, + }, + "name": { + Description: "The display name for the space.", + Type: schema.TypeString, + Required: true, + }, + "description": { + Description: "The description for the space.", + Type: schema.TypeString, + Optional: true, + }, + "disabled_features": { + 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).", + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "initials": { + 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.", + Type: schema.TypeString, + Computed: true, + }, + "color": { + Description: "The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name.", + Type: schema.TypeString, + Computed: true, + }, + "image_url": { + Description: "The data-URL encoded image to display in the space avatar.", + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + } + + return &schema.Resource{ + Description: "Search for spaces by name.", + ReadContext: datasourceSpacesRead, + Schema: spacesSchema, + } +} + +func datasourceSpacesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, diags := clients.NewApiClientFromSDKResource(d, meta) + if diags.HasError() { + return diags + } + + kibana, err := client.GetKibanaClient() + if err != nil { + return diag.FromErr(err) + } + + spaceName := d.Get("search").(string) + + allSpaces, err := kibana.KibanaSpaces.List() + if err != nil { + return diag.FromErr(err) + } + + foundSpaces := kbapi.KibanaSpaces{} + for _, space := range allSpaces { + if space.Name == spaceName { + foundSpaces = append(foundSpaces, space) + } + } + + d.SetId(fmt.Sprintf("%d", schema.HashString(spaceName))) + d.Set("spaces", flattenSpaces(foundSpaces)) + + return nil +} + +func flattenSpaces(spaces kbapi.KibanaSpaces) []interface{} { + spacesList := []interface{}{} + + for _, space := range spaces { + values := map[string]interface{}{ + "id": space.ID, + "space_id": space.ID, + "name": space.Name, + "description": space.Description, + "disabled_features": space.DisabledFeatures, + "initials": space.Initials, + "color": space.Color, + "image_url": space.ImageURL, + } + + spacesList = append(spacesList, values) + } + + return spacesList +} diff --git a/internal/kibana/spaces_data_source_test.go b/internal/kibana/spaces_data_source_test.go new file mode 100644 index 000000000..6faec6167 --- /dev/null +++ b/internal/kibana/spaces_data_source_test.go @@ -0,0 +1,43 @@ +package kibana_test + +import ( + "testing" + + "github.com/elastic/terraform-provider-elasticstack/internal/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceKibanaSpaces(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.Providers, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSpaces, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].name", "my_space"), + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].space_id", "my_space_id"), + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].description", "My Space"), + ), + }, + }, + }) +} + +const testAccDataSourceSpaces = ` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_kibana_space" "myspace" { + name = "my_space" + space_id = "my_space_id" + description = "My Space" + disabled_features = ["dev_tools"] +} + +data "elasticstack_kibana_spaces" "myspaces" { + search = elasticstack_kibana_space.myspace.name +} +` From 0362ca28a87cea1893f0ef5f25c2d6b3fd710275 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:40:46 +1000 Subject: [PATCH 02/11] Bump github.com/hashicorp/terraform-plugin-framework (#679) Bumps [github.com/hashicorp/terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) from 1.9.0 to 1.10.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-framework/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-framework/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-framework/compare/v1.9.0...v1.10.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-framework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 35869affb..702cdbf9f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-version v1.7.0 - github.com/hashicorp/terraform-plugin-framework v1.9.0 + github.com/hashicorp/terraform-plugin-framework v1.10.0 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-log v0.9.0 diff --git a/go.sum b/go.sum index 15f549c2d..bd0668fc8 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,8 @@ github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVW github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= -github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU= -github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= +github.com/hashicorp/terraform-plugin-framework v1.10.0 h1:xXhICE2Fns1RYZxEQebwkB2+kXouLC932Li9qelozrc= +github.com/hashicorp/terraform-plugin-framework v1.10.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= From 15c2319090a6b29f7be21d27110aaef86a01cb5b Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Tue, 16 Jul 2024 08:55:54 +0200 Subject: [PATCH 03/11] Spaces data source --- internal/kibana/spaces_data_source.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/kibana/spaces_data_source.go b/internal/kibana/spaces_data_source.go index 63bb4fb73..3170493e3 100644 --- a/internal/kibana/spaces_data_source.go +++ b/internal/kibana/spaces_data_source.go @@ -104,7 +104,9 @@ func datasourceSpacesRead(ctx context.Context, d *schema.ResourceData, meta inte } d.SetId(fmt.Sprintf("%d", schema.HashString(spaceName))) - d.Set("spaces", flattenSpaces(foundSpaces)) + if err := d.Set("spaces", flattenSpaces(foundSpaces)); err != nil { + return diag.FromErr(err) + } return nil } From dfeb5efa674a1297414126ca6a9aa6362afb00ea Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Tue, 16 Jul 2024 08:59:27 +0200 Subject: [PATCH 04/11] Spaces data source --- internal/kibana/spaces_data_source.go | 2 +- provider/provider.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/kibana/spaces_data_source.go b/internal/kibana/spaces_data_source.go index 3170493e3..007f56d2f 100644 --- a/internal/kibana/spaces_data_source.go +++ b/internal/kibana/spaces_data_source.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func DataSourceSpace() *schema.Resource { +func DataSourceSpaces() *schema.Resource { var spacesSchema = map[string]*schema.Schema{ "search": { Description: "Search spaces by name.", diff --git a/provider/provider.go b/provider/provider.go index 18145367c..4313cb356 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -81,6 +81,7 @@ func New(version string) *schema.Provider { "elasticstack_kibana_action_connector": kibana.DataSourceConnector(), "elasticstack_kibana_security_role": kibana.DataSourceRole(), + "elasticstack_kibana_spaces": kibana.DataSourceSpaces(), "elasticstack_fleet_enrollment_tokens": fleet.DataSourceEnrollmentTokens(), "elasticstack_fleet_integration": fleet.DataSourceIntegration(), From 1a2d1070f7bd478fd7f6949b27e7a229a4234270 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 10:46:35 +0200 Subject: [PATCH 05/11] Kibana spaces data source --- docs/data-sources/kibana_spaces.md | 51 +++++++ .../elasticstack_kibana_spaces/data-source.tf | 9 ++ internal/kibana/spaces/data_source.go | 51 +++++++ .../data_source_test.go} | 25 ++-- internal/kibana/spaces/models.go | 20 +++ internal/kibana/spaces/read.go | 50 +++++++ internal/kibana/spaces/schema.go | 59 ++++++++ internal/kibana/spaces_data_source.go | 133 ------------------ provider/plugin_framework.go | 5 +- provider/provider.go | 1 - templates/data-sources/kibana_spaces.md.tmpl | 17 +++ 11 files changed, 270 insertions(+), 151 deletions(-) create mode 100644 docs/data-sources/kibana_spaces.md create mode 100644 examples/data-sources/elasticstack_kibana_spaces/data-source.tf create mode 100644 internal/kibana/spaces/data_source.go rename internal/kibana/{spaces_data_source_test.go => spaces/data_source_test.go} (51%) create mode 100644 internal/kibana/spaces/models.go create mode 100644 internal/kibana/spaces/read.go create mode 100644 internal/kibana/spaces/schema.go delete mode 100644 internal/kibana/spaces_data_source.go create mode 100644 templates/data-sources/kibana_spaces.md.tmpl diff --git a/docs/data-sources/kibana_spaces.md b/docs/data-sources/kibana_spaces.md new file mode 100644 index 000000000..953288687 --- /dev/null +++ b/docs/data-sources/kibana_spaces.md @@ -0,0 +1,51 @@ +--- +subcategory: "Kibana" +layout: "" +page_title: "Elasticstack: elasticstack_kibana_spaces Data Source" +description: |- + Retrieve all Kibana spaces. See https://www.elastic.co/guide/en/kibana/master/spaces-api-get-all.html +--- + +# Data Source: elasticstack_kibana_spaces + +Use this data source to retrieve and get information about all existing Kibana spaces. + +## Example Usage + +```terraform +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +data "elasticstack_kibana_spaces" "all_spaces" { + +} +``` + + +## Schema + +### Read-Only + +- `id` (String) Generated ID for the spaces. +- `spaces` (Attributes List) The list of spaces. (see [below for nested schema](#nestedatt--spaces)) + + +### Nested Schema for `spaces` + +Required: + +- `name` (String) The display name for the space. + +Optional: + +- `description` (String) The description for the space. +- `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). +- `image_url` (String) The data-URL encoded image to display in the space avatar. + +Read-Only: + +- `color` (String) The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name. +- `id` (String) Internal identifier of the resource. +- `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. diff --git a/examples/data-sources/elasticstack_kibana_spaces/data-source.tf b/examples/data-sources/elasticstack_kibana_spaces/data-source.tf new file mode 100644 index 000000000..2d6cf8906 --- /dev/null +++ b/examples/data-sources/elasticstack_kibana_spaces/data-source.tf @@ -0,0 +1,9 @@ + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +data "elasticstack_kibana_spaces" "all_spaces" { + +} diff --git a/internal/kibana/spaces/data_source.go b/internal/kibana/spaces/data_source.go new file mode 100644 index 000000000..2985e6c60 --- /dev/null +++ b/internal/kibana/spaces/data_source.go @@ -0,0 +1,51 @@ +package spaces + +import ( + "context" + + "github.com/disaster37/go-kibana-rest/v8/kbapi" + "github.com/elastic/terraform-provider-elasticstack/internal/clients" + "github.com/hashicorp/terraform-plugin-framework/datasource" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &dataSource{} + _ datasource.DataSource = &dataSource{} + _ datasource.DataSourceWithConfigure = &dataSource{} +) + +// NewDataSource is a helper function to simplify the provider implementation. +func NewDataSource() datasource.DataSource { + return &dataSource{} +} + +// dataSource is the data source implementation. +type dataSource struct { + client *kbapi.KibanaSpacesAPI +} + +// Metadata returns the data source type name. +func (d *dataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_kibana_spaces" +} + +// Configure adds the provider configured client to the data source. +func (d *dataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + // Add a nil check when handling ProviderData because Terraform + // sets that data after it calls the ConfigureProvider RPC. + if req.ProviderData == nil { + return + } + + client, diags := clients.ConvertProviderData(req.ProviderData) + resp.Diagnostics.Append(diags...) + + kibanaClient, err := client.GetKibanaClient() + if err != nil { + resp.Diagnostics.AddError("unable to get spaces client", err.Error()) + return + } + + d.client = kibanaClient.KibanaSpaces +} diff --git a/internal/kibana/spaces_data_source_test.go b/internal/kibana/spaces/data_source_test.go similarity index 51% rename from internal/kibana/spaces_data_source_test.go rename to internal/kibana/spaces/data_source_test.go index 6faec6167..efc1cc246 100644 --- a/internal/kibana/spaces_data_source_test.go +++ b/internal/kibana/spaces/data_source_test.go @@ -1,4 +1,4 @@ -package kibana_test +package spaces_test import ( "testing" @@ -7,37 +7,30 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccDataSourceKibanaSpaces(t *testing.T) { +func TestAccSpacesDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: acctest.Providers, Steps: []resource.TestStep{ { - Config: testAccDataSourceSpaces, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].name", "my_space"), - resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].space_id", "my_space_id"), - resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.myspaces", "spaces[0].description", "My Space"), + Config: testAccSpacesDataSourceConfig, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.id", "default"), + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.name", "Default"), + resource.TestCheckResourceAttr("data.elasticstack_kibana_spaces.all_spaces", "spaces.0.description", "This is your default space!"), ), }, }, }) } -const testAccDataSourceSpaces = ` +const testAccSpacesDataSourceConfig = ` provider "elasticstack" { elasticsearch {} kibana {} } -resource "elasticstack_kibana_space" "myspace" { - name = "my_space" - space_id = "my_space_id" - description = "My Space" - disabled_features = ["dev_tools"] -} +data "elasticstack_kibana_spaces" "all_spaces" { -data "elasticstack_kibana_spaces" "myspaces" { - search = elasticstack_kibana_space.myspace.name } ` diff --git a/internal/kibana/spaces/models.go b/internal/kibana/spaces/models.go new file mode 100644 index 000000000..05abeea7e --- /dev/null +++ b/internal/kibana/spaces/models.go @@ -0,0 +1,20 @@ +package spaces + +import "github.com/hashicorp/terraform-plugin-framework/types" + +// spacesDataSourceModel maps the data source schema data. +type dataSourceModel struct { + ID types.String `tfsdk:"id"` + Spaces []model `tfsdk:"spaces"` +} + +// spacesModel maps coffees schema data. +type model struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + DisabledFeatures types.List `tfsdk:"disabled_features"` + Initials types.String `tfsdk:"initials"` + Color types.String `tfsdk:"color"` + ImageUrl types.String `tfsdk:"image_url"` +} diff --git a/internal/kibana/spaces/read.go b/internal/kibana/spaces/read.go new file mode 100644 index 000000000..ba4ac2962 --- /dev/null +++ b/internal/kibana/spaces/read.go @@ -0,0 +1,50 @@ +package spaces + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// Read refreshes the Terraform state with the latest data. +func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var state dataSourceModel + + // Call client API + spaces, err := d.client.List() + if err != nil { + resp.Diagnostics.AddError("unable to list spaces", err.Error()) + return + } + + // Map response body to model + for _, space := range spaces { + spaceState := model{ + ID: types.StringValue(space.ID), + Name: types.StringValue(space.Name), + Description: types.StringValue(space.Description), + Initials: types.StringValue(space.Initials), + Color: types.StringValue(space.Color), + ImageUrl: types.StringValue(space.ImageURL), + } + + if disabledFeatures, diags := types.ListValueFrom(ctx, types.StringType, space.DisabledFeatures); diags.HasError() { + resp.Diagnostics.Append(diags...) + return + } else { + spaceState.DisabledFeatures = disabledFeatures + } + + state.Spaces = append(state.Spaces, spaceState) + } + + state.ID = types.StringValue("spaces") + + // Set state + diags := resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} diff --git a/internal/kibana/spaces/schema.go b/internal/kibana/spaces/schema.go new file mode 100644 index 000000000..bb08c3958 --- /dev/null +++ b/internal/kibana/spaces/schema.go @@ -0,0 +1,59 @@ +package spaces + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// Schema defines the schema for the data source. +func (d *dataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "Manages Kibana spaces", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "Generated ID for the spaces.", + Computed: true, + }, + "spaces": schema.ListNestedAttribute{ + Description: "The list of spaces.", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "Internal identifier of the resource.", + Computed: true, + }, + "name": schema.StringAttribute{ + Description: "The display name for the space.", + Required: true, + }, + "description": schema.StringAttribute{ + Description: "The description for the space.", + Optional: true, + }, + "disabled_features": schema.ListAttribute{ + 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).", + ElementType: types.StringType, + Optional: true, + }, + "initials": schema.StringAttribute{ + 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.", + Computed: true, + }, + "color": schema.StringAttribute{ + Description: "The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name.", + Computed: true, + }, + "image_url": schema.StringAttribute{ + Description: "The data-URL encoded image to display in the space avatar.", + Optional: true, + }, + }, + }, + }, + }, + } +} diff --git a/internal/kibana/spaces_data_source.go b/internal/kibana/spaces_data_source.go deleted file mode 100644 index 007f56d2f..000000000 --- a/internal/kibana/spaces_data_source.go +++ /dev/null @@ -1,133 +0,0 @@ -package kibana - -import ( - "context" - "fmt" - - "github.com/disaster37/go-kibana-rest/v8/kbapi" - "github.com/elastic/terraform-provider-elasticstack/internal/clients" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func DataSourceSpaces() *schema.Resource { - var spacesSchema = map[string]*schema.Schema{ - "search": { - Description: "Search spaces by name.", - Type: schema.TypeString, - Optional: true, - }, - "spaces": { - Description: "The list of spaces.", - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Description: "Internal identifier of the resource.", - Type: schema.TypeString, - Computed: true, - }, - "space_id": { - Description: "The space ID that is part of the Kibana URL when inside the space.", - Type: schema.TypeString, - Required: true, - }, - "name": { - Description: "The display name for the space.", - Type: schema.TypeString, - Required: true, - }, - "description": { - Description: "The description for the space.", - Type: schema.TypeString, - Optional: true, - }, - "disabled_features": { - 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).", - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "initials": { - 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.", - Type: schema.TypeString, - Computed: true, - }, - "color": { - Description: "The hexadecimal color code used in the space avatar. By default, the color is automatically generated from the space name.", - Type: schema.TypeString, - Computed: true, - }, - "image_url": { - Description: "The data-URL encoded image to display in the space avatar.", - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - } - - return &schema.Resource{ - Description: "Search for spaces by name.", - ReadContext: datasourceSpacesRead, - Schema: spacesSchema, - } -} - -func datasourceSpacesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, diags := clients.NewApiClientFromSDKResource(d, meta) - if diags.HasError() { - return diags - } - - kibana, err := client.GetKibanaClient() - if err != nil { - return diag.FromErr(err) - } - - spaceName := d.Get("search").(string) - - allSpaces, err := kibana.KibanaSpaces.List() - if err != nil { - return diag.FromErr(err) - } - - foundSpaces := kbapi.KibanaSpaces{} - for _, space := range allSpaces { - if space.Name == spaceName { - foundSpaces = append(foundSpaces, space) - } - } - - d.SetId(fmt.Sprintf("%d", schema.HashString(spaceName))) - if err := d.Set("spaces", flattenSpaces(foundSpaces)); err != nil { - return diag.FromErr(err) - } - - return nil -} - -func flattenSpaces(spaces kbapi.KibanaSpaces) []interface{} { - spacesList := []interface{}{} - - for _, space := range spaces { - values := map[string]interface{}{ - "id": space.ID, - "space_id": space.ID, - "name": space.Name, - "description": space.Description, - "disabled_features": space.DisabledFeatures, - "initials": space.Initials, - "color": space.Color, - "image_url": space.ImageURL, - } - - spacesList = append(spacesList, values) - } - - return spacesList -} diff --git a/provider/plugin_framework.go b/provider/plugin_framework.go index a5a190c6a..5d1b22cf4 100644 --- a/provider/plugin_framework.go +++ b/provider/plugin_framework.go @@ -7,6 +7,7 @@ import ( "github.com/elastic/terraform-provider-elasticstack/internal/clients/config" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/data_view" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/import_saved_objects" + "github.com/elastic/terraform-provider-elasticstack/internal/kibana/spaces" "github.com/elastic/terraform-provider-elasticstack/internal/schema" "github.com/hashicorp/terraform-plugin-framework/datasource" fwprovider "github.com/hashicorp/terraform-plugin-framework/provider" @@ -59,7 +60,9 @@ func (p *Provider) Configure(ctx context.Context, req fwprovider.ConfigureReques } func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource { - return []func() datasource.DataSource{} + return []func() datasource.DataSource{ + spaces.NewDataSource, + } } func (p *Provider) Resources(ctx context.Context) []func() resource.Resource { diff --git a/provider/provider.go b/provider/provider.go index 4313cb356..18145367c 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -81,7 +81,6 @@ func New(version string) *schema.Provider { "elasticstack_kibana_action_connector": kibana.DataSourceConnector(), "elasticstack_kibana_security_role": kibana.DataSourceRole(), - "elasticstack_kibana_spaces": kibana.DataSourceSpaces(), "elasticstack_fleet_enrollment_tokens": fleet.DataSourceEnrollmentTokens(), "elasticstack_fleet_integration": fleet.DataSourceIntegration(), diff --git a/templates/data-sources/kibana_spaces.md.tmpl b/templates/data-sources/kibana_spaces.md.tmpl new file mode 100644 index 000000000..4ad23929c --- /dev/null +++ b/templates/data-sources/kibana_spaces.md.tmpl @@ -0,0 +1,17 @@ +--- +subcategory: "Kibana" +layout: "" +page_title: "Elasticstack: elasticstack_kibana_spaces Data Source" +description: |- + Retrieve all Kibana spaces. See https://www.elastic.co/guide/en/kibana/master/spaces-api-get-all.html +--- + +# Data Source: elasticstack_kibana_spaces + +Use this data source to retrieve and get information about all existing Kibana spaces. + +## Example Usage + +{{ tffile "examples/data-sources/elasticstack_kibana_spaces/data-source.tf" }} + +{{ .SchemaMarkdown | trimspace }} From 06a1f9bbf3310ce50b2547d8bfc5c0eed4d8cd3d Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 12:02:00 +0200 Subject: [PATCH 06/11] Kibana spaces data source --- go.mod | 20 +++++++++++--------- go.sum | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 702cdbf9f..396ec8bcc 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-mux v0.16.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 + github.com/hashicorp/terraform-plugin-testing v1.9.0 github.com/mitchellh/mapstructure v1.5.0 github.com/oapi-codegen/runtime v1.1.1 github.com/stretchr/testify v1.9.0 @@ -38,12 +39,12 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.6.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/hashicorp/hc-install v0.6.4 // indirect - github.com/hashicorp/hcl/v2 v2.20.1 // indirect + github.com/hashicorp/hc-install v0.7.0 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect github.com/hashicorp/terraform-json v0.22.1 // indirect @@ -65,12 +66,13 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.4 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - golang.org/x/tools v0.17.0 // indirect + golang.org/x/crypto v0.25.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/text v0.16.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/grpc v1.63.2 // indirect diff --git a/go.sum b/go.sum index bd0668fc8..877755239 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUK github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= @@ -78,8 +80,12 @@ github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKe github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hc-install v0.6.4 h1:QLqlM56/+SIIGvGcfFiwMY3z5WGXT066suo/v9Km8e0= github.com/hashicorp/hc-install v0.6.4/go.mod h1:05LWLy8TD842OtgcfBbOT0WMoInBMUSHjmDx10zuBIA= +github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk= +github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA= github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= @@ -98,6 +104,8 @@ github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQs github.com/hashicorp/terraform-plugin-mux v0.16.0/go.mod h1:PF79mAsPc8CpusXPfEVa4X8PtkB+ngWoiUClMrNZlYo= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg= +github.com/hashicorp/terraform-plugin-testing v1.9.0 h1:xOsQRqqlHKXpFq6etTxih3ubdK3HVDtfE1IY7Rpd37o= +github.com/hashicorp/terraform-plugin-testing v1.9.0/go.mod h1:fhhVx/8+XNJZTD5o3b4stfZ6+q7z9+lIWigIYdT6/44= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= @@ -180,15 +188,20 @@ github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8 github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -196,11 +209,15 @@ golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -217,10 +234,13 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -229,11 +249,15 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= From 9cd9c4f95337d65008e5d2e2432502e511b23bd1 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 16:04:46 +0200 Subject: [PATCH 07/11] Kibana spaces data source --- docs/data-sources/kibana_spaces.md | 2 +- examples/data-sources/elasticstack_kibana_spaces/data-source.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/kibana_spaces.md b/docs/data-sources/kibana_spaces.md index 953288687..4bb1d0120 100644 --- a/docs/data-sources/kibana_spaces.md +++ b/docs/data-sources/kibana_spaces.md @@ -19,7 +19,7 @@ provider "elasticstack" { } data "elasticstack_kibana_spaces" "all_spaces" { - + } ``` diff --git a/examples/data-sources/elasticstack_kibana_spaces/data-source.tf b/examples/data-sources/elasticstack_kibana_spaces/data-source.tf index 2d6cf8906..af3acbf72 100644 --- a/examples/data-sources/elasticstack_kibana_spaces/data-source.tf +++ b/examples/data-sources/elasticstack_kibana_spaces/data-source.tf @@ -5,5 +5,5 @@ provider "elasticstack" { } data "elasticstack_kibana_spaces" "all_spaces" { - + } From 8a09b7d212ea3c57d3c2b54a6813c25c772aac36 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 22:42:57 +0200 Subject: [PATCH 08/11] Kibana spaces data source --- internal/kibana/spaces/data_source.go | 2 +- internal/kibana/spaces/models.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/kibana/spaces/data_source.go b/internal/kibana/spaces/data_source.go index 2985e6c60..f7313fddb 100644 --- a/internal/kibana/spaces/data_source.go +++ b/internal/kibana/spaces/data_source.go @@ -43,7 +43,7 @@ func (d *dataSource) Configure(_ context.Context, req datasource.ConfigureReques kibanaClient, err := client.GetKibanaClient() if err != nil { - resp.Diagnostics.AddError("unable to get spaces client", err.Error()) + resp.Diagnostics.AddError("unable to get Kibana client", err.Error()) return } diff --git a/internal/kibana/spaces/models.go b/internal/kibana/spaces/models.go index 05abeea7e..1460baf82 100644 --- a/internal/kibana/spaces/models.go +++ b/internal/kibana/spaces/models.go @@ -2,13 +2,13 @@ package spaces import "github.com/hashicorp/terraform-plugin-framework/types" -// spacesDataSourceModel maps the data source schema data. +// dataSourceModel maps the data source schema data. type dataSourceModel struct { ID types.String `tfsdk:"id"` Spaces []model `tfsdk:"spaces"` } -// spacesModel maps coffees schema data. +// model maps coffees schema data. type model struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` From ec629ed79b5024552e4268c597f3ca33a932f777 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 23:32:26 +0200 Subject: [PATCH 09/11] Kibana spaces data source --- internal/kibana/spaces/data_source.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/kibana/spaces/data_source.go b/internal/kibana/spaces/data_source.go index f7313fddb..7578fe32c 100644 --- a/internal/kibana/spaces/data_source.go +++ b/internal/kibana/spaces/data_source.go @@ -40,6 +40,9 @@ func (d *dataSource) Configure(_ context.Context, req datasource.ConfigureReques client, diags := clients.ConvertProviderData(req.ProviderData) resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } kibanaClient, err := client.GetKibanaClient() if err != nil { From 16369491efc0ab66d5017ec6c4c6fc5588ad2302 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Thu, 18 Jul 2024 23:41:23 +0200 Subject: [PATCH 10/11] Kibana spaces data source --- internal/kibana/spaces/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/kibana/spaces/models.go b/internal/kibana/spaces/models.go index 1460baf82..e7187566f 100644 --- a/internal/kibana/spaces/models.go +++ b/internal/kibana/spaces/models.go @@ -8,7 +8,7 @@ type dataSourceModel struct { Spaces []model `tfsdk:"spaces"` } -// model maps coffees schema data. +// model maps spaces schema data. type model struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` From b74116672b5a904baaa316d08e904e67a61be578 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Mon, 19 Aug 2024 08:43:14 +0200 Subject: [PATCH 11/11] Suggestions apply --- CHANGELOG.md | 2 ++ internal/kibana/spaces/data_source.go | 1 - internal/kibana/spaces/read.go | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e7c8071..055fc6d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Add `elasticstack_kibana_spaces` data source ([#682](https://github.com/elastic/terraform-provider-elasticstack/pull/682)) + ## [0.11.5] - 2024-08-12 - Fix setting `id` for Fleet outputs and servers ([#666](https://github.com/elastic/terraform-provider-elasticstack/pull/666)) diff --git a/internal/kibana/spaces/data_source.go b/internal/kibana/spaces/data_source.go index 7578fe32c..f531e836c 100644 --- a/internal/kibana/spaces/data_source.go +++ b/internal/kibana/spaces/data_source.go @@ -10,7 +10,6 @@ import ( // Ensure the implementation satisfies the expected interfaces. var ( - _ datasource.DataSource = &dataSource{} _ datasource.DataSource = &dataSource{} _ datasource.DataSourceWithConfigure = &dataSource{} ) diff --git a/internal/kibana/spaces/read.go b/internal/kibana/spaces/read.go index ba4ac2962..ee7879a81 100644 --- a/internal/kibana/spaces/read.go +++ b/internal/kibana/spaces/read.go @@ -29,13 +29,14 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp ImageUrl: types.StringValue(space.ImageURL), } - if disabledFeatures, diags := types.ListValueFrom(ctx, types.StringType, space.DisabledFeatures); diags.HasError() { + disabledFeatures, diags := types.ListValueFrom(ctx, types.StringType, space.DisabledFeatures) + if diags.HasError() { resp.Diagnostics.Append(diags...) return - } else { - spaceState.DisabledFeatures = disabledFeatures } + spaceState.DisabledFeatures = disabledFeatures + state.Spaces = append(state.Spaces, spaceState) }