Skip to content

Commit

Permalink
feat: Add a new variable to control the creation of a lifecycle policy (
Browse files Browse the repository at this point in the history
#4)

Co-authored-by: Bryant Biggs <[email protected]>
  • Loading branch information
phr3nzii and bryantbiggs authored Jun 13, 2022
1 parent b31ca50 commit 18c0515
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
| <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 |
| <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 |
| <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 |
| <a name="input_create_repository"></a> [create\_repository](#input\_create\_repository) | Determines whether a repository will be created | `bool` | `true` | no |
Expand Down
1 change: 1 addition & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module "ecr" {
repository_name = local.name

repository_read_write_access_arns = [data.aws_caller_identity.current.arn]
create_lifecycle_policy = true
repository_lifecycle_policy = jsonencode({
rules = [
{
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ resource "aws_ecr_repository" "this" {
################################################################################

resource "aws_ecr_repository_policy" "this" {
count = local.create_private_repository ? 1 : 0
count = local.create_private_repository && var.create_repository_policy ? 1 : 0

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

resource "aws_ecr_lifecycle_policy" "this" {
count = local.create_private_repository ? 1 : 0
count = local.create_private_repository && var.create_lifecycle_policy ? 1 : 0

repository = aws_ecr_repository.this[0].name
policy = var.repository_lifecycle_policy
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ variable "repository_read_write_access_arns" {
# Lifecycle Policy
################################################################################

variable "create_lifecycle_policy" {
description = "Determines whether a lifecycle policy will be created"
type = bool
default = true
}

variable "repository_lifecycle_policy" {
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"
type = string
Expand Down
1 change: 1 addition & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module "wrapper" {
create_repository_policy = try(each.value.create_repository_policy, var.defaults.create_repository_policy, true)
repository_read_access_arns = try(each.value.repository_read_access_arns, var.defaults.repository_read_access_arns, [])
repository_read_write_access_arns = try(each.value.repository_read_write_access_arns, var.defaults.repository_read_write_access_arns, [])
create_lifecycle_policy = try(each.value.create_lifecycle_policy, var.defaults.create_lifecycle_policy, true)
repository_lifecycle_policy = try(each.value.repository_lifecycle_policy, var.defaults.repository_lifecycle_policy, "")
public_repository_catalog_data = try(each.value.public_repository_catalog_data, var.defaults.public_repository_catalog_data, {})
create_registry_policy = try(each.value.create_registry_policy, var.defaults.create_registry_policy, false)
Expand Down

0 comments on commit 18c0515

Please sign in to comment.