Skip to content

Commit

Permalink
Merge pull request #22 from olksdr/feat/slm-policy
Browse files Browse the repository at this point in the history
Add new resource to manage SLM policies
  • Loading branch information
olksdr authored Dec 6, 2021
2 parents 4a46737 + 5671c52 commit 3a2ece5
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 0 deletions.
89 changes: 89 additions & 0 deletions docs/resources/elasticsearch_snapshot_lifecycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "elasticstack_elasticsearch_snapshot_lifecycle Resource - terraform-provider-elasticstack"
subcategory: ""
description: |-
Creates or updates a snapshot lifecycle policy. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put-policy.html
---

# elasticstack_elasticsearch_snapshot_lifecycle (Resource)

Creates or updates a snapshot lifecycle policy. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put-policy.html

## Example Usage

```terraform
provider "elasticstack" {
elasticsearch {}
}
// create a repository for snapshots
resource "elasticstack_elasticsearch_snapshot_repository" "repo" {
name = "my_snap_repo"
fs {
location = "/tmp/snapshots"
compress = true
max_restore_bytes_per_sec = "20mb"
}
}
// create a SLM policy and use the above created repository
resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" {
name = "my_slm_policy"
schedule = "0 30 1 * * ?"
snapshot_name = "<daily-snap-{now/d}>"
repository = elasticstack_elasticsearch_snapshot_repository.repo.name
indices = ["data-*", "important"]
ignore_unavailable = false
include_global_state = false
expire_after = "30d"
min_count = 5
max_count = 50
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **name** (String) ID for the snapshot lifecycle policy you want to create or update.
- **repository** (String) Repository used to store snapshots created by this policy.
- **schedule** (String) Periodic or absolute schedule at which the policy creates snapshots.

### Optional

- **elasticsearch_connection** (Block List, Max: 1) Used to establish connection to Elasticsearch server. Overrides environment variables if present. (see [below for nested schema](#nestedblock--elasticsearch_connection))
- **expand_wildcards** (String) Determines how wildcard patterns in the `indices` parameter match data streams and indices. Supports comma-separated values, such as `closed,hidden`.
- **expire_after** (String) Time period after which a snapshot is considered expired and eligible for deletion.
- **feature_states** (Set of String) Feature states to include in the snapshot.
- **id** (String) The ID of this resource.
- **ignore_unavailable** (Boolean) If `false`, the snapshot fails if any data stream or index in indices is missing or closed. If `true`, the snapshot ignores missing or closed data streams and indices.
- **include_global_state** (Boolean) If `true`, include the cluster state in the snapshot.
- **indices** (Set of String) Comma-separated list of data streams and indices to include in the snapshot.
- **max_count** (Number) Maximum number of snapshots to retain, even if the snapshots have not yet expired.
- **metadata** (String) Attaches arbitrary metadata to the snapshot.
- **min_count** (Number) Minimum number of snapshots to retain, even if the snapshots have expired.
- **partial** (Boolean) If `false`, the entire snapshot will fail if one or more indices included in the snapshot do not have all primary shards available.
- **snapshot_name** (String) Name automatically assigned to each snapshot created by the policy.

<a id="nestedblock--elasticsearch_connection"></a>
### Nested Schema for `elasticsearch_connection`

Optional:

- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.
- **username** (String) A username to use for API authentication to Elasticsearch.

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_elasticsearch_snapshot_lifecycle.my_policy <cluster_uuid>/<slm policy name>
```
6 changes: 6 additions & 0 deletions docs/resources/elasticsearch_snapshot_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@ Optional:
- **max_snapshot_bytes_per_sec** (String) Maximum snapshot creation rate per node.
- **readonly** (Boolean) If true, the repository is read-only.

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_elasticsearch_snapshot_repository.my_repository <cluster_uuid>/<repository name>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import elasticstack_elasticsearch_snapshot_lifecycle.my_policy <cluster_uuid>/<slm policy name>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
provider "elasticstack" {
elasticsearch {}
}

// create a repository for snapshots
resource "elasticstack_elasticsearch_snapshot_repository" "repo" {
name = "my_snap_repo"

fs {
location = "/tmp/snapshots"
compress = true
max_restore_bytes_per_sec = "20mb"
}
}

// create a SLM policy and use the above created repository
resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" {
name = "my_slm_policy"

schedule = "0 30 1 * * ?"
snapshot_name = "<daily-snap-{now/d}>"
repository = elasticstack_elasticsearch_snapshot_repository.repo.name

indices = ["data-*", "important"]
ignore_unavailable = false
include_global_state = false

expire_after = "30d"
min_count = 5
max_count = 50
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import elasticstack_elasticsearch_snapshot_repository.my_repository <cluster_uuid>/<repository name>
Loading

0 comments on commit 3a2ece5

Please sign in to comment.