-
Notifications
You must be signed in to change notification settings - Fork 109
Kibana spaces data source #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
277f08e
Spaces Data Source
jdesnoes 0362ca2
Bump github.com/hashicorp/terraform-plugin-framework (#679)
dependabot[bot] 15c2319
Spaces data source
jdesnoes dfeb5ef
Spaces data source
jdesnoes 1a2d107
Kibana spaces data source
jdesnoes 06a1f9b
Kibana spaces data source
jdesnoes 9cd9c4f
Kibana spaces data source
jdesnoes 8a09b7d
Kibana spaces data source
jdesnoes ec629ed
Kibana spaces data source
jdesnoes 1636949
Kibana spaces data source
jdesnoes c51fd88
Merge branch 'main' into spaces_data_source
jdesnoes b741166
Suggestions apply
jdesnoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `id` (String) Generated ID for the spaces. | ||
- `spaces` (Attributes List) The list of spaces. (see [below for nested schema](#nestedatt--spaces)) | ||
|
||
<a id="nestedatt--spaces"></a> | ||
### 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. |
9 changes: 9 additions & 0 deletions
9
examples/data-sources/elasticstack_kibana_spaces/data-source.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
provider "elasticstack" { | ||
elasticsearch {} | ||
kibana {} | ||
} | ||
|
||
data "elasticstack_kibana_spaces" "all_spaces" { | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
kibanaClient, err := client.GetKibanaClient() | ||
if err != nil { | ||
resp.Diagnostics.AddError("unable to get Kibana client", err.Error()) | ||
return | ||
} | ||
|
||
d.client = kibanaClient.KibanaSpaces | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package spaces_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/terraform-provider-elasticstack/internal/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccSpacesDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ProtoV6ProviderFactories: acctest.Providers, | ||
Steps: []resource.TestStep{ | ||
{ | ||
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 testAccSpacesDataSourceConfig = ` | ||
provider "elasticstack" { | ||
elasticsearch {} | ||
kibana {} | ||
} | ||
|
||
data "elasticstack_kibana_spaces" "all_spaces" { | ||
|
||
} | ||
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package spaces | ||
|
||
import "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
// dataSourceModel maps the data source schema data. | ||
type dataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Spaces []model `tfsdk:"spaces"` | ||
} | ||
|
||
// model maps spaces 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"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
jdesnoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.