Skip to content

Commit

Permalink
feat: validate bucket names (#102)
Browse files Browse the repository at this point in the history
* #101: added validation for s3_bucket_name* input variables

* #101: remove override variable from conditional bc validation condition can only refer to tha variable being validated

* #101: try to fix validation regex error

* #101: escape backslashes

* #101: remove lookaheads from regex bc tf doesn't support them

* #101: added missing backslash escape

* fix: do not allow uppercase letters for bucket names

* fix: do not fail vailidation when bucket names are not specified

Co-authored-by: nozaq <[email protected]>
  • Loading branch information
timblaktu and nozaq authored Oct 22, 2022
1 parent 11c636d commit f35f913
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,19 @@ variable "s3_bucket_name" {
description = "If override_s3_bucket_name is true, use this bucket name instead of dynamic name with bucket_prefix"
type = string
default = ""
validation {
condition = length(var.s3_bucket_name) == 0 || length(regexall("^[a-z0-9][a-z0-9\\-.]{1,61}[a-z0-9]$", var.s3_bucket_name)) > 0
error_message = "Input variable s3_bucket_name is invalid. Please refer to https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html."
}
}
variable "s3_bucket_name_replica" {
description = "If override_s3_bucket_name is true, use this bucket name for replica instead of dynamic name with bucket_prefix"
type = string
default = ""
validation {
condition = length(var.s3_bucket_name_replica) == 0 || length(regexall("^[a-z0-9][a-z0-9\\-.]{1,61}[a-z0-9]$", var.s3_bucket_name_replica)) > 0
error_message = "Input variable s3_bucket_name_replica is invalid. Please refer to https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html."
}
}

#---------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit f35f913

Please sign in to comment.