UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

138 lines 5.24 kB
"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"); /** * Manages an ECR repository lifecycle policy. * * > **NOTE:** Only one `aws.ecr.LifecyclePolicy` resource can be used with the same ECR repository. To apply multiple rules, they must be combined in the `policy` JSON. * * > **NOTE:** The AWS ECR API seems to reorder rules based on `rulePriority`. If you define multiple rules that are not sorted in ascending `rulePriority` order in the this provider code, the resource will be flagged for recreation every deployment. * * ## Example Usage * * ### Policy on untagged image * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ecr.Repository("example", {name: "example-repo"}); * const exampleLifecyclePolicy = new aws.ecr.LifecyclePolicy("example", { * repository: example.name, * policy: `{ * "rules": [ * { * "rulePriority": 1, * "description": "Expire images older than 14 days", * "selection": { * "tagStatus": "untagged", * "countType": "sinceImagePushed", * "countUnit": "days", * "countNumber": 14 * }, * "action": { * "type": "expire" * } * } * ] * } * `, * }); * ``` * * ### Policy on tagged image * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ecr.Repository("example", {name: "example-repo"}); * const exampleLifecyclePolicy = new aws.ecr.LifecyclePolicy("example", { * repository: example.name, * policy: `{ * "rules": [ * { * "rulePriority": 1, * "description": "Keep last 30 images", * "selection": { * "tagStatus": "tagged", * "tagPrefixList": ["v"], * "countType": "imageCountMoreThan", * "countNumber": 30 * }, * "action": { * "type": "expire" * } * } * ] * } * `, * }); * ``` * * ## Import * * Using `pulumi import`, import ECR Lifecycle Policy using the name of the repository. For example: * * ```sh * $ pulumi import aws:ecr/lifecyclePolicy:LifecyclePolicy example tf-example * ``` */ 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, Object.assign(Object.assign({}, 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["policy"] = state ? state.policy : undefined; resourceInputs["region"] = state ? state.region : undefined; resourceInputs["registryId"] = state ? state.registryId : undefined; resourceInputs["repository"] = state ? state.repository : undefined; } else { const args = argsOrState; if ((!args || args.policy === undefined) && !opts.urn) { throw new Error("Missing required property 'policy'"); } if ((!args || args.repository === undefined) && !opts.urn) { throw new Error("Missing required property 'repository'"); } resourceInputs["policy"] = args ? args.policy : undefined; resourceInputs["region"] = args ? args.region : undefined; resourceInputs["repository"] = args ? args.repository : undefined; resourceInputs["registryId"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(LifecyclePolicy.__pulumiType, name, resourceInputs, opts); } } exports.LifecyclePolicy = LifecyclePolicy; /** @internal */ LifecyclePolicy.__pulumiType = 'aws:ecr/lifecyclePolicy:LifecyclePolicy'; //# sourceMappingURL=lifecyclePolicy.js.map