Ensures all S3 bucket names match the naming rules.
rule "aws_s3_bucket_name" {
enabled = true
regex = "^[a-z\\-]+$"
prefix = "my-org"
}
regex
: A Go regex that bucket names must match (string)prefix
: A prefix that should be used for bucket names (string)
resource "aws_s3_bucket" "foo" {
bucket = "foo"
}
resource "aws_s3_bucket" "too_long" {
bucket = "a-really-ultra-hiper-super-long-foo-bar-baz-bucket-name.domain.test"
}
$ tflint
2 issue(s) found:
Error: Bucket name "foo" does not have prefix "my-org" (aws_s3_bucket_name)
on main.tf line 2:
2: bucket = "foo"
Error: Bucket name "a-really-ultra-hiper-super-long-foo-bar-baz-bucket-name.domain.test" length must be within 3 - 63 character range (aws_s3_bucket_name)
on main.tf line 2:
2: bucket = "a-really-ultra-hiper-super-long-foo-bar-baz-bucket-name.domain.test"
Amazon S3 bucket names must be globally unique and have restrictive naming rules.
- Prefixing bucket names with an organization name can help avoid naming conflicts
- You may wish to enforce other naming conventions (e.g., disallowing dots)
Ensure the bucket name matches the specified rules.