github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ecr/lifecyclePolicy.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 // Manages an ECR repository lifecycle policy. 16 // 17 // > **NOTE:** Only one `ecr.LifecyclePolicy` resource can be used with the same ECR repository. To apply multiple rules, they must be combined in the `policy` JSON. 18 // 19 // > **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. 20 // 21 // ## Example Usage 22 // 23 // ### Policy on untagged image 24 // 25 // <!--Start PulumiCodeChooser --> 26 // ```go 27 // package main 28 // 29 // import ( 30 // 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 // example, err := ecr.NewRepository(ctx, "example", &ecr.RepositoryArgs{ 39 // Name: pulumi.String("example-repo"), 40 // }) 41 // if err != nil { 42 // return err 43 // } 44 // _, err = ecr.NewLifecyclePolicy(ctx, "example", &ecr.LifecyclePolicyArgs{ 45 // Repository: example.Name, 46 // Policy: pulumi.Any(`{ 47 // "rules": [ 48 // { 49 // "rulePriority": 1, 50 // "description": "Expire images older than 14 days", 51 // "selection": { 52 // "tagStatus": "untagged", 53 // "countType": "sinceImagePushed", 54 // "countUnit": "days", 55 // "countNumber": 14 56 // }, 57 // "action": { 58 // "type": "expire" 59 // } 60 // } 61 // ] 62 // } 63 // 64 // `), 65 // 66 // }) 67 // if err != nil { 68 // return err 69 // } 70 // return nil 71 // }) 72 // } 73 // 74 // ``` 75 // <!--End PulumiCodeChooser --> 76 // 77 // ### Policy on tagged image 78 // 79 // <!--Start PulumiCodeChooser --> 80 // ```go 81 // package main 82 // 83 // import ( 84 // 85 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecr" 86 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 87 // 88 // ) 89 // 90 // func main() { 91 // pulumi.Run(func(ctx *pulumi.Context) error { 92 // example, err := ecr.NewRepository(ctx, "example", &ecr.RepositoryArgs{ 93 // Name: pulumi.String("example-repo"), 94 // }) 95 // if err != nil { 96 // return err 97 // } 98 // _, err = ecr.NewLifecyclePolicy(ctx, "example", &ecr.LifecyclePolicyArgs{ 99 // Repository: example.Name, 100 // Policy: pulumi.Any(`{ 101 // "rules": [ 102 // { 103 // "rulePriority": 1, 104 // "description": "Keep last 30 images", 105 // "selection": { 106 // "tagStatus": "tagged", 107 // "tagPrefixList": ["v"], 108 // "countType": "imageCountMoreThan", 109 // "countNumber": 30 110 // }, 111 // "action": { 112 // "type": "expire" 113 // } 114 // } 115 // ] 116 // } 117 // 118 // `), 119 // 120 // }) 121 // if err != nil { 122 // return err 123 // } 124 // return nil 125 // }) 126 // } 127 // 128 // ``` 129 // <!--End PulumiCodeChooser --> 130 // 131 // ## Import 132 // 133 // Using `pulumi import`, import ECR Lifecycle Policy using the name of the repository. For example: 134 // 135 // ```sh 136 // $ pulumi import aws:ecr/lifecyclePolicy:LifecyclePolicy example tf-example 137 // ``` 138 type LifecyclePolicy struct { 139 pulumi.CustomResourceState 140 141 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 142 Policy pulumi.StringOutput `pulumi:"policy"` 143 // The registry ID where the repository was created. 144 RegistryId pulumi.StringOutput `pulumi:"registryId"` 145 // Name of the repository to apply the policy. 146 Repository pulumi.StringOutput `pulumi:"repository"` 147 } 148 149 // NewLifecyclePolicy registers a new resource with the given unique name, arguments, and options. 150 func NewLifecyclePolicy(ctx *pulumi.Context, 151 name string, args *LifecyclePolicyArgs, opts ...pulumi.ResourceOption) (*LifecyclePolicy, error) { 152 if args == nil { 153 return nil, errors.New("missing one or more required arguments") 154 } 155 156 if args.Policy == nil { 157 return nil, errors.New("invalid value for required argument 'Policy'") 158 } 159 if args.Repository == nil { 160 return nil, errors.New("invalid value for required argument 'Repository'") 161 } 162 opts = internal.PkgResourceDefaultOpts(opts) 163 var resource LifecyclePolicy 164 err := ctx.RegisterResource("aws:ecr/lifecyclePolicy:LifecyclePolicy", name, args, &resource, opts...) 165 if err != nil { 166 return nil, err 167 } 168 return &resource, nil 169 } 170 171 // GetLifecyclePolicy gets an existing LifecyclePolicy resource's state with the given name, ID, and optional 172 // state properties that are used to uniquely qualify the lookup (nil if not required). 173 func GetLifecyclePolicy(ctx *pulumi.Context, 174 name string, id pulumi.IDInput, state *LifecyclePolicyState, opts ...pulumi.ResourceOption) (*LifecyclePolicy, error) { 175 var resource LifecyclePolicy 176 err := ctx.ReadResource("aws:ecr/lifecyclePolicy:LifecyclePolicy", name, id, state, &resource, opts...) 177 if err != nil { 178 return nil, err 179 } 180 return &resource, nil 181 } 182 183 // Input properties used for looking up and filtering LifecyclePolicy resources. 184 type lifecyclePolicyState struct { 185 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 186 Policy interface{} `pulumi:"policy"` 187 // The registry ID where the repository was created. 188 RegistryId *string `pulumi:"registryId"` 189 // Name of the repository to apply the policy. 190 Repository *string `pulumi:"repository"` 191 } 192 193 type LifecyclePolicyState struct { 194 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 195 Policy pulumi.Input 196 // The registry ID where the repository was created. 197 RegistryId pulumi.StringPtrInput 198 // Name of the repository to apply the policy. 199 Repository pulumi.StringPtrInput 200 } 201 202 func (LifecyclePolicyState) ElementType() reflect.Type { 203 return reflect.TypeOf((*lifecyclePolicyState)(nil)).Elem() 204 } 205 206 type lifecyclePolicyArgs struct { 207 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 208 Policy interface{} `pulumi:"policy"` 209 // Name of the repository to apply the policy. 210 Repository string `pulumi:"repository"` 211 } 212 213 // The set of arguments for constructing a LifecyclePolicy resource. 214 type LifecyclePolicyArgs struct { 215 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 216 Policy pulumi.Input 217 // Name of the repository to apply the policy. 218 Repository pulumi.StringInput 219 } 220 221 func (LifecyclePolicyArgs) ElementType() reflect.Type { 222 return reflect.TypeOf((*lifecyclePolicyArgs)(nil)).Elem() 223 } 224 225 type LifecyclePolicyInput interface { 226 pulumi.Input 227 228 ToLifecyclePolicyOutput() LifecyclePolicyOutput 229 ToLifecyclePolicyOutputWithContext(ctx context.Context) LifecyclePolicyOutput 230 } 231 232 func (*LifecyclePolicy) ElementType() reflect.Type { 233 return reflect.TypeOf((**LifecyclePolicy)(nil)).Elem() 234 } 235 236 func (i *LifecyclePolicy) ToLifecyclePolicyOutput() LifecyclePolicyOutput { 237 return i.ToLifecyclePolicyOutputWithContext(context.Background()) 238 } 239 240 func (i *LifecyclePolicy) ToLifecyclePolicyOutputWithContext(ctx context.Context) LifecyclePolicyOutput { 241 return pulumi.ToOutputWithContext(ctx, i).(LifecyclePolicyOutput) 242 } 243 244 // LifecyclePolicyArrayInput is an input type that accepts LifecyclePolicyArray and LifecyclePolicyArrayOutput values. 245 // You can construct a concrete instance of `LifecyclePolicyArrayInput` via: 246 // 247 // LifecyclePolicyArray{ LifecyclePolicyArgs{...} } 248 type LifecyclePolicyArrayInput interface { 249 pulumi.Input 250 251 ToLifecyclePolicyArrayOutput() LifecyclePolicyArrayOutput 252 ToLifecyclePolicyArrayOutputWithContext(context.Context) LifecyclePolicyArrayOutput 253 } 254 255 type LifecyclePolicyArray []LifecyclePolicyInput 256 257 func (LifecyclePolicyArray) ElementType() reflect.Type { 258 return reflect.TypeOf((*[]*LifecyclePolicy)(nil)).Elem() 259 } 260 261 func (i LifecyclePolicyArray) ToLifecyclePolicyArrayOutput() LifecyclePolicyArrayOutput { 262 return i.ToLifecyclePolicyArrayOutputWithContext(context.Background()) 263 } 264 265 func (i LifecyclePolicyArray) ToLifecyclePolicyArrayOutputWithContext(ctx context.Context) LifecyclePolicyArrayOutput { 266 return pulumi.ToOutputWithContext(ctx, i).(LifecyclePolicyArrayOutput) 267 } 268 269 // LifecyclePolicyMapInput is an input type that accepts LifecyclePolicyMap and LifecyclePolicyMapOutput values. 270 // You can construct a concrete instance of `LifecyclePolicyMapInput` via: 271 // 272 // LifecyclePolicyMap{ "key": LifecyclePolicyArgs{...} } 273 type LifecyclePolicyMapInput interface { 274 pulumi.Input 275 276 ToLifecyclePolicyMapOutput() LifecyclePolicyMapOutput 277 ToLifecyclePolicyMapOutputWithContext(context.Context) LifecyclePolicyMapOutput 278 } 279 280 type LifecyclePolicyMap map[string]LifecyclePolicyInput 281 282 func (LifecyclePolicyMap) ElementType() reflect.Type { 283 return reflect.TypeOf((*map[string]*LifecyclePolicy)(nil)).Elem() 284 } 285 286 func (i LifecyclePolicyMap) ToLifecyclePolicyMapOutput() LifecyclePolicyMapOutput { 287 return i.ToLifecyclePolicyMapOutputWithContext(context.Background()) 288 } 289 290 func (i LifecyclePolicyMap) ToLifecyclePolicyMapOutputWithContext(ctx context.Context) LifecyclePolicyMapOutput { 291 return pulumi.ToOutputWithContext(ctx, i).(LifecyclePolicyMapOutput) 292 } 293 294 type LifecyclePolicyOutput struct{ *pulumi.OutputState } 295 296 func (LifecyclePolicyOutput) ElementType() reflect.Type { 297 return reflect.TypeOf((**LifecyclePolicy)(nil)).Elem() 298 } 299 300 func (o LifecyclePolicyOutput) ToLifecyclePolicyOutput() LifecyclePolicyOutput { 301 return o 302 } 303 304 func (o LifecyclePolicyOutput) ToLifecyclePolicyOutputWithContext(ctx context.Context) LifecyclePolicyOutput { 305 return o 306 } 307 308 // The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs. Consider using the `ecr.getLifecyclePolicyDocument` dataSource to generate/manage the JSON document used for the `policy` argument. 309 func (o LifecyclePolicyOutput) Policy() pulumi.StringOutput { 310 return o.ApplyT(func(v *LifecyclePolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput) 311 } 312 313 // The registry ID where the repository was created. 314 func (o LifecyclePolicyOutput) RegistryId() pulumi.StringOutput { 315 return o.ApplyT(func(v *LifecyclePolicy) pulumi.StringOutput { return v.RegistryId }).(pulumi.StringOutput) 316 } 317 318 // Name of the repository to apply the policy. 319 func (o LifecyclePolicyOutput) Repository() pulumi.StringOutput { 320 return o.ApplyT(func(v *LifecyclePolicy) pulumi.StringOutput { return v.Repository }).(pulumi.StringOutput) 321 } 322 323 type LifecyclePolicyArrayOutput struct{ *pulumi.OutputState } 324 325 func (LifecyclePolicyArrayOutput) ElementType() reflect.Type { 326 return reflect.TypeOf((*[]*LifecyclePolicy)(nil)).Elem() 327 } 328 329 func (o LifecyclePolicyArrayOutput) ToLifecyclePolicyArrayOutput() LifecyclePolicyArrayOutput { 330 return o 331 } 332 333 func (o LifecyclePolicyArrayOutput) ToLifecyclePolicyArrayOutputWithContext(ctx context.Context) LifecyclePolicyArrayOutput { 334 return o 335 } 336 337 func (o LifecyclePolicyArrayOutput) Index(i pulumi.IntInput) LifecyclePolicyOutput { 338 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *LifecyclePolicy { 339 return vs[0].([]*LifecyclePolicy)[vs[1].(int)] 340 }).(LifecyclePolicyOutput) 341 } 342 343 type LifecyclePolicyMapOutput struct{ *pulumi.OutputState } 344 345 func (LifecyclePolicyMapOutput) ElementType() reflect.Type { 346 return reflect.TypeOf((*map[string]*LifecyclePolicy)(nil)).Elem() 347 } 348 349 func (o LifecyclePolicyMapOutput) ToLifecyclePolicyMapOutput() LifecyclePolicyMapOutput { 350 return o 351 } 352 353 func (o LifecyclePolicyMapOutput) ToLifecyclePolicyMapOutputWithContext(ctx context.Context) LifecyclePolicyMapOutput { 354 return o 355 } 356 357 func (o LifecyclePolicyMapOutput) MapIndex(k pulumi.StringInput) LifecyclePolicyOutput { 358 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *LifecyclePolicy { 359 return vs[0].(map[string]*LifecyclePolicy)[vs[1].(string)] 360 }).(LifecyclePolicyOutput) 361 } 362 363 func init() { 364 pulumi.RegisterInputType(reflect.TypeOf((*LifecyclePolicyInput)(nil)).Elem(), &LifecyclePolicy{}) 365 pulumi.RegisterInputType(reflect.TypeOf((*LifecyclePolicyArrayInput)(nil)).Elem(), LifecyclePolicyArray{}) 366 pulumi.RegisterInputType(reflect.TypeOf((*LifecyclePolicyMapInput)(nil)).Elem(), LifecyclePolicyMap{}) 367 pulumi.RegisterOutputType(LifecyclePolicyOutput{}) 368 pulumi.RegisterOutputType(LifecyclePolicyArrayOutput{}) 369 pulumi.RegisterOutputType(LifecyclePolicyMapOutput{}) 370 }