Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Added
- Add support for Kibana SLOs ([#385](https://github.com/elastic/terraform-provider-elasticstack/pull/385))
- Document all available environment variables ([#405](https://github.com/elastic/terraform-provider-elasticstack/pull/405))

## [0.6.2] - 2023-06-19

Expand Down
41 changes: 37 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The following methods are supported:

### Static credentials

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in `elasticsearch` block:
#### Elasticsearch

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in the `elasticsearch` block:

```terraform
provider "elasticstack" {
Expand All @@ -49,16 +51,47 @@ provider "elasticstack" {
}
```

#### Kibana

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in the `kibana` block:

```terraform
provider "elasticstack" {
kibana {
username = "elastic"
password = "changeme"
endpoints = ["http://localhost:5601"]
}
}
```

If no credentials are supplied the provider will fall back to using those provided in the `elasticsearch` block.

### Environment Variables

You can provide your credentials for the default connection via the `ELASTICSEARCH_USERNAME`, `ELASTICSEARCH_PASSWORD` and comma-separated list `ELASTICSEARCH_ENDPOINTS`,
environment variables, representing your user, password and Elasticsearch API endpoints respectively.
The provider configuration can be specified through environment variables.

For Elasticsearch resources, you can use the following variables:
- `ELASTICSEARCH_USERNAME` - The username to use for Elasticsearch authentication
- `ELASTICSEARCH_PASSWORD` - The password to use for Elasticsearch authentication
- `ELASTICSEARCH_ENDPOINTS` - A comma separated list of Elasticsearch hosts to connect to
- `ELASTICSEARCH_API_KEY` - An Elasticsearch API key to use instead of `ELASTICSEARCH_USERNAME` and `ELASTICSEARCH_PASSWORD`

Kibana resources will re-use any Elasticsearch credentials specified, these may be overridden with the following variables:
- `KIBANA_USERNAME` - The username to use for Kibana authentication
- `KIBANA_PASSWORD` - The password to use for Kibana authentication
- `KIBANA_ENDPOINT` - The Kibana host to connect to

Alternatively the `ELASTICSEARCH_API_KEY` variable can be specified instead of `ELASTICSEARCH_USERNAME` and `ELASTICSEARCH_PASSWORD`.
Fleet resources will re-use any Kibana or Elasticsearch credentials specified, these may be overridden with the following variables:
- `FLEET_USERNAME` - The username to use for Kibana authentication
- `FLEET_PASSWORD` - The password to use for Kibana authentication
- `FLEET_ENDPOINT` - The Kibana host to connect to. ** Note the Fleet API is hosted within Kibana. This must be a Kibana HTTP host **
- `FLEET_API_KEY` - API key to use for authentication to Fleet

```terraform
provider "elasticstack" {
elasticsearch {}
kibana {}
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/kibana_action_connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Creates or updates a Kibana action connector. See https://www.elastic.co/guide/e

```terraform
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_action_connector" "example" {
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/kibana_alerting_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Creates or updates a Kibana alerting rule. See https://www.elastic.co/guide/en/k

```terraform
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_alerting_rule" "example" {
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/kibana_space.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Creates or updates a Kibana space. See https://www.elastic.co/guide/en/kibana/ma

```terraform
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_space" "example" {
Expand Down
7 changes: 7 additions & 0 deletions examples/provider/kibana.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "elasticstack" {
kibana {
username = "elastic"
password = "changeme"
endpoints = ["http://localhost:5601"]
}
}
2 changes: 1 addition & 1 deletion examples/provider/provider-env.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider "elasticstack" {
elasticsearch {}
kibana {}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_action_connector" "example" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_alerting_rule" "example" {
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/elasticstack_kibana_space/resource.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "elasticstack" {
elasticsearch {}
kibana {}
}

resource "elasticstack_kibana_space" "example" {
Expand Down
9 changes: 9 additions & 0 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ func buildFleetClient(d *schema.ResourceData, kibanaCfg kibana.Config) (*fleet.C
}
}

if v := os.Getenv("FLEET_ENDPOINT"); v != "" {
config.URL = v
}
if v := os.Getenv("FLEET_USERNAME"); v != "" {
config.Username = v
}
if v := os.Getenv("FLEET_PASSWORD"); v != "" {
config.Password = v
}
if v := os.Getenv("FLEET_API_KEY"); v != "" {
config.APIKey = v
}
Expand Down
32 changes: 28 additions & 4 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,44 @@ The following methods are supported:

### Static credentials

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in `elasticsearch` block:
#### Elasticsearch

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in the `elasticsearch` block:

{{tffile "examples/provider/provider.tf"}}

Alternatively an `api_key` can be specified instead of `username` and `password`:

{{tffile "examples/provider/provider-apikey.tf"}}

#### Kibana

Default static credentials can be provided by adding the `username`, `password` and `endpoints` in the `kibana` block:

{{tffile "examples/provider/kibana.tf"}}

If no credentials are supplied the provider will fall back to using those provided in the `elasticsearch` block.

### Environment Variables

You can provide your credentials for the default connection via the `ELASTICSEARCH_USERNAME`, `ELASTICSEARCH_PASSWORD` and comma-separated list `ELASTICSEARCH_ENDPOINTS`,
environment variables, representing your user, password and Elasticsearch API endpoints respectively.
The provider configuration can be specified through environment variables.

For Elasticsearch resources, you can use the following variables:
- `ELASTICSEARCH_USERNAME` - The username to use for Elasticsearch authentication
- `ELASTICSEARCH_PASSWORD` - The password to use for Elasticsearch authentication
- `ELASTICSEARCH_ENDPOINTS` - A comma separated list of Elasticsearch hosts to connect to
- `ELASTICSEARCH_API_KEY` - An Elasticsearch API key to use instead of `ELASTICSEARCH_USERNAME` and `ELASTICSEARCH_PASSWORD`

Kibana resources will re-use any Elasticsearch credentials specified, these may be overridden with the following variables:
- `KIBANA_USERNAME` - The username to use for Kibana authentication
- `KIBANA_PASSWORD` - The password to use for Kibana authentication
- `KIBANA_ENDPOINT` - The Kibana host to connect to

Alternatively the `ELASTICSEARCH_API_KEY` variable can be specified instead of `ELASTICSEARCH_USERNAME` and `ELASTICSEARCH_PASSWORD`.
Fleet resources will re-use any Kibana or Elasticsearch credentials specified, these may be overridden with the following variables:
- `FLEET_USERNAME` - The username to use for Kibana authentication
- `FLEET_PASSWORD` - The password to use for Kibana authentication
- `FLEET_ENDPOINT` - The Kibana host to connect to. ** Note the Fleet API is hosted within Kibana. This must be a Kibana HTTP host **
- `FLEET_API_KEY` - API key to use for authentication to Fleet

{{tffile "examples/provider/provider-env.tf"}}

Expand Down