1. Packages
  2. AWS Classic
  3. API Docs
  4. ecr
  5. getLifecyclePolicyDocument

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

aws.ecr.getLifecyclePolicyDocument

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

    Generates an ECR lifecycle policy document in JSON format. Can be used with resources such as the aws.ecr.LifecyclePolicy resource.

    For more information about building AWS ECR lifecycle policy documents, see the AWS ECR Lifecycle Policy Document Guide.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = aws.ecr.getLifecyclePolicyDocument({
        rules: [{
            priority: 1,
            description: "This is a test.",
            selection: {
                tagStatus: "tagged",
                tagPrefixLists: ["prod"],
                countType: "imageCountMoreThan",
                countNumber: 100,
            },
        }],
    });
    const exampleLifecyclePolicy = new aws.ecr.LifecyclePolicy("example", {
        repository: exampleAwsEcrRepository.name,
        policy: example.then(example => example.json),
    });
    
    import pulumi
    import pulumi_aws as aws
    
    example = aws.ecr.get_lifecycle_policy_document(rules=[{
        "priority": 1,
        "description": "This is a test.",
        "selection": {
            "tagStatus": "tagged",
            "tagPrefixLists": ["prod"],
            "countType": "imageCountMoreThan",
            "countNumber": 100,
        },
    }])
    example_lifecycle_policy = aws.ecr.LifecyclePolicy("example",
        repository=example_aws_ecr_repository["name"],
        policy=example.json)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecr"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := ecr.GetLifecyclePolicyDocument(ctx, &ecr.GetLifecyclePolicyDocumentArgs{
    			Rules: []ecr.GetLifecyclePolicyDocumentRule{
    				{
    					Priority:    1,
    					Description: pulumi.StringRef("This is a test."),
    					Selection: {
    						TagStatus: "tagged",
    						TagPrefixLists: []string{
    							"prod",
    						},
    						CountType:   "imageCountMoreThan",
    						CountNumber: 100,
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = ecr.NewLifecyclePolicy(ctx, "example", &ecr.LifecyclePolicyArgs{
    			Repository: pulumi.Any(exampleAwsEcrRepository.Name),
    			Policy:     pulumi.String(example.Json),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Aws.Ecr.GetLifecyclePolicyDocument.Invoke(new()
        {
            Rules = new[]
            {
                new Aws.Ecr.Inputs.GetLifecyclePolicyDocumentRuleInputArgs
                {
                    Priority = 1,
                    Description = "This is a test.",
                    Selection = new Aws.Ecr.Inputs.GetLifecyclePolicyDocumentRuleSelectionInputArgs
                    {
                        TagStatus = "tagged",
                        TagPrefixLists = new[]
                        {
                            "prod",
                        },
                        CountType = "imageCountMoreThan",
                        CountNumber = 100,
                    },
                },
            },
        });
    
        var exampleLifecyclePolicy = new Aws.Ecr.LifecyclePolicy("example", new()
        {
            Repository = exampleAwsEcrRepository.Name,
            Policy = example.Apply(getLifecyclePolicyDocumentResult => getLifecyclePolicyDocumentResult.Json),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.ecr.EcrFunctions;
    import com.pulumi.aws.ecr.inputs.GetLifecyclePolicyDocumentArgs;
    import com.pulumi.aws.ecr.LifecyclePolicy;
    import com.pulumi.aws.ecr.LifecyclePolicyArgs;
    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) {
            final var example = EcrFunctions.getLifecyclePolicyDocument(GetLifecyclePolicyDocumentArgs.builder()
                .rules(GetLifecyclePolicyDocumentRuleArgs.builder()
                    .priority(1)
                    .description("This is a test.")
                    .selection(GetLifecyclePolicyDocumentRuleSelectionArgs.builder()
                        .tagStatus("tagged")
                        .tagPrefixLists("prod")
                        .countType("imageCountMoreThan")
                        .countNumber(100)
                        .build())
                    .build())
                .build());
    
            var exampleLifecyclePolicy = new LifecyclePolicy("exampleLifecyclePolicy", LifecyclePolicyArgs.builder()
                .repository(exampleAwsEcrRepository.name())
                .policy(example.applyValue(getLifecyclePolicyDocumentResult -> getLifecyclePolicyDocumentResult.json()))
                .build());
    
        }
    }
    
    resources:
      exampleLifecyclePolicy:
        type: aws:ecr:LifecyclePolicy
        name: example
        properties:
          repository: ${exampleAwsEcrRepository.name}
          policy: ${example.json}
    variables:
      example:
        fn::invoke:
          Function: aws:ecr:getLifecyclePolicyDocument
          Arguments:
            rules:
              - priority: 1
                description: This is a test.
                selection:
                  tagStatus: tagged
                  tagPrefixLists:
                    - prod
                  countType: imageCountMoreThan
                  countNumber: 100
    

    Using getLifecyclePolicyDocument

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getLifecyclePolicyDocument(args: GetLifecyclePolicyDocumentArgs, opts?: InvokeOptions): Promise<GetLifecyclePolicyDocumentResult>
    function getLifecyclePolicyDocumentOutput(args: GetLifecyclePolicyDocumentOutputArgs, opts?: InvokeOptions): Output<GetLifecyclePolicyDocumentResult>
    def get_lifecycle_policy_document(rules: Optional[Sequence[GetLifecyclePolicyDocumentRule]] = None,
                                      opts: Optional[InvokeOptions] = None) -> GetLifecyclePolicyDocumentResult
    def get_lifecycle_policy_document_output(rules: Optional[pulumi.Input[Sequence[pulumi.Input[GetLifecyclePolicyDocumentRuleArgs]]]] = None,
                                      opts: Optional[InvokeOptions] = None) -> Output[GetLifecyclePolicyDocumentResult]
    func GetLifecyclePolicyDocument(ctx *Context, args *GetLifecyclePolicyDocumentArgs, opts ...InvokeOption) (*GetLifecyclePolicyDocumentResult, error)
    func GetLifecyclePolicyDocumentOutput(ctx *Context, args *GetLifecyclePolicyDocumentOutputArgs, opts ...InvokeOption) GetLifecyclePolicyDocumentResultOutput

    > Note: This function is named GetLifecyclePolicyDocument in the Go SDK.

    public static class GetLifecyclePolicyDocument 
    {
        public static Task<GetLifecyclePolicyDocumentResult> InvokeAsync(GetLifecyclePolicyDocumentArgs args, InvokeOptions? opts = null)
        public static Output<GetLifecyclePolicyDocumentResult> Invoke(GetLifecyclePolicyDocumentInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetLifecyclePolicyDocumentResult> getLifecyclePolicyDocument(GetLifecyclePolicyDocumentArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:ecr/getLifecyclePolicyDocument:getLifecyclePolicyDocument
      arguments:
        # arguments dictionary

    The following arguments are supported:

    getLifecyclePolicyDocument Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Json string
    The above arguments serialized as a standard JSON policy document.
    Rules List<GetLifecyclePolicyDocumentRule>
    Id string
    The provider-assigned unique ID for this managed resource.
    Json string
    The above arguments serialized as a standard JSON policy document.
    Rules []GetLifecyclePolicyDocumentRule
    id String
    The provider-assigned unique ID for this managed resource.
    json String
    The above arguments serialized as a standard JSON policy document.
    rules List<GetLifecyclePolicyDocumentRule>
    id string
    The provider-assigned unique ID for this managed resource.
    json string
    The above arguments serialized as a standard JSON policy document.
    rules GetLifecyclePolicyDocumentRule[]
    id str
    The provider-assigned unique ID for this managed resource.
    json str
    The above arguments serialized as a standard JSON policy document.
    rules Sequence[GetLifecyclePolicyDocumentRule]
    id String
    The provider-assigned unique ID for this managed resource.
    json String
    The above arguments serialized as a standard JSON policy document.
    rules List<Property Map>

    Supporting Types

    GetLifecyclePolicyDocumentRule

    Priority int
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    Action GetLifecyclePolicyDocumentRuleAction
    Specifies the action type.
    Description string
    Describes the purpose of a rule within a lifecycle policy.
    Selection GetLifecyclePolicyDocumentRuleSelection
    Collects parameters describing the selection criteria for the ECR lifecycle policy:
    Priority int
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    Action GetLifecyclePolicyDocumentRuleAction
    Specifies the action type.
    Description string
    Describes the purpose of a rule within a lifecycle policy.
    Selection GetLifecyclePolicyDocumentRuleSelection
    Collects parameters describing the selection criteria for the ECR lifecycle policy:
    priority Integer
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    action GetLifecyclePolicyDocumentRuleAction
    Specifies the action type.
    description String
    Describes the purpose of a rule within a lifecycle policy.
    selection GetLifecyclePolicyDocumentRuleSelection
    Collects parameters describing the selection criteria for the ECR lifecycle policy:
    priority number
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    action GetLifecyclePolicyDocumentRuleAction
    Specifies the action type.
    description string
    Describes the purpose of a rule within a lifecycle policy.
    selection GetLifecyclePolicyDocumentRuleSelection
    Collects parameters describing the selection criteria for the ECR lifecycle policy:
    priority int
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    action GetLifecyclePolicyDocumentRuleAction
    Specifies the action type.
    description str
    Describes the purpose of a rule within a lifecycle policy.
    selection GetLifecyclePolicyDocumentRuleSelection
    Collects parameters describing the selection criteria for the ECR lifecycle policy:
    priority Number
    Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with a tag_status value of any must have the highest value for priority and be evaluated last.
    action Property Map
    Specifies the action type.
    description String
    Describes the purpose of a rule within a lifecycle policy.
    selection Property Map
    Collects parameters describing the selection criteria for the ECR lifecycle policy:

    GetLifecyclePolicyDocumentRuleAction

    Type string
    The supported value is expire.
    Type string
    The supported value is expire.
    type String
    The supported value is expire.
    type string
    The supported value is expire.
    type str
    The supported value is expire.
    type String
    The supported value is expire.

    GetLifecyclePolicyDocumentRuleSelection

    CountNumber int
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    CountType string
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    TagStatus string
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    CountUnit string
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    TagPatternLists List<string>
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    TagPrefixLists List<string>
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
    CountNumber int
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    CountType string
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    TagStatus string
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    CountUnit string
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    TagPatternLists []string
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    TagPrefixLists []string
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
    countNumber Integer
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    countType String
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    tagStatus String
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    countUnit String
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    tagPatternLists List<String>
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    tagPrefixLists List<String>
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
    countNumber number
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    countType string
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    tagStatus string
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    countUnit string
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    tagPatternLists string[]
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    tagPrefixLists string[]
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
    count_number int
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    count_type str
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    tag_status str
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    count_unit str
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    tag_pattern_lists Sequence[str]
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    tag_prefix_lists Sequence[str]
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
    countNumber Number
    Specify a count number. If the count_type used is imageCountMoreThan, then the value is the maximum number of images that you want to retain in your repository. If the count_type used is sinceImagePushed, then the value is the maximum age limit for your images.
    countType String
    Specify a count type to apply to the images. If count_type is set to imageCountMoreThan, you also specify count_number to create a rule that sets a limit on the number of images that exist in your repository. If count_type is set to sinceImagePushed, you also specify count_unit and count_number to specify a time limit on the images that exist in your repository.
    tagStatus String
    Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule applied to them. If you specify tagged, then you must also specify a tag_prefix_list value. If you specify untagged, then you must omit tag_prefix_list.
    countUnit String
    Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
    tagPatternLists List<String>
    You must specify a comma-separated list of image tag patterns that may contain wildcards () on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag pattern list prod to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards () per string. For example, ["test123", "test123*"] is valid but ["test*1*2*3*4*5*6"] is invalid.
    tagPrefixLists List<String>
    You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them. If you specify multiple tags, only images with all specified tags are selected.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi