Skip to content

Commit

Permalink
Add support for Snapshot Management (#125)
Browse files Browse the repository at this point in the history
* Add support for Snapshot Management

Signed-off-by: Philip Dubois <[email protected]>

* Add support for Snapshot Management

Signed-off-by: Philip Dubois <[email protected]>

* Fix liniting errors

Signed-off-by: Philip Dubois <[email protected]>

* Fix terrafmt

Signed-off-by: Philip Dubois <[email protected]>

* Extend example docs

Signed-off-by: Philip Dubois <[email protected]>

* Fix PR comments

Signed-off-by: Philip Dubois <[email protected]>

---------

Signed-off-by: Philip Dubois <[email protected]>
  • Loading branch information
duboisph authored Dec 12, 2023
1 parent 3a47818 commit 880a43b
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 0 deletions.
98 changes: 98 additions & 0 deletions docs/resources/sm_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "opensearch_sm_policy Resource - terraform-provider-opensearch"
subcategory: ""
description: |-
Provides an OpenSearch Snapshot Management (SM) policy. Please refer to the OpenSearch SM documentation for details.
---

# opensearch_sm_policy (Resource)

Provides an OpenSearch Snapshot Management (SM) policy. Please refer to the OpenSearch SM documentation for details.

## Example Usage

```terraform
# Create a snapshot repository. Make sure you also have created the bucket (eg.
# via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
resource "opensearch_snapshot_repository" "repo" {
name = "os-index-backups"
type = "s3"
settings = {
bucket = module.s3_snapshot.s3_bucket_id
region = module.s3_snapshot.s3_bucket_region
role_arn = aws_iam_role.snapshot_create.arn
server_side_encryption = true
}
}
# Create the SM policy
resource "opensearch_sm_policy" "snapshot_to_s3" {
policy_name = "snapshot_to_s3"
body = jsonencode({
"enabled" = true
"description" = "My snapshot policy"
"creation" = {
"schedule" = {
"cron" = {
"expression" = "0 0 * * *"
"timezone" = "UTC"
}
}
"time_limit" = "1h"
}
"deletion" = {
"schedule" = {
"cron" = {
"expression" = "0 0 * * *"
"timezone" = "UTC"
}
}
"condition" = {
"max_age" = "14d"
"max_count" = 400
"min_count" = 1
}
"time_limit" = "1h"
}
"snapshot_config" = {
"timezone" = "UTC"
"indices" = "*"
"repository" = opensearch_snapshot_repository.repo.name
}
})
}
```

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

### Required

- `body` (String) The policy document.
- `policy_name` (String) The name of the SM policy.

### Optional

- `primary_term` (Number) The primary term of the SM policy version.
- `seq_no` (Number) The sequence number of the SM policy version.

### Read-Only

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

```shell
terraform import opensearch_sm_policy.cleanup snapshot_to_s3
```
1 change: 1 addition & 0 deletions examples/resources/opensearch_sm_policy/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import opensearch_sm_policy.cleanup snapshot_to_s3
57 changes: 57 additions & 0 deletions examples/resources/opensearch_sm_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Create a snapshot repository. Make sure you also have created the bucket (eg.
# via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
resource "opensearch_snapshot_repository" "repo" {
name = "os-index-backups"
type = "s3"

settings = {
bucket = module.s3_snapshot.s3_bucket_id
region = module.s3_snapshot.s3_bucket_region
role_arn = aws_iam_role.snapshot_create.arn
server_side_encryption = true
}
}

# Create the SM policy
resource "opensearch_sm_policy" "snapshot_to_s3" {
policy_name = "snapshot_to_s3"

body = jsonencode({
"enabled" = true
"description" = "My snapshot policy"

"creation" = {
"schedule" = {
"cron" = {
"expression" = "0 0 * * *"
"timezone" = "UTC"
}
}

"time_limit" = "1h"
}

"deletion" = {
"schedule" = {
"cron" = {
"expression" = "0 0 * * *"
"timezone" = "UTC"
}
}

"condition" = {
"max_age" = "14d"
"max_count" = 400
"min_count" = 1
}

"time_limit" = "1h"
}

"snapshot_config" = {
"timezone" = "UTC"
"indices" = "*"
"repository" = opensearch_snapshot_repository.repo.name
}
})
}
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func Provider() *schema.Provider {
"opensearch_snapshot_repository": resourceOpensearchSnapshotRepository(),
"opensearch_channel_configuration": resourceOpenSearchChannelConfiguration(),
"opensearch_anomaly_detection": resourceOpenSearchAnomalyDetection(),
"opensearch_sm_policy": resourceOpenSearchSMPolicy(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
Loading

0 comments on commit 880a43b

Please sign in to comment.