UNPKG

@pulumi/aws

Version:

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

150 lines 5.42 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 * * ### Identity Schema * * #### Required * * * `repository` - (String) Name of the ECR repository. * * #### Optional * * * `account_id` (String) AWS Account where this resource is managed. * * * `region` (String) Region where this resource is managed. * * Using `pulumi import`, import ECR Lifecycle Policy using the name of the repository. For example: * * console * * % pulumi import aws_ecr_lifecycle_policy.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, { ...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?.policy; resourceInputs["region"] = state?.region; resourceInputs["registryId"] = state?.registryId; resourceInputs["repository"] = state?.repository; } else { const args = argsOrState; if (args?.policy === undefined && !opts.urn) { throw new Error("Missing required property 'policy'"); } if (args?.repository === undefined && !opts.urn) { throw new Error("Missing required property 'repository'"); } resourceInputs["policy"] = args?.policy; resourceInputs["region"] = args?.region; resourceInputs["repository"] = args?.repository; 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