1. Packages
  2. Opensearch Provider
  3. API Docs
  4. SmPolicy
opensearch 2.3.1 published on Monday, Apr 14, 2025 by opensearch-project

opensearch.SmPolicy

Explore with Pulumi AI

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

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as opensearch from "@pulumi/opensearch";

// Create a snapshot repository. Make sure you also have created the bucket (eg. 
// via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
const repo = new opensearch.SnapshotRepository("repo", {
    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
const snapshotToS3 = new opensearch.SmPolicy("snapshotToS3", {
    policyName: "snapshot_to_s3",
    body: pulumi.jsonStringify({
        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: repo.name,
        },
    }),
});
Copy
import pulumi
import json
import pulumi_opensearch as opensearch

# Create a snapshot repository. Make sure you also have created the bucket (eg. 
# via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
repo = opensearch.SnapshotRepository("repo",
    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
snapshot_to_s3 = opensearch.SmPolicy("snapshotToS3",
    policy_name="snapshot_to_s3",
    body=pulumi.Output.json_dumps({
        "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": repo.name,
        },
    }))
Copy
package main

import (
	"encoding/json"

	"github.com/pulumi/pulumi-terraform-provider/sdks/go/opensearch/v2/opensearch"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Create a snapshot repository. Make sure you also have created the bucket (eg.
		// via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
		repo, err := opensearch.NewSnapshotRepository(ctx, "repo", &opensearch.SnapshotRepositoryArgs{
			Type: pulumi.String("s3"),
			Settings: pulumi.StringMap{
				"bucket":                 pulumi.Any(module.S3_snapshot.S3_bucket_id),
				"region":                 pulumi.Any(module.S3_snapshot.S3_bucket_region),
				"role_arn":               pulumi.Any(aws_iam_role.Snapshot_create.Arn),
				"server_side_encryption": pulumi.String("true"),
			},
		})
		if err != nil {
			return err
		}
		// Create the SM policy
		_, err = opensearch.NewSmPolicy(ctx, "snapshotToS3", &opensearch.SmPolicyArgs{
			PolicyName: pulumi.String("snapshot_to_s3"),
			Body: repo.Name.ApplyT(func(name string) (pulumi.String, error) {
				var _zero pulumi.String
				tmpJSON0, err := json.Marshal(map[string]interface{}{
					"enabled":     true,
					"description": "My snapshot policy",
					"creation": map[string]interface{}{
						"schedule": map[string]interface{}{
							"cron": map[string]interface{}{
								"expression": "0 0 * * *",
								"timezone":   "UTC",
							},
						},
						"time_limit": "1h",
					},
					"deletion": map[string]interface{}{
						"schedule": map[string]interface{}{
							"cron": map[string]interface{}{
								"expression": "0 0 * * *",
								"timezone":   "UTC",
							},
						},
						"condition": map[string]interface{}{
							"max_age":   "14d",
							"max_count": 400,
							"min_count": 1,
						},
						"time_limit": "1h",
					},
					"snapshot_config": map[string]interface{}{
						"timezone":   "UTC",
						"indices":    "*",
						"repository": name,
					},
				})
				if err != nil {
					return _zero, err
				}
				json0 := string(tmpJSON0)
				return pulumi.String(json0), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Opensearch = Pulumi.Opensearch;

return await Deployment.RunAsync(() => 
{
    // Create a snapshot repository. Make sure you also have created the bucket (eg. 
    // via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
    var repo = new Opensearch.SnapshotRepository("repo", new()
    {
        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
    var snapshotToS3 = new Opensearch.SmPolicy("snapshotToS3", new()
    {
        PolicyName = "snapshot_to_s3",
        Body = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
        {
            ["enabled"] = true,
            ["description"] = "My snapshot policy",
            ["creation"] = new Dictionary<string, object?>
            {
                ["schedule"] = new Dictionary<string, object?>
                {
                    ["cron"] = new Dictionary<string, object?>
                    {
                        ["expression"] = "0 0 * * *",
                        ["timezone"] = "UTC",
                    },
                },
                ["time_limit"] = "1h",
            },
            ["deletion"] = new Dictionary<string, object?>
            {
                ["schedule"] = new Dictionary<string, object?>
                {
                    ["cron"] = new Dictionary<string, object?>
                    {
                        ["expression"] = "0 0 * * *",
                        ["timezone"] = "UTC",
                    },
                },
                ["condition"] = new Dictionary<string, object?>
                {
                    ["max_age"] = "14d",
                    ["max_count"] = 400,
                    ["min_count"] = 1,
                },
                ["time_limit"] = "1h",
            },
            ["snapshot_config"] = new Dictionary<string, object?>
            {
                ["timezone"] = "UTC",
                ["indices"] = "*",
                ["repository"] = repo.Name,
            },
        })),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.opensearch.SnapshotRepository;
import com.pulumi.opensearch.SnapshotRepositoryArgs;
import com.pulumi.opensearch.SmPolicy;
import com.pulumi.opensearch.SmPolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        // Create a snapshot repository. Make sure you also have created the bucket (eg. 
        // via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
        var repo = new SnapshotRepository("repo", SnapshotRepositoryArgs.builder()
            .type("s3")
            .settings(Map.ofEntries(
                Map.entry("bucket", module.s3_snapshot().s3_bucket_id()),
                Map.entry("region", module.s3_snapshot().s3_bucket_region()),
                Map.entry("role_arn", aws_iam_role.snapshot_create().arn()),
                Map.entry("server_side_encryption", true)
            ))
            .build());

        // Create the SM policy
        var snapshotToS3 = new SmPolicy("snapshotToS3", SmPolicyArgs.builder()
            .policyName("snapshot_to_s3")
            .body(repo.name().applyValue(name -> serializeJson(
                jsonObject(
                    jsonProperty("enabled", true),
                    jsonProperty("description", "My snapshot policy"),
                    jsonProperty("creation", jsonObject(
                        jsonProperty("schedule", jsonObject(
                            jsonProperty("cron", jsonObject(
                                jsonProperty("expression", "0 0 * * *"),
                                jsonProperty("timezone", "UTC")
                            ))
                        )),
                        jsonProperty("time_limit", "1h")
                    )),
                    jsonProperty("deletion", jsonObject(
                        jsonProperty("schedule", jsonObject(
                            jsonProperty("cron", jsonObject(
                                jsonProperty("expression", "0 0 * * *"),
                                jsonProperty("timezone", "UTC")
                            ))
                        )),
                        jsonProperty("condition", jsonObject(
                            jsonProperty("max_age", "14d"),
                            jsonProperty("max_count", 400),
                            jsonProperty("min_count", 1)
                        )),
                        jsonProperty("time_limit", "1h")
                    )),
                    jsonProperty("snapshot_config", jsonObject(
                        jsonProperty("timezone", "UTC"),
                        jsonProperty("indices", "*"),
                        jsonProperty("repository", name)
                    ))
                ))))
            .build());

    }
}
Copy
resources:
  # Create a snapshot repository. Make sure you also have created the bucket (eg. 
  # via `terraform-aws-modules/s3-bucket/aws`) and matching IAM role.
  repo:
    type: opensearch:SnapshotRepository
    properties:
      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
  snapshotToS3:
    type: opensearch:SmPolicy
    properties:
      policyName: snapshot_to_s3
      body:
        fn::toJSON:
          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: ${repo.name}
Copy

Create SmPolicy Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new SmPolicy(name: string, args: SmPolicyArgs, opts?: CustomResourceOptions);
@overload
def SmPolicy(resource_name: str,
             args: SmPolicyArgs,
             opts: Optional[ResourceOptions] = None)

@overload
def SmPolicy(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             body: Optional[str] = None,
             policy_name: Optional[str] = None,
             primary_term: Optional[float] = None,
             seq_no: Optional[float] = None,
             sm_policy_id: Optional[str] = None)
func NewSmPolicy(ctx *Context, name string, args SmPolicyArgs, opts ...ResourceOption) (*SmPolicy, error)
public SmPolicy(string name, SmPolicyArgs args, CustomResourceOptions? opts = null)
public SmPolicy(String name, SmPolicyArgs args)
public SmPolicy(String name, SmPolicyArgs args, CustomResourceOptions options)
type: opensearch:SmPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SmPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SmPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SmPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SmPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SmPolicyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var smPolicyResource = new Opensearch.SmPolicy("smPolicyResource", new()
{
    Body = "string",
    PolicyName = "string",
    PrimaryTerm = 0,
    SeqNo = 0,
    SmPolicyId = "string",
});
Copy
example, err := opensearch.NewSmPolicy(ctx, "smPolicyResource", &opensearch.SmPolicyArgs{
Body: pulumi.String("string"),
PolicyName: pulumi.String("string"),
PrimaryTerm: pulumi.Float64(0),
SeqNo: pulumi.Float64(0),
SmPolicyId: pulumi.String("string"),
})
Copy
var smPolicyResource = new SmPolicy("smPolicyResource", SmPolicyArgs.builder()
    .body("string")
    .policyName("string")
    .primaryTerm(0)
    .seqNo(0)
    .smPolicyId("string")
    .build());
Copy
sm_policy_resource = opensearch.SmPolicy("smPolicyResource",
    body="string",
    policy_name="string",
    primary_term=0,
    seq_no=0,
    sm_policy_id="string")
Copy
const smPolicyResource = new opensearch.SmPolicy("smPolicyResource", {
    body: "string",
    policyName: "string",
    primaryTerm: 0,
    seqNo: 0,
    smPolicyId: "string",
});
Copy
type: opensearch:SmPolicy
properties:
    body: string
    policyName: string
    primaryTerm: 0
    seqNo: 0
    smPolicyId: string
Copy

SmPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The SmPolicy resource accepts the following input properties:

Body This property is required. string
The policy document.
PolicyName This property is required. string
The name of the SM policy.
PrimaryTerm double
The primary term of the SM policy version.
SeqNo double
The sequence number of the SM policy version.
SmPolicyId string
The ID of this resource.
Body This property is required. string
The policy document.
PolicyName This property is required. string
The name of the SM policy.
PrimaryTerm float64
The primary term of the SM policy version.
SeqNo float64
The sequence number of the SM policy version.
SmPolicyId string
The ID of this resource.
body This property is required. String
The policy document.
policyName This property is required. String
The name of the SM policy.
primaryTerm Double
The primary term of the SM policy version.
seqNo Double
The sequence number of the SM policy version.
smPolicyId String
The ID of this resource.
body This property is required. string
The policy document.
policyName This property is required. string
The name of the SM policy.
primaryTerm number
The primary term of the SM policy version.
seqNo number
The sequence number of the SM policy version.
smPolicyId string
The ID of this resource.
body This property is required. str
The policy document.
policy_name This property is required. str
The name of the SM policy.
primary_term float
The primary term of the SM policy version.
seq_no float
The sequence number of the SM policy version.
sm_policy_id str
The ID of this resource.
body This property is required. String
The policy document.
policyName This property is required. String
The name of the SM policy.
primaryTerm Number
The primary term of the SM policy version.
seqNo Number
The sequence number of the SM policy version.
smPolicyId String
The ID of this resource.

Outputs

All input properties are implicitly available as output properties. Additionally, the SmPolicy resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing SmPolicy Resource

Get an existing SmPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SmPolicyState, opts?: CustomResourceOptions): SmPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        body: Optional[str] = None,
        policy_name: Optional[str] = None,
        primary_term: Optional[float] = None,
        seq_no: Optional[float] = None,
        sm_policy_id: Optional[str] = None) -> SmPolicy
func GetSmPolicy(ctx *Context, name string, id IDInput, state *SmPolicyState, opts ...ResourceOption) (*SmPolicy, error)
public static SmPolicy Get(string name, Input<string> id, SmPolicyState? state, CustomResourceOptions? opts = null)
public static SmPolicy get(String name, Output<String> id, SmPolicyState state, CustomResourceOptions options)
resources:  _:    type: opensearch:SmPolicy    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Body string
The policy document.
PolicyName string
The name of the SM policy.
PrimaryTerm double
The primary term of the SM policy version.
SeqNo double
The sequence number of the SM policy version.
SmPolicyId string
The ID of this resource.
Body string
The policy document.
PolicyName string
The name of the SM policy.
PrimaryTerm float64
The primary term of the SM policy version.
SeqNo float64
The sequence number of the SM policy version.
SmPolicyId string
The ID of this resource.
body String
The policy document.
policyName String
The name of the SM policy.
primaryTerm Double
The primary term of the SM policy version.
seqNo Double
The sequence number of the SM policy version.
smPolicyId String
The ID of this resource.
body string
The policy document.
policyName string
The name of the SM policy.
primaryTerm number
The primary term of the SM policy version.
seqNo number
The sequence number of the SM policy version.
smPolicyId string
The ID of this resource.
body str
The policy document.
policy_name str
The name of the SM policy.
primary_term float
The primary term of the SM policy version.
seq_no float
The sequence number of the SM policy version.
sm_policy_id str
The ID of this resource.
body String
The policy document.
policyName String
The name of the SM policy.
primaryTerm Number
The primary term of the SM policy version.
seqNo Number
The sequence number of the SM policy version.
smPolicyId String
The ID of this resource.

Import

$ pulumi import opensearch:index/smPolicy:SmPolicy cleanup snapshot_to_s3
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
opensearch opensearch-project/terraform-provider-opensearch
License
Notes
This Pulumi package is based on the opensearch Terraform Provider.