LifecyclePolicy class

Manages an Image Builder Lifecycle Policy.

Example Usage

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

const current = aws.getRegion({});
const currentGetPartition = aws.getPartition({});
const example = new aws.iam.Role("example", {
    assumeRolePolicy: JSON.stringify({
        Version: "2012-10-17",
        Statement: [{
            Action: "sts:AssumeRole",
            Effect: "Allow",
            Principal: {
                Service: currentGetPartition.then(currentGetPartition => `imagebuilder.${currentGetPartition.dnsSuffix}`),
            },
        }],
    }),
    name: "example",
});
const exampleRolePolicyAttachment = new aws.iam.RolePolicyAttachment("example", {
    policyArn: currentGetPartition.then(currentGetPartition => `arn:${currentGetPartition.partition}:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy`),
    role: example.name,
});
const exampleLifecyclePolicy = new aws.imagebuilder.LifecyclePolicy("example", {
    resourceSelection: {
        tagMap: {
            key1: "value1",
            key2: "value2",
        },
    },
    policyDetails: [{
        action: {
            type: "DELETE",
        },
        filter: {
            type: "AGE",
            value: 6,
            retainAtLeast: 10,
            unit: "YEARS",
        },
    }],
    name: "name",
    description: "Example description",
    executionRole: example.arn,
    resourceType: "AMI_IMAGE",
}, {
    dependsOn: [exampleRolePolicyAttachment],
});
import pulumi
import json
import pulumi_aws as aws

current = aws.get_region()
current_get_partition = aws.get_partition()
example = aws.iam.Role("example",
    assume_role_policy=json.dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Action": "sts:AssumeRole",
            "Effect": "Allow",
            "Principal": {
                "Service": f"imagebuilder.{current_get_partition.dns_suffix}",
            },
        }],
    }),
    name="example")
example_role_policy_attachment = aws.iam.RolePolicyAttachment("example",
    policy_arn=f"arn:{current_get_partition.partition}:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy",
    role=example.name)
example_lifecycle_policy = aws.imagebuilder.LifecyclePolicy("example",
    resource_selection={
        "tag_map": {
            "key1": "value1",
            "key2": "value2",
        },
    },
    policy_details=[{
        "action": {
            "type": "DELETE",
        },
        "filter": {
            "type": "AGE",
            "value": 6,
            "retain_at_least": 10,
            "unit": "YEARS",
        },
    }],
    name="name",
    description="Example description",
    execution_role=example.arn,
    resource_type="AMI_IMAGE",
    opts = pulumi.ResourceOptions(depends_on=[example_role_policy_attachment]))
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var current = Aws.GetRegion.Invoke();

    var currentGetPartition = Aws.GetPartition.Invoke();

    var example = new Aws.Iam.Role("example", new()
    {
        AssumeRolePolicy = JsonSerializer.Serialize(new Dictionary<string, object?>
        {
            ["Version"] = "2012-10-17",
            ["Statement"] = new[]
            {
                new Dictionary<string, object?>
                {
                    ["Action"] = "sts:AssumeRole",
                    ["Effect"] = "Allow",
                    ["Principal"] = new Dictionary<string, object?>
                    {
                        ["Service"] = $"imagebuilder.{currentGetPartition.Apply(getPartitionResult => getPartitionResult.DnsSuffix)}",
                    },
                },
            },
        }),
        Name = "example",
    });

    var exampleRolePolicyAttachment = new Aws.Iam.RolePolicyAttachment("example", new()
    {
        PolicyArn = $"arn:{currentGetPartition.Apply(getPartitionResult => getPartitionResult.Partition)}:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy",
        Role = example.Name,
    });

    var exampleLifecyclePolicy = new Aws.ImageBuilder.LifecyclePolicy("example", new()
    {
        ResourceSelection = new Aws.ImageBuilder.Inputs.LifecyclePolicyResourceSelectionArgs
        {
            TagMap =
            {
                { "key1", "value1" },
                { "key2", "value2" },
            },
        },
        PolicyDetails = new[]
        {
            new Aws.ImageBuilder.Inputs.LifecyclePolicyPolicyDetailArgs
            {
                Action = new Aws.ImageBuilder.Inputs.LifecyclePolicyPolicyDetailActionArgs
                {
                    Type = "DELETE",
                },
                Filter = new Aws.ImageBuilder.Inputs.LifecyclePolicyPolicyDetailFilterArgs
                {
                    Type = "AGE",
                    Value = 6,
                    RetainAtLeast = 10,
                    Unit = "YEARS",
                },
            },
        },
        Name = "name",
        Description = "Example description",
        ExecutionRole = example.Arn,
        ResourceType = "AMI_IMAGE",
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            exampleRolePolicyAttachment,
        },
    });

});
package main

import (
	"encoding/json"
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/imagebuilder"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := aws.GetRegion(ctx, &aws.GetRegionArgs{}, nil)
		if err != nil {
			return err
		}
		currentGetPartition, err := aws.GetPartition(ctx, &aws.GetPartitionArgs{}, nil)
		if err != nil {
			return err
		}
		tmpJSON0, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Action": "sts:AssumeRole",
					"Effect": "Allow",
					"Principal": map[string]string{
						"Service": fmt.Sprintf("imagebuilder.%v", currentGetPartition.DnsSuffix),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		example, err := iam.NewRole(ctx, "example", &iam.RoleArgs{
			AssumeRolePolicy: json0,
			Name:             pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		exampleRolePolicyAttachment, err := iam.NewRolePolicyAttachment(ctx, "example", &iam.RolePolicyAttachmentArgs{
			PolicyArn: pulumi.Sprintf("arn:%v:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy", currentGetPartition.Partition),
			Role:      example.Name,
		})
		if err != nil {
			return err
		}
		_, err = imagebuilder.NewLifecyclePolicy(ctx, "example", &imagebuilder.LifecyclePolicyArgs{
			ResourceSelection: &imagebuilder.LifecyclePolicyResourceSelectionArgs{
				TagMap: pulumi.StringMap{
					"key1": pulumi.String("value1"),
					"key2": pulumi.String("value2"),
				},
			},
			PolicyDetails: imagebuilder.LifecyclePolicyPolicyDetailArray{
				&imagebuilder.LifecyclePolicyPolicyDetailArgs{
					Action: &imagebuilder.LifecyclePolicyPolicyDetailActionArgs{
						Type: pulumi.String("DELETE"),
					},
					Filter: &imagebuilder.LifecyclePolicyPolicyDetailFilterArgs{
						Type:          pulumi.String("AGE"),
						Value:         pulumi.Int(6),
						RetainAtLeast: pulumi.Int(10),
						Unit:          pulumi.String("YEARS"),
					},
				},
			},
			Name:          pulumi.String("name"),
			Description:   pulumi.String("Example description"),
			ExecutionRole: example.Arn,
			ResourceType:  pulumi.String("AMI_IMAGE"),
		}, pulumi.DependsOn([]pulumi.Resource{
			exampleRolePolicyAttachment,
		}))
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_getregion" "current" {
}
data "aws_getpartition" "currentGetPartition" {
}

resource "aws_iam_role" "example" {
  assume_role_policy = jsonencode({
    "Version" = "2012-10-17"
    "Statement" = [{
      "Action" = "sts:AssumeRole"
      "Effect" = "Allow"
      "Principal" = {
        "Service" ="imagebuilder.${data.aws_getpartition.currentGetPartition.dns_suffix}"
      }
    }]
  })
  name = "example"
}
resource "aws_iam_rolepolicyattachment" "example" {
  policy_arn ="arn:${data.aws_getpartition.currentGetPartition.partition}:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy"
  role       = aws_iam_role.example.name
}
resource "aws_imagebuilder_lifecyclepolicy" "example" {
  depends_on = [aws_iam_rolepolicyattachment.example]
  resource_selection = {
    tag_map = {
      "key1" = "value1"
      "key2" = "value2"
    }
  }
  policy_details {
    action = {
      type = "DELETE"
    }
    filter = {
      type            = "AGE"
      value           = 6
      retain_at_least = 10
      unit            = "YEARS"
    }
  }
  name           = "name"
  description    = "Example description"
  execution_role = aws_iam_role.example.arn
  resource_type  = "AMI_IMAGE"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetRegionArgs;
import com.pulumi.aws.inputs.GetPartitionArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicyAttachment;
import com.pulumi.aws.iam.RolePolicyAttachmentArgs;
import com.pulumi.aws.imagebuilder.LifecyclePolicy;
import com.pulumi.aws.imagebuilder.LifecyclePolicyArgs;
import com.pulumi.aws.imagebuilder.inputs.LifecyclePolicyResourceSelectionArgs;
import com.pulumi.aws.imagebuilder.inputs.LifecyclePolicyPolicyDetailArgs;
import com.pulumi.aws.imagebuilder.inputs.LifecyclePolicyPolicyDetailActionArgs;
import com.pulumi.aws.imagebuilder.inputs.LifecyclePolicyPolicyDetailFilterArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
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 current = AwsFunctions.getRegion(GetRegionArgs.builder()
            .build());

        final var currentGetPartition = AwsFunctions.getPartition(GetPartitionArgs.builder()
            .build());

        var example = new Role("example", RoleArgs.builder()
            .assumeRolePolicy(serializeJson(
                jsonObject(
                    jsonProperty("Version", "2012-10-17"),
                    jsonProperty("Statement", jsonArray(jsonObject(
                        jsonProperty("Action", "sts:AssumeRole"),
                        jsonProperty("Effect", "Allow"),
                        jsonProperty("Principal", jsonObject(
                            jsonProperty("Service", String.format("imagebuilder.%s", currentGetPartition.dnsSuffix()))
                        ))
                    )))
                )))
            .name("example")
            .build());

        var exampleRolePolicyAttachment = new RolePolicyAttachment("exampleRolePolicyAttachment", RolePolicyAttachmentArgs.builder()
            .policyArn(String.format("arn:%s:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy", currentGetPartition.partition()))
            .role(example.name())
            .build());

        var exampleLifecyclePolicy = new LifecyclePolicy("exampleLifecyclePolicy", LifecyclePolicyArgs.builder()
            .resourceSelection(LifecyclePolicyResourceSelectionArgs.builder()
                .tagMap(Map.ofEntries(
                    Map.entry("key1", "value1"),
                    Map.entry("key2", "value2")
                ))
                .build())
            .policyDetails(LifecyclePolicyPolicyDetailArgs.builder()
                .action(LifecyclePolicyPolicyDetailActionArgs.builder()
                    .type("DELETE")
                    .build())
                .filter(LifecyclePolicyPolicyDetailFilterArgs.builder()
                    .type("AGE")
                    .value(6)
                    .retainAtLeast(10)
                    .unit("YEARS")
                    .build())
                .build())
            .name("name")
            .description("Example description")
            .executionRole(example.arn())
            .resourceType("AMI_IMAGE")
            .build(), CustomResourceOptions.builder()
                .dependsOn(exampleRolePolicyAttachment)
                .build());

    }
}
resources:
  example:
    type: aws:iam:Role
    properties:
      assumeRolePolicy:
        fn::toJSON:
          Version: 2012-10-17
          Statement:
            - Action: sts:AssumeRole
              Effect: Allow
              Principal:
                Service: imagebuilder.${currentGetPartition.dnsSuffix}
      name: example
  exampleRolePolicyAttachment:
    type: aws:iam:RolePolicyAttachment
    name: example
    properties:
      policyArn: arn:${currentGetPartition.partition}:iam::aws:policy/service-role/EC2ImageBuilderLifecycleExecutionPolicy
      role: ${example.name}
  exampleLifecyclePolicy:
    type: aws:imagebuilder:LifecyclePolicy
    name: example
    properties:
      resourceSelection:
        tagMap:
          key1: value1
          key2: value2
      policyDetails:
        - action:
            type: DELETE
          filter:
            type: AGE
            value: 6
            retainAtLeast: 10
            unit: YEARS
      name: name
      description: Example description
      executionRole: ${example.arn}
      resourceType: AMI_IMAGE
    options:
      dependsOn:
        - ${exampleRolePolicyAttachment}
variables:
  current:
    fn::invoke:
      function: aws:getRegion
      arguments: {}
  currentGetPartition:
    fn::invoke:
      function: aws:getPartition
      arguments: {}

Import

Identity Schema

Required

  • arn (String) ARN of the Image Builder lifecycle policy.

Using pulumi import, import aws.imagebuilder.LifecyclePolicy using the ARN. For example:

$ pulumi import aws:imagebuilder/lifecyclePolicy:LifecyclePolicy example arn:aws:imagebuilder:us-east-1:123456789012:lifecycle-policy/example

Constructors

LifecyclePolicy(String name, {LifecyclePolicyArgs? args, CustomResourceOptions? options})
Creates a new LifecyclePolicy. name The Pulumi resource name. args Arguments used to configure this LifecyclePolicy. The set of arguments for LifecyclePolicy. options Resource options controlling this resource's behavior.
LifecyclePolicy.reference(String urn)
Creates a typed reference to an existing LifecyclePolicy resource.

Properties

arn ↔ Output<String>
ARN of the lifecycle policy.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
description ↔ Output<String?>
description for the lifecycle policy.
latefinal
executionRole ↔ Output<String>
ARN for the IAM role you create that grants Image Builder access to run lifecycle actions. More information about this role can be found here.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
name ↔ Output<String>
The name of the lifecycle policy to create.
latefinal
policyDetails ↔ Output<List<LifecyclePolicyPolicyDetail>>
Configuration block with policy details. Detailed below.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceSelection ↔ Output<LifecyclePolicyResourceSelection>
Selection criteria for the resources that the lifecycle policy applies to. Detailed below.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
resourceType ↔ Output<String>
The type of Image Builder resource that the lifecycle policy applies to. Valid values: AMI_IMAGE or CONTAINER_IMAGE.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
status ↔ Output<String>
The status of the lifecycle policy.
latefinal
tags ↔ Output<Map<String, String>?>
Key-value map of resource tags for the Image Builder Lifecycle Policy. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {LifecyclePolicyState? state, CustomResourceOptions? options}) → LifecyclePolicy
Gets an existing LifecyclePolicy resource's state with the given name and id.