@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
329 lines • 11.4 kB
JavaScript
"use strict";
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.LifecyclePolicy = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Provides a [Data Lifecycle Manager (DLM) lifecycle policy](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/snapshot-lifecycle.html) for managing snapshots.
*
* ## Example Usage
*
* ### Basic
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const assumeRole = aws.iam.getPolicyDocument({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["dlm.amazonaws.com"],
* }],
* actions: ["sts:AssumeRole"],
* }],
* });
* const dlmLifecycleRole = new aws.iam.Role("dlm_lifecycle_role", {
* name: "dlm-lifecycle-role",
* assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
* });
* const dlmLifecycle = aws.iam.getPolicyDocument({
* statements: [
* {
* effect: "Allow",
* actions: [
* "ec2:CreateSnapshot",
* "ec2:CreateSnapshots",
* "ec2:DeleteSnapshot",
* "ec2:DescribeInstances",
* "ec2:DescribeVolumes",
* "ec2:DescribeSnapshots",
* ],
* resources: ["*"],
* },
* {
* effect: "Allow",
* actions: ["ec2:CreateTags"],
* resources: ["arn:aws:ec2:*::snapshot/*"],
* },
* ],
* });
* const dlmLifecycleRolePolicy = new aws.iam.RolePolicy("dlm_lifecycle", {
* name: "dlm-lifecycle-policy",
* role: dlmLifecycleRole.id,
* policy: dlmLifecycle.then(dlmLifecycle => dlmLifecycle.json),
* });
* const example = new aws.dlm.LifecyclePolicy("example", {
* description: "example DLM lifecycle policy",
* executionRoleArn: dlmLifecycleRole.arn,
* state: "ENABLED",
* policyDetails: {
* resourceTypes: ["VOLUME"],
* schedules: [{
* name: "2 weeks of daily snapshots",
* createRule: {
* interval: 24,
* intervalUnit: "HOURS",
* times: "23:45",
* },
* retainRule: {
* count: 14,
* },
* tagsToAdd: {
* SnapshotCreator: "DLM",
* },
* copyTags: false,
* }],
* targetTags: {
* Snapshot: "true",
* },
* },
* });
* ```
*
* ### Example Default Policy
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.dlm.LifecyclePolicy("example", {
* description: "tf-acc-basic",
* executionRoleArn: exampleAwsIamRole.arn,
* defaultPolicy: "VOLUME",
* policyDetails: {
* createInterval: 5,
* resourceType: "VOLUME",
* policyLanguage: "SIMPLIFIED",
* exclusions: {
* excludeBootVolumes: false,
* excludeTags: {
* test: "exclude",
* },
* excludeVolumeTypes: ["gp2"],
* },
* },
* });
* ```
*
* ### Example Cross-Region Snapshot Copy Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* // ...other configuration...
* const current = aws.getCallerIdentity({});
* const key = current.then(current => aws.iam.getPolicyDocument({
* statements: [{
* sid: "Enable IAM User Permissions",
* effect: "Allow",
* principals: [{
* type: "AWS",
* identifiers: [`arn:aws:iam::${current.accountId}:root`],
* }],
* actions: ["kms:*"],
* resources: ["*"],
* }],
* }));
* const dlmCrossRegionCopyCmk = new aws.kms.Key("dlm_cross_region_copy_cmk", {
* description: "Example Alternate Region KMS Key",
* policy: key.then(key => key.json),
* });
* const example = new aws.dlm.LifecyclePolicy("example", {
* description: "example DLM lifecycle policy",
* executionRoleArn: dlmLifecycleRole.arn,
* state: "ENABLED",
* policyDetails: {
* resourceTypes: ["VOLUME"],
* schedules: [{
* name: "2 weeks of daily snapshots",
* createRule: {
* interval: 24,
* intervalUnit: "HOURS",
* times: "23:45",
* },
* retainRule: {
* count: 14,
* },
* tagsToAdd: {
* SnapshotCreator: "DLM",
* },
* copyTags: false,
* crossRegionCopyRules: [{
* target: "us-west-2",
* encrypted: true,
* cmkArn: dlmCrossRegionCopyCmk.arn,
* copyTags: true,
* retainRule: {
* interval: 30,
* intervalUnit: "DAYS",
* },
* }],
* }],
* targetTags: {
* Snapshot: "true",
* },
* },
* });
* ```
*
* ### Example Event Based Policy Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const current = aws.getCallerIdentity({});
* const exampleLifecyclePolicy = new aws.dlm.LifecyclePolicy("example", {
* description: "tf-acc-basic",
* executionRoleArn: exampleAwsIamRole.arn,
* policyDetails: {
* policyType: "EVENT_BASED_POLICY",
* action: {
* name: "tf-acc-basic",
* crossRegionCopies: [{
* encryptionConfiguration: {},
* retainRule: {
* interval: 15,
* intervalUnit: "MONTHS",
* },
* target: "us-east-1",
* }],
* },
* eventSource: {
* type: "MANAGED_CWE",
* parameters: {
* descriptionRegex: "^.*Created for policy: policy-1234567890abcdef0.*$",
* eventType: "shareSnapshot",
* snapshotOwners: [current.then(current => current.accountId)],
* },
* },
* },
* });
* const example = aws.iam.getPolicy({
* name: "AWSDataLifecycleManagerServiceRole",
* });
* const exampleRolePolicyAttachment = new aws.iam.RolePolicyAttachment("example", {
* role: exampleAwsIamRole.id,
* policyArn: example.then(example => example.arn),
* });
* ```
*
* ### Example Post/Pre Scripts
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const test = aws.iam.getPolicy({
* name: "AWSDataLifecycleManagerSSMFullAccess",
* });
* const example = new aws.iam.RolePolicyAttachment("example", {
* role: testAwsIamRole.id,
* policyArn: exampleAwsIamPolicy.arn,
* });
* const exampleLifecyclePolicy = new aws.dlm.LifecyclePolicy("example", {
* description: "tf-acc-basic",
* executionRoleArn: exampleAwsIamRole.arn,
* policyDetails: {
* resourceTypes: ["INSTANCE"],
* schedules: [{
* name: "Windows VSS",
* createRule: {
* interval: 12,
* scripts: {
* executeOperationOnScriptFailure: false,
* executionHandler: "AWS_VSS_BACKUP",
* maximumRetryCount: 2,
* },
* },
* retainRule: {
* count: 10,
* },
* }],
* targetTags: {
* tag1: "Windows",
* },
* },
* });
* ```
*
* ## Import
*
* Using `pulumi import`, import DLM lifecycle policies using their policy ID. For example:
*
* ```sh
* $ pulumi import aws:dlm/lifecyclePolicy:LifecyclePolicy example policy-abcdef12345678901
* ```
*/
class LifecyclePolicy extends pulumi.CustomResource {
/**
* Get an existing LifecyclePolicy resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new LifecyclePolicy(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of LifecyclePolicy. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === LifecyclePolicy.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["arn"] = state?.arn;
resourceInputs["defaultPolicy"] = state?.defaultPolicy;
resourceInputs["description"] = state?.description;
resourceInputs["executionRoleArn"] = state?.executionRoleArn;
resourceInputs["policyDetails"] = state?.policyDetails;
resourceInputs["region"] = state?.region;
resourceInputs["state"] = state?.state;
resourceInputs["tags"] = state?.tags;
resourceInputs["tagsAll"] = state?.tagsAll;
}
else {
const args = argsOrState;
if (args?.description === undefined && !opts.urn) {
throw new Error("Missing required property 'description'");
}
if (args?.executionRoleArn === undefined && !opts.urn) {
throw new Error("Missing required property 'executionRoleArn'");
}
if (args?.policyDetails === undefined && !opts.urn) {
throw new Error("Missing required property 'policyDetails'");
}
resourceInputs["defaultPolicy"] = args?.defaultPolicy;
resourceInputs["description"] = args?.description;
resourceInputs["executionRoleArn"] = args?.executionRoleArn;
resourceInputs["policyDetails"] = args?.policyDetails;
resourceInputs["region"] = args?.region;
resourceInputs["state"] = args?.state;
resourceInputs["tags"] = args?.tags;
resourceInputs["arn"] = undefined /*out*/;
resourceInputs["tagsAll"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(LifecyclePolicy.__pulumiType, name, resourceInputs, opts);
}
}
exports.LifecyclePolicy = LifecyclePolicy;
/** @internal */
LifecyclePolicy.__pulumiType = 'aws:dlm/lifecyclePolicy:LifecyclePolicy';
//# sourceMappingURL=lifecyclePolicy.js.map