RegistryPolicy

Provides an Elastic Container Registry Policy.

Example Usage

using System.Collections.Generic;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var currentCallerIdentity = Output.Create(Aws.GetCallerIdentity.InvokeAsync());
        var currentRegion = Output.Create(Aws.GetRegion.InvokeAsync());
        var currentPartition = Output.Create(Aws.GetPartition.InvokeAsync());
        var example = new Aws.Ecr.RegistryPolicy("example", new Aws.Ecr.RegistryPolicyArgs
        {
            Policy = Output.Tuple(currentPartition, currentCallerIdentity, currentPartition, currentRegion, currentCallerIdentity).Apply(values =>
            {
                var currentPartition = values.Item1;
                var currentCallerIdentity = values.Item2;
                var currentPartition1 = values.Item3;
                var currentRegion = values.Item4;
                var currentCallerIdentity1 = values.Item5;
                return JsonSerializer.Serialize(new Dictionary<string, object?>
                {
                    { "Version", "2012-10-17" },
                    { "Statement", new[]
                        {
                            new Dictionary<string, object?>
                            {
                                { "Sid", "testpolicy" },
                                { "Effect", "Allow" },
                                { "Principal", new Dictionary<string, object?>
                                {
                                    { "AWS", $"arn:{currentPartition.Partition}:iam::{currentCallerIdentity.AccountId}:root" },
                                } },
                                { "Action", new[]
                                    {
                                        "ecr:ReplicateImage",
                                    }
                                 },
                                { "Resource", new[]
                                    {
                                        $"arn:{currentPartition1.Partition}:ecr:{currentRegion.Name}:{currentCallerIdentity1.AccountId}:repository/*",
                                    }
                                 },
                            },
                        }
                     },
                });
            }),
        });
    }

}
package main

import (
	"encoding/json"
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ecr"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		currentCallerIdentity, err := aws.GetCallerIdentity(ctx, nil, nil)
		if err != nil {
			return err
		}
		currentRegion, err := aws.GetRegion(ctx, nil, nil)
		if err != nil {
			return err
		}
		currentPartition, err := aws.GetPartition(ctx, nil, nil)
		if err != nil {
			return err
		}
		tmpJSON0, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Sid":    "testpolicy",
					"Effect": "Allow",
					"Principal": map[string]interface{}{
						"AWS": fmt.Sprintf("%v%v%v%v%v", "arn:", currentPartition.Partition, ":iam::", currentCallerIdentity.AccountId, ":root"),
					},
					"Action": []string{
						"ecr:ReplicateImage",
					},
					"Resource": []string{
						fmt.Sprintf("%v%v%v%v%v%v%v", "arn:", currentPartition.Partition, ":ecr:", currentRegion.Name, ":", currentCallerIdentity.AccountId, ":repository/*"),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		_, err = ecr.NewRegistryPolicy(ctx, "example", &ecr.RegistryPolicyArgs{
			Policy: pulumi.String(json0),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import json
import pulumi_aws as aws

current_caller_identity = aws.get_caller_identity()
current_region = aws.get_region()
current_partition = aws.get_partition()
example = aws.ecr.RegistryPolicy("example", policy=json.dumps({
    "Version": "2012-10-17",
    "Statement": [{
        "Sid": "testpolicy",
        "Effect": "Allow",
        "Principal": {
            "AWS": f"arn:{current_partition.partition}:iam::{current_caller_identity.account_id}:root",
        },
        "Action": ["ecr:ReplicateImage"],
        "Resource": [f"arn:{current_partition.partition}:ecr:{current_region.name}:{current_caller_identity.account_id}:repository/*"],
    }],
}))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const currentCallerIdentity = aws.getCallerIdentity({});
const currentRegion = aws.getRegion({});
const currentPartition = aws.getPartition({});
const example = new aws.ecr.RegistryPolicy("example", {policy: Promise.all([currentPartition, currentCallerIdentity, currentPartition, currentRegion, currentCallerIdentity]).then(([currentPartition, currentCallerIdentity, currentPartition1, currentRegion, currentCallerIdentity1]) => JSON.stringify({
    Version: "2012-10-17",
    Statement: [{
        Sid: "testpolicy",
        Effect: "Allow",
        Principal: {
            AWS: `arn:${currentPartition.partition}:iam::${currentCallerIdentity.accountId}:root`,
        },
        Action: ["ecr:ReplicateImage"],
        Resource: [`arn:${currentPartition1.partition}:ecr:${currentRegion.name}:${currentCallerIdentity1.accountId}:repository/*`],
    }],
}))});

Create a RegistryPolicy Resource

new RegistryPolicy(name: string, args: RegistryPolicyArgs, opts?: CustomResourceOptions);
@overload
def RegistryPolicy(resource_name: str,
                   opts: Optional[ResourceOptions] = None,
                   policy: Optional[str] = None)
@overload
def RegistryPolicy(resource_name: str,
                   args: RegistryPolicyArgs,
                   opts: Optional[ResourceOptions] = None)
func NewRegistryPolicy(ctx *Context, name string, args RegistryPolicyArgs, opts ...ResourceOption) (*RegistryPolicy, error)
public RegistryPolicy(string name, RegistryPolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RegistryPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args RegistryPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args RegistryPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RegistryPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RegistryPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The RegistryPolicy resource accepts the following input properties:

Policy string
Policy string
policy string
policy str

Outputs

All input properties are implicitly available as output properties. Additionally, the RegistryPolicy resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
RegistryId string
The registry ID where the registry was created.
Id string
The provider-assigned unique ID for this managed resource.
RegistryId string
The registry ID where the registry was created.
id string
The provider-assigned unique ID for this managed resource.
registryId string
The registry ID where the registry was created.
id str
The provider-assigned unique ID for this managed resource.
registry_id str
The registry ID where the registry was created.

Look up an Existing RegistryPolicy Resource

Get an existing RegistryPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: RegistryPolicyState, opts?: CustomResourceOptions): RegistryPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy: Optional[str] = None,
        registry_id: Optional[str] = None) -> RegistryPolicy
func GetRegistryPolicy(ctx *Context, name string, id IDInput, state *RegistryPolicyState, opts ...ResourceOption) (*RegistryPolicy, error)
public static RegistryPolicy Get(string name, Input<string> id, RegistryPolicyState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Policy string
RegistryId string
The registry ID where the registry was created.
Policy string
RegistryId string
The registry ID where the registry was created.
policy string
registryId string
The registry ID where the registry was created.
policy str
registry_id str
The registry ID where the registry was created.

Import

ECR Registry Policy can be imported using the registry id, e.g.

 $ pulumi import aws:ecr/registryPolicy:RegistryPolicy example 123456789012

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.