github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ecr/registryPolicy.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package ecr
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Provides an Elastic Container Registry Policy.
    16  //
    17  // > **NOTE on ECR Registry Policies:** While the AWS Management Console interface may suggest the ability to define multiple policies by creating multiple statements, ECR registry policies are effectively managed as singular entities at the regional level by the AWS APIs. Therefore, the `ecr.RegistryPolicy` resource should be configured only once per region with all necessary statements defined in the same policy. Attempting to define multiple `ecr.RegistryPolicy` resources may result in perpetual differences, with one policy overriding another.
    18  //
    19  // ## Example Usage
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"encoding/json"
    28  //	"fmt"
    29  //
    30  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
    31  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecr"
    32  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    33  //
    34  // )
    35  //
    36  //	func main() {
    37  //		pulumi.Run(func(ctx *pulumi.Context) error {
    38  //			current, err := aws.GetCallerIdentity(ctx, nil, nil)
    39  //			if err != nil {
    40  //				return err
    41  //			}
    42  //			currentGetRegion, err := aws.GetRegion(ctx, nil, nil)
    43  //			if err != nil {
    44  //				return err
    45  //			}
    46  //			currentGetPartition, err := aws.GetPartition(ctx, nil, nil)
    47  //			if err != nil {
    48  //				return err
    49  //			}
    50  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    51  //				"Version": "2012-10-17",
    52  //				"Statement": []map[string]interface{}{
    53  //					map[string]interface{}{
    54  //						"Sid":    "testpolicy",
    55  //						"Effect": "Allow",
    56  //						"Principal": map[string]interface{}{
    57  //							"AWS": fmt.Sprintf("arn:%v:iam::%v:root", currentGetPartition.Partition, current.AccountId),
    58  //						},
    59  //						"Action": []string{
    60  //							"ecr:ReplicateImage",
    61  //						},
    62  //						"Resource": []string{
    63  //							fmt.Sprintf("arn:%v:ecr:%v:%v:repository/*", currentGetPartition.Partition, currentGetRegion.Name, current.AccountId),
    64  //						},
    65  //					},
    66  //				},
    67  //			})
    68  //			if err != nil {
    69  //				return err
    70  //			}
    71  //			json0 := string(tmpJSON0)
    72  //			_, err = ecr.NewRegistryPolicy(ctx, "example", &ecr.RegistryPolicyArgs{
    73  //				Policy: pulumi.String(json0),
    74  //			})
    75  //			if err != nil {
    76  //				return err
    77  //			}
    78  //			return nil
    79  //		})
    80  //	}
    81  //
    82  // ```
    83  // <!--End PulumiCodeChooser -->
    84  //
    85  // ## Import
    86  //
    87  // Using `pulumi import`, import ECR Registry Policy using the registry id. For example:
    88  //
    89  // ```sh
    90  // $ pulumi import aws:ecr/registryPolicy:RegistryPolicy example 123456789012
    91  // ```
    92  type RegistryPolicy struct {
    93  	pulumi.CustomResourceState
    94  
    95  	// The policy document. This is a JSON formatted string.
    96  	Policy pulumi.StringOutput `pulumi:"policy"`
    97  	// The registry ID where the registry was created.
    98  	RegistryId pulumi.StringOutput `pulumi:"registryId"`
    99  }
   100  
   101  // NewRegistryPolicy registers a new resource with the given unique name, arguments, and options.
   102  func NewRegistryPolicy(ctx *pulumi.Context,
   103  	name string, args *RegistryPolicyArgs, opts ...pulumi.ResourceOption) (*RegistryPolicy, error) {
   104  	if args == nil {
   105  		return nil, errors.New("missing one or more required arguments")
   106  	}
   107  
   108  	if args.Policy == nil {
   109  		return nil, errors.New("invalid value for required argument 'Policy'")
   110  	}
   111  	opts = internal.PkgResourceDefaultOpts(opts)
   112  	var resource RegistryPolicy
   113  	err := ctx.RegisterResource("aws:ecr/registryPolicy:RegistryPolicy", name, args, &resource, opts...)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  	return &resource, nil
   118  }
   119  
   120  // GetRegistryPolicy gets an existing RegistryPolicy resource's state with the given name, ID, and optional
   121  // state properties that are used to uniquely qualify the lookup (nil if not required).
   122  func GetRegistryPolicy(ctx *pulumi.Context,
   123  	name string, id pulumi.IDInput, state *RegistryPolicyState, opts ...pulumi.ResourceOption) (*RegistryPolicy, error) {
   124  	var resource RegistryPolicy
   125  	err := ctx.ReadResource("aws:ecr/registryPolicy:RegistryPolicy", name, id, state, &resource, opts...)
   126  	if err != nil {
   127  		return nil, err
   128  	}
   129  	return &resource, nil
   130  }
   131  
   132  // Input properties used for looking up and filtering RegistryPolicy resources.
   133  type registryPolicyState struct {
   134  	// The policy document. This is a JSON formatted string.
   135  	Policy interface{} `pulumi:"policy"`
   136  	// The registry ID where the registry was created.
   137  	RegistryId *string `pulumi:"registryId"`
   138  }
   139  
   140  type RegistryPolicyState struct {
   141  	// The policy document. This is a JSON formatted string.
   142  	Policy pulumi.Input
   143  	// The registry ID where the registry was created.
   144  	RegistryId pulumi.StringPtrInput
   145  }
   146  
   147  func (RegistryPolicyState) ElementType() reflect.Type {
   148  	return reflect.TypeOf((*registryPolicyState)(nil)).Elem()
   149  }
   150  
   151  type registryPolicyArgs struct {
   152  	// The policy document. This is a JSON formatted string.
   153  	Policy interface{} `pulumi:"policy"`
   154  }
   155  
   156  // The set of arguments for constructing a RegistryPolicy resource.
   157  type RegistryPolicyArgs struct {
   158  	// The policy document. This is a JSON formatted string.
   159  	Policy pulumi.Input
   160  }
   161  
   162  func (RegistryPolicyArgs) ElementType() reflect.Type {
   163  	return reflect.TypeOf((*registryPolicyArgs)(nil)).Elem()
   164  }
   165  
   166  type RegistryPolicyInput interface {
   167  	pulumi.Input
   168  
   169  	ToRegistryPolicyOutput() RegistryPolicyOutput
   170  	ToRegistryPolicyOutputWithContext(ctx context.Context) RegistryPolicyOutput
   171  }
   172  
   173  func (*RegistryPolicy) ElementType() reflect.Type {
   174  	return reflect.TypeOf((**RegistryPolicy)(nil)).Elem()
   175  }
   176  
   177  func (i *RegistryPolicy) ToRegistryPolicyOutput() RegistryPolicyOutput {
   178  	return i.ToRegistryPolicyOutputWithContext(context.Background())
   179  }
   180  
   181  func (i *RegistryPolicy) ToRegistryPolicyOutputWithContext(ctx context.Context) RegistryPolicyOutput {
   182  	return pulumi.ToOutputWithContext(ctx, i).(RegistryPolicyOutput)
   183  }
   184  
   185  // RegistryPolicyArrayInput is an input type that accepts RegistryPolicyArray and RegistryPolicyArrayOutput values.
   186  // You can construct a concrete instance of `RegistryPolicyArrayInput` via:
   187  //
   188  //	RegistryPolicyArray{ RegistryPolicyArgs{...} }
   189  type RegistryPolicyArrayInput interface {
   190  	pulumi.Input
   191  
   192  	ToRegistryPolicyArrayOutput() RegistryPolicyArrayOutput
   193  	ToRegistryPolicyArrayOutputWithContext(context.Context) RegistryPolicyArrayOutput
   194  }
   195  
   196  type RegistryPolicyArray []RegistryPolicyInput
   197  
   198  func (RegistryPolicyArray) ElementType() reflect.Type {
   199  	return reflect.TypeOf((*[]*RegistryPolicy)(nil)).Elem()
   200  }
   201  
   202  func (i RegistryPolicyArray) ToRegistryPolicyArrayOutput() RegistryPolicyArrayOutput {
   203  	return i.ToRegistryPolicyArrayOutputWithContext(context.Background())
   204  }
   205  
   206  func (i RegistryPolicyArray) ToRegistryPolicyArrayOutputWithContext(ctx context.Context) RegistryPolicyArrayOutput {
   207  	return pulumi.ToOutputWithContext(ctx, i).(RegistryPolicyArrayOutput)
   208  }
   209  
   210  // RegistryPolicyMapInput is an input type that accepts RegistryPolicyMap and RegistryPolicyMapOutput values.
   211  // You can construct a concrete instance of `RegistryPolicyMapInput` via:
   212  //
   213  //	RegistryPolicyMap{ "key": RegistryPolicyArgs{...} }
   214  type RegistryPolicyMapInput interface {
   215  	pulumi.Input
   216  
   217  	ToRegistryPolicyMapOutput() RegistryPolicyMapOutput
   218  	ToRegistryPolicyMapOutputWithContext(context.Context) RegistryPolicyMapOutput
   219  }
   220  
   221  type RegistryPolicyMap map[string]RegistryPolicyInput
   222  
   223  func (RegistryPolicyMap) ElementType() reflect.Type {
   224  	return reflect.TypeOf((*map[string]*RegistryPolicy)(nil)).Elem()
   225  }
   226  
   227  func (i RegistryPolicyMap) ToRegistryPolicyMapOutput() RegistryPolicyMapOutput {
   228  	return i.ToRegistryPolicyMapOutputWithContext(context.Background())
   229  }
   230  
   231  func (i RegistryPolicyMap) ToRegistryPolicyMapOutputWithContext(ctx context.Context) RegistryPolicyMapOutput {
   232  	return pulumi.ToOutputWithContext(ctx, i).(RegistryPolicyMapOutput)
   233  }
   234  
   235  type RegistryPolicyOutput struct{ *pulumi.OutputState }
   236  
   237  func (RegistryPolicyOutput) ElementType() reflect.Type {
   238  	return reflect.TypeOf((**RegistryPolicy)(nil)).Elem()
   239  }
   240  
   241  func (o RegistryPolicyOutput) ToRegistryPolicyOutput() RegistryPolicyOutput {
   242  	return o
   243  }
   244  
   245  func (o RegistryPolicyOutput) ToRegistryPolicyOutputWithContext(ctx context.Context) RegistryPolicyOutput {
   246  	return o
   247  }
   248  
   249  // The policy document. This is a JSON formatted string.
   250  func (o RegistryPolicyOutput) Policy() pulumi.StringOutput {
   251  	return o.ApplyT(func(v *RegistryPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   252  }
   253  
   254  // The registry ID where the registry was created.
   255  func (o RegistryPolicyOutput) RegistryId() pulumi.StringOutput {
   256  	return o.ApplyT(func(v *RegistryPolicy) pulumi.StringOutput { return v.RegistryId }).(pulumi.StringOutput)
   257  }
   258  
   259  type RegistryPolicyArrayOutput struct{ *pulumi.OutputState }
   260  
   261  func (RegistryPolicyArrayOutput) ElementType() reflect.Type {
   262  	return reflect.TypeOf((*[]*RegistryPolicy)(nil)).Elem()
   263  }
   264  
   265  func (o RegistryPolicyArrayOutput) ToRegistryPolicyArrayOutput() RegistryPolicyArrayOutput {
   266  	return o
   267  }
   268  
   269  func (o RegistryPolicyArrayOutput) ToRegistryPolicyArrayOutputWithContext(ctx context.Context) RegistryPolicyArrayOutput {
   270  	return o
   271  }
   272  
   273  func (o RegistryPolicyArrayOutput) Index(i pulumi.IntInput) RegistryPolicyOutput {
   274  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *RegistryPolicy {
   275  		return vs[0].([]*RegistryPolicy)[vs[1].(int)]
   276  	}).(RegistryPolicyOutput)
   277  }
   278  
   279  type RegistryPolicyMapOutput struct{ *pulumi.OutputState }
   280  
   281  func (RegistryPolicyMapOutput) ElementType() reflect.Type {
   282  	return reflect.TypeOf((*map[string]*RegistryPolicy)(nil)).Elem()
   283  }
   284  
   285  func (o RegistryPolicyMapOutput) ToRegistryPolicyMapOutput() RegistryPolicyMapOutput {
   286  	return o
   287  }
   288  
   289  func (o RegistryPolicyMapOutput) ToRegistryPolicyMapOutputWithContext(ctx context.Context) RegistryPolicyMapOutput {
   290  	return o
   291  }
   292  
   293  func (o RegistryPolicyMapOutput) MapIndex(k pulumi.StringInput) RegistryPolicyOutput {
   294  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *RegistryPolicy {
   295  		return vs[0].(map[string]*RegistryPolicy)[vs[1].(string)]
   296  	}).(RegistryPolicyOutput)
   297  }
   298  
   299  func init() {
   300  	pulumi.RegisterInputType(reflect.TypeOf((*RegistryPolicyInput)(nil)).Elem(), &RegistryPolicy{})
   301  	pulumi.RegisterInputType(reflect.TypeOf((*RegistryPolicyArrayInput)(nil)).Elem(), RegistryPolicyArray{})
   302  	pulumi.RegisterInputType(reflect.TypeOf((*RegistryPolicyMapInput)(nil)).Elem(), RegistryPolicyMap{})
   303  	pulumi.RegisterOutputType(RegistryPolicyOutput{})
   304  	pulumi.RegisterOutputType(RegistryPolicyArrayOutput{})
   305  	pulumi.RegisterOutputType(RegistryPolicyMapOutput{})
   306  }