Skip to content

Commit

Permalink
allow capital letters to resource name on block reader (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremmfr authored Aug 16, 2022
1 parent 220dcfa commit 093e0a3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blocks/blockreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (bv blockVisitor) Visit(cursor *astutil.Cursor) bool {

// Includes matching Go format verbs in the resource, data source, variable, or output name.
// Technically, this is only valid for the Go matcher, but included generally for simplicity.
var terraformMatcher = regexp.MustCompile(`(((resource|data)\s+"[-a-z0-9_]+")|(variable|output))\s+"[-a-z0-9_%\[\]]+"\s+\{`)
var terraformMatcher = regexp.MustCompile(`(((resource|data)\s+"[-a-z0-9_]+")|(variable|output))\s+"[-a-zA-Z0-9_%\[\]]+"\s+\{`)

// A simple check to see if the content looks like a Terraform configuration.
// Looks for a line with either a resource, data source, variable, or output declaration
Expand Down
14 changes: 14 additions & 0 deletions lib/blocks/blockreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ func TestBlockDetection(t *testing.T) {
text: `resource "aws_s3_bucket" "%s" {
bucket = "tf-test-bucket-with-quotedname"
}
`,
},
{
leadingPadding: "\n",
trailingPadding: "\n",
text: `resource "aws_s3_bucket" "UpperCase" {
bucket = "tf-test-bucket-with-uppercase"
}
`,
},
},
Expand All @@ -128,6 +136,12 @@ func TestBlockDetection(t *testing.T) {
resource "aws_s3_bucket" "leading-space-and-line" {
bucket = "tf-test-bucket-leading-space-and-line"
}
`,
},
{
text: `resource "aws_s3_bucket" "UpperCase" {
bucket = "tf-test-bucket-with-uppercase"
}
`,
},
},
Expand Down
8 changes: 8 additions & 0 deletions lib/blocks/testdata/test1.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ resource "aws_s3_bucket" "%s" {
`, name)
}

func testFormatUpperCase(name string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "UpperCase" {
bucket = "tf-test-bucket-with-uppercase"
}
`)
}

func notTerraformSimpleString() string {
fmt.Sprintf("%d: bad create: \n%#v\n%#v", i, cm, tc.Create)
}
Expand Down
8 changes: 8 additions & 0 deletions lib/blocks/testdata/test2.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ Test block with leading whitespace and line
bucket = "tf-test-bucket-leading-space-and-line"
}
```

Test block with capital letters in resource name

```terraform
resource "aws_s3_bucket" "UpperCase" {
bucket = "tf-test-bucket-with-uppercase"
}
```

0 comments on commit 093e0a3

Please sign in to comment.