Skip to content

Commit 18c0515

Browse files
feat: Add a new variable to control the creation of a lifecycle policy (#4)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent b31ca50 commit 18c0515

File tree

6 files changed

+12
-3
lines changed

6 files changed

+12
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
- '--args=--only=terraform_standard_module_structure'
2525
- '--args=--only=terraform_workspace_remote'
2626
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.2.0
27+
rev: v4.3.0
2828
hooks:
2929
- id: check-merge-conflict
3030
- id: end-of-file-fixer

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ No modules.
216216
| Name | Description | Type | Default | Required |
217217
|------|-------------|------|---------|:--------:|
218218
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
219+
| <a name="input_create_lifecycle_policy"></a> [create\_lifecycle\_policy](#input\_create\_lifecycle\_policy) | Determines whether a lifecycle policy will be created | `bool` | `true` | no |
219220
| <a name="input_create_registry_policy"></a> [create\_registry\_policy](#input\_create\_registry\_policy) | Determines whether a registry policy will be created | `bool` | `false` | no |
220221
| <a name="input_create_registry_replication_configuration"></a> [create\_registry\_replication\_configuration](#input\_create\_registry\_replication\_configuration) | Determines whether a registry replication configuration will be created | `bool` | `false` | no |
221222
| <a name="input_create_repository"></a> [create\_repository](#input\_create\_repository) | Determines whether a repository will be created | `bool` | `true` | no |

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module "ecr" {
3232
repository_name = local.name
3333

3434
repository_read_write_access_arns = [data.aws_caller_identity.current.arn]
35+
create_lifecycle_policy = true
3536
repository_lifecycle_policy = jsonencode({
3637
rules = [
3738
{

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ resource "aws_ecr_repository" "this" {
109109
################################################################################
110110

111111
resource "aws_ecr_repository_policy" "this" {
112-
count = local.create_private_repository ? 1 : 0
112+
count = local.create_private_repository && var.create_repository_policy ? 1 : 0
113113

114114
repository = aws_ecr_repository.this[0].name
115115
policy = var.create_repository_policy ? data.aws_iam_policy_document.repository[0].json : var.repository_policy
@@ -120,7 +120,7 @@ resource "aws_ecr_repository_policy" "this" {
120120
################################################################################
121121

122122
resource "aws_ecr_lifecycle_policy" "this" {
123-
count = local.create_private_repository ? 1 : 0
123+
count = local.create_private_repository && var.create_lifecycle_policy ? 1 : 0
124124

125125
repository = aws_ecr_repository.this[0].name
126126
policy = var.repository_lifecycle_policy

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ variable "repository_read_write_access_arns" {
8888
# Lifecycle Policy
8989
################################################################################
9090

91+
variable "create_lifecycle_policy" {
92+
description = "Determines whether a lifecycle policy will be created"
93+
type = bool
94+
default = true
95+
}
96+
9197
variable "repository_lifecycle_policy" {
9298
description = "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"
9399
type = string

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module "wrapper" {
1616
create_repository_policy = try(each.value.create_repository_policy, var.defaults.create_repository_policy, true)
1717
repository_read_access_arns = try(each.value.repository_read_access_arns, var.defaults.repository_read_access_arns, [])
1818
repository_read_write_access_arns = try(each.value.repository_read_write_access_arns, var.defaults.repository_read_write_access_arns, [])
19+
create_lifecycle_policy = try(each.value.create_lifecycle_policy, var.defaults.create_lifecycle_policy, true)
1920
repository_lifecycle_policy = try(each.value.repository_lifecycle_policy, var.defaults.repository_lifecycle_policy, "")
2021
public_repository_catalog_data = try(each.value.public_repository_catalog_data, var.defaults.public_repository_catalog_data, {})
2122
create_registry_policy = try(each.value.create_registry_policy, var.defaults.create_registry_policy, false)

0 commit comments

Comments
 (0)