Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource: ECR Lifecycle Policy #1869

Closed
wants to merge 196 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
231b0f8
Add AWS SES DKIM resource
arr-dev Oct 1, 2017
52ad2b6
If default cloudfront certificate is used, ignore minimum_protocol_ve…
Oct 1, 2017
5a038e4
Wrap DkimTokens in aws.StringValueSlice to make sure it's saved
arr-dev Oct 3, 2017
2a22dd1
Support SMS in SNS Topic Subscription protocols
icy Oct 5, 2017
7e2a397
resource/aws_alb_target_group: Add support for `target_type`
stack72 Sep 5, 2017
10ed381
Using `self false` icw `cidr_blocks` should be valid
Oct 9, 2017
9a7e7e1
Adding vpc_id to aws_security_group resource md (fixes #1670)
Oct 9, 2017
f81c3dc
resource/aws_spot_fleet_request: Add support for instance_interruptio…
mikekap Oct 10, 2017
12d480e
r/vpn_connection_route: Wait until route is available/deleted
radeksimko Oct 10, 2017
e331386
Changes the default minimum_protocol_version to TLSv1 and updates the…
JamesBelchamber Oct 11, 2017
d736b3c
Update ELB create to align with 4000s idle timeout
jbruett Oct 11, 2017
da762b1
Make file
atsushi-ishibashi Oct 12, 2017
25a2820
Add link to AWS documentation
iiska Oct 12, 2017
823468f
Merge pull request #1861 from jbruett/patch-1
Ninir Oct 12, 2017
536f593
Update CHANGELOG.md
Ninir Oct 12, 2017
cece5ff
Merge pull request #1871 from iiska/doc/solution-stacks-link
Ninir Oct 12, 2017
dbd3504
Fixed SpotRequest terminate behavior test & updated documentation
Ninir Oct 12, 2017
22426e0
Merge pull request #1847 from mikekap/iib-for-fleets
Ninir Oct 12, 2017
be4f724
Update CHANGELOG.md
Ninir Oct 12, 2017
e8f1e38
Added missing attribute
martinssipenko Oct 12, 2017
de474a8
Specify kinesis stream as the source of a aws_kinesis_firehose_delive…
pleschev Oct 12, 2017
cce6922
Update CHANGELOG.md
Ninir Oct 12, 2017
32d32f8
Merge pull request #1875 from martinssipenko/patch-1
Ninir Oct 12, 2017
efcd9a9
Add doc note about import and domain verification requirement
arr-dev Oct 12, 2017
450e421
Indicate that ipv6 addresses are exported
meangrape Oct 12, 2017
d3d22d0
Add dkim tokens state store test
arr-dev Oct 13, 2017
aa3fc3a
Log complete error while creating Kinesis Firehose Delivery Stream
ApsOps Oct 13, 2017
3da6863
Check VPC array size
andreaTP Oct 13, 2017
d40e668
Merge pull request #1849 from terraform-providers/b-vpn-conn-route-wa…
radeksimko Oct 14, 2017
8e7ff53
Update CHANGELOG.md
radeksimko Oct 14, 2017
45b5774
Add aws_ecr_lifecycle_policy
atsushi-ishibashi Oct 14, 2017
28c9fc8
r/batch_job_queue: Wait for update completion when disabling
radeksimko Oct 14, 2017
6a94aee
Update CHANGELOG.md
radeksimko Oct 14, 2017
445f5bf
r/elasticache_parameter_group: Add missing return to retry logic
radeksimko Oct 14, 2017
e833133
Validate json for policy
atsushi-ishibashi Oct 14, 2017
a45d3a5
Merge pull request #1785 from ekini/default_certificate
radeksimko Oct 14, 2017
9d416b5
Update CHANGELOG.md
radeksimko Oct 14, 2017
9f3f1f4
r/snapshot_create_volume_permission: Raise timeout
radeksimko Oct 14, 2017
68f9358
r/kms_key: Retry reading tags on NotFoundException
radeksimko Oct 14, 2017
ab72b39
Merge pull request #1878 from jayed/aws_instance_doc_ipv6
radeksimko Oct 14, 2017
4db5c35
Merge pull request #1881 from ApsOps/clarify-kinesis-delivery-stream-…
radeksimko Oct 14, 2017
1995248
Update CHANGELOG.md
radeksimko Oct 14, 2017
c43dfcd
r/kms_alias: Retry creation on NotFoundException
radeksimko Oct 14, 2017
4fc6d6b
Update CHANGELOG.md
radeksimko Oct 15, 2017
f8bedbd
r/db_snapshot: Raise creation timeout to 20mins
radeksimko Oct 15, 2017
fd5f541
Spot Instance Request: handle "closed" requests
darkowlzz Oct 15, 2017
00fd7e9
Clarify Documentation on Application AutoScaling Policy Resource
brandonstevens Oct 15, 2017
3089ed0
Merge pull request #1903 from darkowlzz/1327-handle-closed-spot-request
radeksimko Oct 15, 2017
f16302c
Update CHANGELOG.md
radeksimko Oct 15, 2017
0e82c15
Merge pull request #1904 from brandonstevens/appautoscaling-docs
radeksimko Oct 15, 2017
ca67ee9
add vendoring for aws service budget (#1898)
xchapter7x Oct 15, 2017
247737a
Add default value
koooge Oct 16, 2017
eaf717c
Add aws-sdk-go/service/shield package (#1901)
atsushi-ishibashi Oct 16, 2017
004c845
Merge pull request #1906 from koooge/master
radeksimko Oct 16, 2017
c206aec
Merge pull request #1843 from ryno75/master
radeksimko Oct 16, 2017
1492516
Merge pull request #1839 from svanharmelen/f-security-group-rule
radeksimko Oct 16, 2017
5cd548b
Update CHANGELOG.md
radeksimko Oct 16, 2017
ea5fb39
Add comment explaining purpose of check
radeksimko Oct 16, 2017
aa626d6
Merge pull request #1882 from andreaTP/checkVPCSPresence
radeksimko Oct 16, 2017
12d5b1a
Update CHANGELOG.md
radeksimko Oct 16, 2017
0baded9
v1.1.0
Oct 16, 2017
0fe93ab
Cleanup after v1.1.0 release
Oct 16, 2017
3ff38ca
docs: Fix broken link to LBs
radeksimko Oct 16, 2017
9c86d16
docs: Add missing link to d/s3_bucket
radeksimko Oct 16, 2017
a2a895d
Merge pull request #1908 from terraform-providers/docs-add-missing-link
radeksimko Oct 16, 2017
be2418b
Merge pull request #1891 from terraform-providers/b-elasticache-prm-g…
radeksimko Oct 16, 2017
029107d
Update CHANGELOG.md
radeksimko Oct 16, 2017
fb52fc7
Merge pull request #1892 from terraform-providers/b-batch-deletion-state
radeksimko Oct 16, 2017
a953b20
Update CHANGELOG.md
radeksimko Oct 16, 2017
736e244
Update CHANGELOG.md
radeksimko Oct 16, 2017
c365570
Merge pull request #1894 from terraform-providers/b-snapshot-vol-perm…
radeksimko Oct 16, 2017
8a3c35a
Merge pull request #1896 from terraform-providers/b-kms-alias-retry-c…
radeksimko Oct 16, 2017
285aa91
Update CHANGELOG.md
radeksimko Oct 16, 2017
cc5cc25
Merge pull request #1900 from terraform-providers/b-kms-key-retry-tags
radeksimko Oct 16, 2017
20eb39b
Update CHANGELOG.md
radeksimko Oct 16, 2017
595e265
Merge pull request #1905 from terraform-providers/b-db-snapshot-retry…
radeksimko Oct 16, 2017
572d93c
Update CHANGELOG.md
radeksimko Oct 16, 2017
64f5506
Update CHANGELOG.md
radeksimko Oct 16, 2017
f18bb98
vendor: github.com/aws/aws-sdk-go/service/directconnect
radeksimko Oct 16, 2017
befa952
Merge pull request #1915 from terraform-providers/vendor-aws-direct-c…
radeksimko Oct 16, 2017
14a240c
Add aws-sdk-go/service/workspaces@v1.12.8
atsushi-ishibashi Oct 16, 2017
5eb6320
Merge pull request #1916 from atsushi-ishibashi/vendor-workspaces
radeksimko Oct 16, 2017
43605cb
Update README.md
ApsOps Oct 17, 2017
5f2d99d
Merge pull request #1926 from ApsOps/patch-1
radeksimko Oct 18, 2017
5c65f31
Add aws-sdk-go/service/...@v1.12.12
handlerbot Oct 18, 2017
e82313f
data_source_aws_security_group: add description
darkowlzz Oct 17, 2017
d6b12ce
Merge pull request #1950 from handlerbot/vendor-elasticsearch
radeksimko Oct 18, 2017
4e0b0e0
r/aws_lb: Allow assigning EIP to network LB
radeksimko Oct 18, 2017
c33cd2f
Merge pull request #1943 from darkowlzz/sg-description
Ninir Oct 18, 2017
a2f482a
Update CHANGELOG.md
Ninir Oct 18, 2017
1b6527c
Merge pull request #1856 from JamesBelchamber/cloudfront-new-minimum-…
Ninir Oct 18, 2017
8d21069
Update CHANGELOG.md
Ninir Oct 18, 2017
79826aa
Adding servicecatalog_portfolio resource (#1694)
bw-intuit Oct 18, 2017
6618107
Update CHANGELOG.md
Ninir Oct 18, 2017
7bbe54f
Merge pull request #1813 from icyfork/enable_sms_topic_subscription
Ninir Oct 18, 2017
b17bb9f
Update CHANGELOG.md
Ninir Oct 18, 2017
f9fbfa2
r/aws_lb: Wait until NLB ENIs are gone
radeksimko Oct 18, 2017
2aac7e0
Bump AWS SDK to v1.12.14.
ewbankkit Oct 20, 2017
a61d2ed
Merge pull request #1984 from ewbankkit/bump-aws-sdk-1.12.14
radeksimko Oct 20, 2017
ecee8f9
Add support for SQS queue tags.
ewbankkit Oct 20, 2017
3056b04
Merge pull request #1956 from terraform-providers/b-nlb-eip
radeksimko Oct 20, 2017
f956e2f
Update CHANGELOG.md
radeksimko Oct 20, 2017
0c0da38
Fix typo in d/route53_zone.html
abinashmeher999 Oct 21, 2017
5f36ce7
Merge pull request #1997 from abinashmeher999/route53-docs
radeksimko Oct 21, 2017
424a5a4
rm vendor update
atsushi-ishibashi Oct 21, 2017
f738c02
Modify aws_kms_key.key_usage default value in doc
dtan4 Oct 22, 2017
db0414b
Merge pull request #2006 from dtan4/kms-key-usage-doc
radeksimko Oct 23, 2017
e7ed12f
Cognito: Added Identity Pool Roles Attachment
Ninir Jun 14, 2017
20bdb38
Merge pull request #1786 from arr-dev/b-ses-dkim
radeksimko Oct 23, 2017
d36dbee
Update CHANGELOG.md
radeksimko Oct 23, 2017
95359b4
r/s3_bucket: Retry tagging on OperationAborted
radeksimko Oct 23, 2017
50ad29a
resource/aws_cognito_identity_pool: Fixed refresh of providers
Ninir Oct 23, 2017
230b696
Cognito Roles Attachment: Fixed cast issue, updated test logic
Ninir Oct 23, 2017
99c4355
Merge pull request #2008 from terraform-providers/b-s3-bucket-retry-o…
radeksimko Oct 23, 2017
6717b27
Update CHANGELOG.md
radeksimko Oct 23, 2017
88876bd
Merge pull request #863 from Ninir/f-cognito-ip-roles-attachment
Ninir Oct 23, 2017
fa7f424
Update CHANGELOG.md
Ninir Oct 23, 2017
f1a572e
Documentation fix in api_gateway_integration example - fixes #1934
alex1x Oct 24, 2017
0da2f01
Those id needs to be arn
ROunofF Oct 24, 2017
4427885
Merge pull request #2022 from alex1x/master
Ninir Oct 24, 2017
c6e3d86
Merge pull request #2015 from Ninir/b-cognito-refresh
Ninir Oct 24, 2017
ef7086e
Update CHANGELOG.md
Ninir Oct 24, 2017
b5bb97c
Merge pull request #2025 from ROunofF/patch-1
Ninir Oct 24, 2017
f081c8e
Minor inconsistent indentation correction
abinashmeher999 Oct 21, 2017
27fe2af
Fix typo in changelog
abinashmeher999 Oct 25, 2017
6c1bd5d
add encrypted can't be used with snapshot_id in r/ami
abinashmeher999 Oct 25, 2017
0476f80
r/spot_fleet_request: Raise bid price in acceptance test
radeksimko Oct 25, 2017
03c0ae7
Merge pull request #2045 from abinashmeher999/doc_changes
radeksimko Oct 25, 2017
baa5d8b
r/elasticache_replication_group: Raise creation timeout to 50mins
radeksimko Oct 25, 2017
96093dd
r/snapshot_create_volume_permission: Raise creation timeout to 20mins
radeksimko Oct 25, 2017
6514cc5
Add 'tags' support to aws_spot_fleet_request (#2042)
jekh Oct 25, 2017
960b309
Update CHANGELOG.md
radeksimko Oct 25, 2017
a538b06
Fix #2031 - DHCP Options Set docs should explain how to maintain defa…
alex1x Oct 24, 2017
1f6df30
Merge pull request #2047 from terraform-providers/b-spot-fleet-bid-price
radeksimko Oct 25, 2017
ccb49f6
Merge pull request #2048 from terraform-providers/b-elasticache-rg-ra…
radeksimko Oct 25, 2017
6c5775c
Update CHANGELOG.md
radeksimko Oct 25, 2017
a1c3c62
Merge pull request #2049 from terraform-providers/b-snapshot-vol-perm…
radeksimko Oct 25, 2017
4e6b0a9
Update CHANGELOG.md
radeksimko Oct 25, 2017
d90eaac
Add instructions on using the plugin
Oct 25, 2017
4bebf54
Merge pull request #2052 from jwinter/README-using-the-provider
radeksimko Oct 25, 2017
1be222f
Merge pull request #2033 from alex1x/master
Ninir Oct 25, 2017
80a2af5
r/spot_instances_request: Fix failing acceptance test (SubnetId)
radeksimko Oct 25, 2017
44edced
Add s3_backup_mode option in Firehose Redshift destination (#1830)
ApsOps Oct 25, 2017
79e0138
Update CHANGELOG.md
radeksimko Oct 25, 2017
ab0d139
r/kinesis_firehose_delivery_stream: Use data source instead of static…
radeksimko Oct 25, 2017
328c3b3
New Data Source: aws_dynamodb_table
bflad Oct 26, 2017
8ef6def
Update subnet_ids.html.markdown (#2058)
icebourg Oct 26, 2017
5659df1
Support VPC configuration of aws_elasticsearch_domain resources. (#1958)
handlerbot Oct 26, 2017
968a752
Update CHANGELOG.md
radeksimko Oct 26, 2017
d0af71f
Update aws_appautoscaling_target and aws_appautoscaling_policy resour…
bflad Oct 26, 2017
aa72c27
remove "id" fields from schema definitions (#1626)
jbardin Oct 26, 2017
f41ccb0
Update CHANGELOG.md
radeksimko Oct 26, 2017
cfcdb83
Remove id field from aws_servicecatalog_portfolio
radeksimko Oct 26, 2017
bee254a
travis: Bump go to 1.9.1
radeksimko Oct 26, 2017
925af31
Merge pull request #2067 from terraform-providers/dep-travis-go-1.9.1
radeksimko Oct 26, 2017
6b2f18b
Merge pull request #2065 from terraform-providers/b-servicecatalog-id…
radeksimko Oct 26, 2017
191b3ef
Fixed wrong method name usage
Ninir Oct 26, 2017
8d66014
Merge pull request #1589 from stack72/f-aws-alb-target-group-type
Ninir Oct 26, 2017
2b4343e
Update CHANGELOG.md
Ninir Oct 26, 2017
ab9e3e6
Add NatGateway data source (#1294)
shadycuz Oct 26, 2017
0bfaf6c
Update CHANGELOG.md
Ninir Oct 26, 2017
63a3f68
#2062 PR review updates for copypasta and formatting
bflad Oct 26, 2017
10866b4
vendor: github.com/hashicorp/terraform/...@ddff8bb
radeksimko Oct 26, 2017
8e159e3
vendor: github.com/hashicorp/go-getter@a686900
radeksimko Oct 26, 2017
107fab8
vendor: github.com/hashicorp/go-plugin/...@a5174f8
radeksimko Oct 26, 2017
95ef257
Merge pull request #2055 from terraform-providers/t-kinesis-tests-ref…
radeksimko Oct 26, 2017
dca0899
resource/aws_api_gateway_usag_plan: Fixed setting of rate_limit
Ninir Oct 26, 2017
918be14
Fixed a bug where the account id was the random string generated
Ninir Oct 27, 2017
b3c6f76
Merge pull request #2079 from Ninir/b-firehosestreamsource-accountid
Ninir Oct 27, 2017
35fe15d
Update CHANGELOG.md
Ninir Oct 27, 2017
b66f6b6
Merge pull request #2076 from Ninir/b-usageplan-ratelimit
Ninir Oct 27, 2017
c95887e
Update CHANGELOG.md
Ninir Oct 27, 2017
0e1dc39
Merge pull request #2062 from bflad/dynamodb_table_data_source
Ninir Oct 27, 2017
c162ebb
Update CHANGELOG.md
Ninir Oct 27, 2017
3177675
Add 'aws_cloudtrail_service_account' data source.
Sep 28, 2017
6371b04
Merge pull request #1774 from ewbankkit/add-data_source_cloudtrail_se…
radeksimko Oct 27, 2017
59afb0a
Update CHANGELOG.md
radeksimko Oct 27, 2017
39611c5
Merge pull request #1987 from ewbankkit/issue-1983
radeksimko Oct 27, 2017
a710eab
Update CHANGELOG.md
radeksimko Oct 27, 2017
1bf1537
Merge pull request #2054 from terraform-providers/b-spot-instance-sub…
radeksimko Oct 27, 2017
1258982
Merge pull request #2066 from terraform-providers/vendor-tf-latest
radeksimko Oct 27, 2017
8026b18
Fix TestAccAWSEMRCluster_terminationProtected (#2091)
catsby Oct 27, 2017
aa1ec0d
Make file
atsushi-ishibashi Oct 12, 2017
f06f861
Add aws_ecr_lifecycle_policy
atsushi-ishibashi Oct 14, 2017
9d6fc1f
Validate json for policy
atsushi-ishibashi Oct 14, 2017
d1b30b6
reflect reviews
atsushi-ishibashi Oct 28, 2017
177a198
r/aws_{ami,ami_copy,ami_from_instance}: Configurable timeouts. (#1811)
jmehnle Oct 28, 2017
2355a5c
Update CHANGELOG.md
radeksimko Oct 28, 2017
a3ada8a
Bump AWS SDK to v1.12.19. (#2088)
ewbankkit Oct 28, 2017
6ef0e9d
Update lb_target_group.html.markdown
jkodroff Oct 28, 2017
0a57a38
Update lb.html.markdown
jkodroff Oct 28, 2017
b042fdb
Fixes typo in aws_lb_listener_rule resource docs.
jkodroff Oct 28, 2017
0b74ea6
Make file
atsushi-ishibashi Oct 12, 2017
d62e784
Add aws_ecr_lifecycle_policy
atsushi-ishibashi Oct 14, 2017
24b30e8
Validate json for policy
atsushi-ishibashi Oct 14, 2017
c5e865c
Merge branch 'issue1868' of github.com:atsushi-ishibashi/terraform-pr…
atsushi-ishibashi Oct 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func Provider() terraform.ResourceProvider {
"aws_dynamodb_table": resourceAwsDynamoDbTable(),
"aws_ebs_snapshot": resourceAwsEbsSnapshot(),
"aws_ebs_volume": resourceAwsEbsVolume(),
"aws_ecr_lifecycle_policy": resourceAwsEcrLifecyclePolicy(),
"aws_ecr_repository": resourceAwsEcrRepository(),
"aws_ecr_repository_policy": resourceAwsEcrRepositoryPolicy(),
"aws_ecs_cluster": resourceAwsEcsCluster(),
Expand Down
101 changes: 101 additions & 0 deletions aws/resource_aws_ecr_lifecycle_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package aws

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsEcrLifecyclePolicy() *schema.Resource {
return &schema.Resource{
Create: resourceAwsEcrLifecyclePolicyCreate,
Read: resourceAwsEcrLifecyclePolicyRead,
Delete: resourceAwsEcrLifecyclePolicyDelete,

Schema: map[string]*schema.Schema{
"repository": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"policy": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateJsonString,
},
"registry_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceAwsEcrLifecyclePolicyCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecrconn

input := &ecr.PutLifecyclePolicyInput{
RepositoryName: aws.String(d.Get("repository").(string)),
LifecyclePolicyText: aws.String(d.Get("policy").(string)),
}

resp, err := conn.PutLifecyclePolicy(input)
if err != nil {
return err
}
d.SetId(*resp.RepositoryName)
d.Set("registry_id", *resp.RegistryId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to intentionally avoid dereferencing pointers in d.Set() as we were burnt in the past when the API returned empty field and terraform ended up crashing because it tried to dereference nil. Set() can perform safe dereferencing, so it's ok to just pass the pointer, i.e. d.Set("registry_id", resp.RegistryId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand👍

return resourceAwsEcrLifecyclePolicyRead(d, meta)
}

func resourceAwsEcrLifecyclePolicyRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecrconn

input := &ecr.GetLifecyclePolicyInput{
RegistryId: aws.String(d.Get("registry_id").(string)),
RepositoryName: aws.String(d.Get("repository").(string)),
}

_, err := conn.GetLifecyclePolicy(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case ecr.ErrCodeRepositoryNotFoundException, ecr.ErrCodeLifecyclePolicyNotFoundException:
d.SetId("")
return nil
default:
return err
}
}
return err
}

return nil
}

func resourceAwsEcrLifecyclePolicyDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecrconn

input := &ecr.DeleteLifecyclePolicyInput{
RegistryId: aws.String(d.Get("registry_id").(string)),
RepositoryName: aws.String(d.Get("repository").(string)),
}

_, err := conn.DeleteLifecyclePolicy(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case ecr.ErrCodeRepositoryNotFoundException, ecr.ErrCodeLifecyclePolicyNotFoundException:
d.SetId("")
return nil
default:
return err
}
}
return err
}

return nil
}
97 changes: 97 additions & 0 deletions aws/resource_aws_ecr_lifecycle_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package aws

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSEcrLifecyclePolicy(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but we like to give all basic test functions a suffix _basic so that when we add more in the future we can still run just this function without matching other ones which may have different suffix.

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrLifecyclePolicyDestroy,
Steps: []resource.TestStep{
{
Config: testAccEcrLifecyclePolicyConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrLifecyclePolicyExists("aws_ecr_lifecycle_policy.foo"),
),
},
},
})
}

func testAccCheckAWSEcrLifecyclePolicyDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecrconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_ecr_lifecycle_policy" {
continue
}

input := &ecr.GetLifecyclePolicyInput{
RegistryId: aws.String(rs.Primary.Attributes["registry_id"]),
RepositoryName: aws.String(rs.Primary.Attributes["repository"]),
}

_, err := conn.GetLifecyclePolicy(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case ecr.ErrCodeRepositoryNotFoundException:
return nil
default:
return err
}
}
return err
}
}

return nil
}

func testAccCheckAWSEcrLifecyclePolicyExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

return nil
}
}

const testAccEcrLifecyclePolicyConfig = `
resource "aws_ecr_repository" "foo" {
name = "bar"
}
resource "aws_ecr_lifecycle_policy" "foo" {
repository = "${aws_ecr_repository.foo.name}"
policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Expire images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 14
},
"action": {
"type": "expire"
}
}
]
}
EOF
}
`
4 changes: 4 additions & 0 deletions website/aws.erb
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@
<a href="#">ECS Resources</a>
<ul class="nav nav-visible">

<li<%= sidebar_current("docs-aws-resource-ecr-lifecycle-policy") %>>
<a href="/docs/providers/aws/r/ecr_lifecycle_policy.html">aws_ecr_lifecycle_policy</a>
</li>

<li<%= sidebar_current("docs-aws-resource-ecr-repository") %>>
<a href="/docs/providers/aws/r/ecr_repository.html">aws_ecr_repository</a>
</li>
Expand Down
57 changes: 57 additions & 0 deletions website/docs/r/ecr_lifecycle_policy.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: "aws"
page_title: "AWS: aws_ecr_lifecycle_policy"
sidebar_current: "docs-aws-resource-ecr-lifecycle-policy"
description: |-
Provides an ECR Lifecycle Policy.
---

# aws_ecr_ifecycle_policy

Provides an ECR lifecycle policy.

## Example Usage

```hcl
resource "aws_ecr_repository" "foo" {
name = "bar"
}

resource "aws_ecr_lifecycle_policy" "foopolicy" {
repository = "${aws_ecr_repository.foo.name}"

policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Expire images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 14
},
"action": {
"type": "expire"
}
}
]
}
EOF
}
```

## Argument Reference

The following arguments are supported:

* `repository` - (Required) Name of the repository to apply the policy.
* `policy` - (Required) The policy document. This is a JSON formatted string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to a any place which describes the supported syntax in the official docs? e.g. http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters


## Attributes Reference

The following attributes are exported:

* `repository` - The name of the repository.
* `registry_id` - The registry ID where the repository was created.