Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions rules/aws_s3_bucket_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (r *AwsS3BucketNameRule) Check(runner tflint.Runner) error {
Description: "Bucket names must not start with the prefix 'xn--'.",
},
{
Regexp: *regexp.MustCompile("^(sthree-|sthree-configurator)"),
Description: "Bucket names must not start with the prefix 'sthree-' and the prefix 'sthree-configurator'.",
Regexp: *regexp.MustCompile("^(sthree-|sthree-configurator|amzn-s3-demo-)"),
Description: "Bucket names must not start with the prefix 'sthree-', 'sthree-configurator', or 'amzn-s3-demo-'.",
},
{
Regexp: *regexp.MustCompile("-s3alias$"),
Expand All @@ -119,6 +119,18 @@ func (r *AwsS3BucketNameRule) Check(runner tflint.Runner) error {
Regexp: *regexp.MustCompile("--ol-s3$"),
Description: "Bucket names must not end with the suffix '--ol-s3'.",
},
{
Regexp: *regexp.MustCompile("\\.mrap$"),
Description: "Bucket names must not end with the suffix '.mrap'.",
},
{
Regexp: *regexp.MustCompile("--x-s3$"),
Description: "Bucket names must not end with the suffix '--x-s3'.",
},
{
Regexp: *regexp.MustCompile("--table-s3$"),
Description: "Bucket names must not end with the suffix '--table-s3'.",
},
}

for _, resource := range resources.Blocks {
Expand Down
78 changes: 77 additions & 1 deletion rules/aws_s3_bucket_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ resource "aws_s3_bucket" "invalid_prefix_sthree" {
Expected: helper.Issues{
{
Rule: NewAwsS3BucketNameRule(),
Message: `Bucket names must not start with the prefix 'sthree-' and the prefix 'sthree-configurator'. (name: "sthree-domain.com", regex: "^(sthree-|sthree-configurator)")`,
Message: `Bucket names must not start with the prefix 'sthree-', 'sthree-configurator', or 'amzn-s3-demo-'. (name: "sthree-domain.com", regex: "^(sthree-|sthree-configurator|amzn-s3-demo-)")`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 12},
Expand Down Expand Up @@ -314,6 +314,82 @@ resource "aws_s3_bucket" "invalid_suffix_ols3" {
},
},
},
{
Name: "invalid_prefix_amzn_s3_demo",
Content: `
resource "aws_s3_bucket" "invalid_prefix_amzn_s3_demo" {
bucket = "amzn-s3-demo-bucket"
}
`,
Expected: helper.Issues{
{
Rule: NewAwsS3BucketNameRule(),
Message: `Bucket names must not start with the prefix 'sthree-', 'sthree-configurator', or 'amzn-s3-demo-'. (name: "amzn-s3-demo-bucket", regex: "^(sthree-|sthree-configurator|amzn-s3-demo-)")`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 12},
End: hcl.Pos{Line: 3, Column: 33},
},
},
},
},
{
Name: "invalid_suffix_mrap",
Content: `
resource "aws_s3_bucket" "invalid_suffix_mrap" {
bucket = "my-bucket.mrap"
}
`,
Expected: helper.Issues{
{
Rule: NewAwsS3BucketNameRule(),
Message: `Bucket names must not end with the suffix '.mrap'. (name: "my-bucket.mrap", regex: "\\.mrap$")`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 12},
End: hcl.Pos{Line: 3, Column: 28},
},
},
},
},
{
Name: "invalid_suffix_x_s3",
Content: `
resource "aws_s3_bucket" "invalid_suffix_x_s3" {
bucket = "my-bucket--x-s3"
}
`,
Expected: helper.Issues{
{
Rule: NewAwsS3BucketNameRule(),
Message: `Bucket names must not end with the suffix '--x-s3'. (name: "my-bucket--x-s3", regex: "--x-s3$")`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 12},
End: hcl.Pos{Line: 3, Column: 29},
},
},
},
},
{
Name: "invalid_suffix_table_s3",
Content: `
resource "aws_s3_bucket" "invalid_suffix_table_s3" {
bucket = "my-bucket--table-s3"
}
`,
Expected: helper.Issues{
{
Rule: NewAwsS3BucketNameRule(),
Message: `Bucket names must not end with the suffix '--table-s3'. (name: "my-bucket--table-s3", regex: "--table-s3$")`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 12},
End: hcl.Pos{Line: 3, Column: 33},
},
},
},
},
}

rule := NewAwsS3BucketNameRule()
Expand Down
Loading