Skip to content

Commit a6e938f

Browse files
authored
refactor: add validation for repository_name
AWS validates repository names only during apply, a Terraform plan can incorrectly appear valid in the plan step. This validation ensures that invalid repository names fail fast and early before any resources are created.
1 parent 9286de9 commit a6e938f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ variable "repository_name" {
3636
description = "The name of the repository"
3737
type = string
3838
default = ""
39+
40+
validation {
41+
condition = can(regex(
42+
"^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*$",
43+
var.repository_name_check
44+
))
45+
error_message = "Invalid repository_name: must be lowercase and match ^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*$"
46+
}
3947
}
4048

4149
variable "repository_image_tag_mutability" {

0 commit comments

Comments
 (0)