Skip to content

Commit 217b4f0

Browse files
committed
fix: resolve lifecycle prevent_destroy variable limitation - Replace single repository resource with conditional creation approach - Use separate aws_ecr_repository resources (repo and repo_protected) - Enable dynamic prevent_destroy control through var.prevent_destroy - Remove moved.tf as it's not needed with this approach - Reorganize main.tf with proper section headers
1 parent 9f0735a commit 217b4f0

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

main.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# ----------------------------------------------------------
2+
# Configuration Locals
3+
# ----------------------------------------------------------
4+
5+
6+
7+
# ----------------------------------------------------------
8+
# ECR Repository
9+
# ----------------------------------------------------------
10+
11+
# ECR Repository - Standard version (prevent_destroy = false)
112
resource "aws_ecr_repository" "repo" {
213
count = var.prevent_destroy ? 0 : 1
314
name = var.name
@@ -84,14 +95,19 @@ resource "aws_ecr_repository" "repo_protected" {
8495
)
8596
}
8697

87-
# Local reference to whichever repository was created
98+
# Repository output references
8899
locals {
100+
# Repository output references for use in other resources and outputs
89101
repository_id = var.prevent_destroy ? aws_ecr_repository.repo_protected[0].id : aws_ecr_repository.repo[0].id
90102
repository_name = var.prevent_destroy ? aws_ecr_repository.repo_protected[0].name : aws_ecr_repository.repo[0].name
91103
repository_url = var.prevent_destroy ? aws_ecr_repository.repo_protected[0].repository_url : aws_ecr_repository.repo[0].repository_url
92104
registry_id = var.prevent_destroy ? aws_ecr_repository.repo_protected[0].registry_id : aws_ecr_repository.repo[0].registry_id
93105
}
94106

107+
# ----------------------------------------------------------
108+
# Repository Policies
109+
# ----------------------------------------------------------
110+
95111
# Repository policy - controls access to the repository
96112
resource "aws_ecr_repository_policy" "policy" {
97113
count = var.policy == null ? 0 : 1
@@ -118,6 +134,10 @@ resource "aws_ecr_lifecycle_policy" "lifecycle_policy" {
118134
]
119135
}
120136

137+
# ----------------------------------------------------------
138+
# AWS Identity and KMS Resources
139+
# ----------------------------------------------------------
140+
121141
# Get current AWS account ID
122142
data "aws_caller_identity" "current" {}
123143

@@ -207,6 +227,10 @@ resource "aws_kms_alias" "kms_key_alias" {
207227
}
208228
}
209229

230+
# ----------------------------------------------------------
231+
# Logging Resources
232+
# ----------------------------------------------------------
233+
210234
# CloudWatch Log Group for ECR logs
211235
resource "aws_cloudwatch_log_group" "ecr_logs" {
212236
count = var.enable_logging ? 1 : 0

moved.tf

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)