From f35f9138ba7345da04e617ef5f3229bc2a18b3a0 Mon Sep 17 00:00:00 2001 From: Tim Black Date: Fri, 21 Oct 2022 19:00:48 -0700 Subject: [PATCH] feat: validate bucket names (#102) * #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 --- variables.tf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/variables.tf b/variables.tf index 4f56013..6aad714 100644 --- a/variables.tf +++ b/variables.tf @@ -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." + } } #---------------------------------------------------------------------------------------------------