generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
296 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
test: | ||
name: ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.15 | ||
- name: Run tests | ||
run: make test | ||
- name: Run build | ||
run: make build | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@master | ||
with: | ||
name: tflint-ruleset-google-${{ matrix.os }} | ||
path: tflint-ruleset-google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: e2e | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
e2e: | ||
name: ${{ matrix.os }} (${{ matrix.version }}) | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
version: [v0.20.1, latest] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.15 | ||
- name: Set env | ||
if: matrix.version != 'latest' | ||
run: echo "::set-env name=TFLINT_VERSION::${{ matrix.version }}" | ||
- name: Install TFLint | ||
run: curl -sL https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash | ||
- name: Install plugin (Linux) | ||
if: runner.os == 'Linux' | ||
run: make install | ||
- name: Install plugin (Windows) | ||
if: runner.os == 'Windows' | ||
run: | | ||
mkdir -p ~/.tflint.d/plugins | ||
go build -o ~/.tflint.d/plugins/tflint-ruleset-google.exe | ||
shell: bash | ||
- name: Run E2E tests | ||
run: make e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugin "google" { | ||
enabled = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "google_app_engine_domain_mapping" "domain_mapping" { | ||
domain_name = "verified-domain.com" | ||
override_strategy = "DEFAULT" | ||
|
||
ssl_settings { | ||
ssl_management_type = "AUTOMATIC" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"issues":[ | ||
{ | ||
"rule":{ | ||
"name":"google_app_engine_domain_mapping_invalid_override_strategy", | ||
"severity":"error", | ||
"link":"" | ||
}, | ||
"message":"expected override_strategy to be one of [STRICT OVERRIDE ], got DEFAULT", | ||
"range":{ | ||
"filename":"main.tf", | ||
"start":{ | ||
"line":3, | ||
"column":23 | ||
}, | ||
"end":{ | ||
"line":3, | ||
"column":32 | ||
} | ||
}, | ||
"callers":[ | ||
|
||
] | ||
} | ||
], | ||
"errors":[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestIntegration(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Command *exec.Cmd | ||
Dir string | ||
}{ | ||
{ | ||
Name: "basic", | ||
Command: exec.Command("tflint", "--format", "json", "--force"), | ||
Dir: "basic", | ||
}, | ||
} | ||
|
||
dir, _ := os.Getwd() | ||
defer os.Chdir(dir) | ||
|
||
for _, tc := range cases { | ||
testDir := dir + "/" + tc.Dir | ||
os.Chdir(testDir) | ||
|
||
var stdout, stderr bytes.Buffer | ||
tc.Command.Stdout = &stdout | ||
tc.Command.Stderr = &stderr | ||
if err := tc.Command.Run(); err != nil { | ||
t.Fatalf("Failed `%s`: %s, stdout=%s stderr=%s", tc.Name, err, stdout.String(), stderr.String()) | ||
} | ||
|
||
ret, err := ioutil.ReadFile("result.json") | ||
if err != nil { | ||
t.Fatalf("Failed `%s`: %s", tc.Name, err) | ||
} | ||
|
||
var expected interface{} | ||
if err := json.Unmarshal(ret, &expected); err != nil { | ||
t.Fatalf("Failed `%s`: %s", tc.Name, err) | ||
} | ||
|
||
var got interface{} | ||
if err := json.Unmarshal(stdout.Bytes(), &got); err != nil { | ||
t.Fatalf("Failed `%s`: %s", tc.Name, err) | ||
} | ||
|
||
if !cmp.Equal(got, expected) { | ||
t.Fatalf("Failed `%s`: diff=%s", tc.Name, cmp.Diff(expected, got)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package magicmodules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/terraform-linters/tflint-plugin-sdk/helper" | ||
) | ||
|
||
func Test_generatedRegexRule(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Content string | ||
Expected helper.Issues | ||
}{ | ||
{ | ||
Name: "invalid", | ||
Content: ` | ||
resource "google_compute_backend_bucket" "main" { | ||
name = "123" | ||
}`, | ||
Expected: helper.Issues{ | ||
{ | ||
Rule: NewGoogleComputeBackendBucketInvalidNameRule(), | ||
Message: `"name" ("123") doesn't match regexp "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$"`, | ||
Range: hcl.Range{ | ||
Filename: "resource.tf", | ||
Start: hcl.Pos{Line: 3, Column: 10}, | ||
End: hcl.Pos{Line: 3, Column: 15}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "valid", | ||
Content: ` | ||
resource "google_compute_backend_bucket" "main" { | ||
name = "valid" | ||
}`, | ||
Expected: helper.Issues{}, | ||
}, | ||
} | ||
|
||
rule := NewGoogleComputeBackendBucketInvalidNameRule() | ||
|
||
for _, tc := range cases { | ||
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content}) | ||
|
||
if err := rule.Check(runner); err != nil { | ||
t.Fatalf("Unexpected error occurred: %s", err) | ||
} | ||
|
||
helper.AssertIssues(t, tc.Expected, runner.Issues) | ||
} | ||
} | ||
|
||
func Test_generatedEnumRule(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Content string | ||
Expected helper.Issues | ||
}{ | ||
{ | ||
Name: "invalid", | ||
Content: ` | ||
resource "google_cloud_asset_folder_feed" "main" { | ||
content_type = "INVALID" | ||
}`, | ||
Expected: helper.Issues{ | ||
{ | ||
Rule: NewGoogleCloudAssetFolderFeedInvalidContentTypeRule(), | ||
Message: `expected content_type to be one of [CONTENT_TYPE_UNSPECIFIED RESOURCE IAM_POLICY ORG_POLICY ACCESS_POLICY ], got INVALID`, | ||
Range: hcl.Range{ | ||
Filename: "resource.tf", | ||
Start: hcl.Pos{Line: 3, Column: 18}, | ||
End: hcl.Pos{Line: 3, Column: 27}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "valid", | ||
Content: ` | ||
resource "google_cloud_asset_folder_feed" "main" { | ||
name = "RESOURCE" | ||
}`, | ||
Expected: helper.Issues{}, | ||
}, | ||
} | ||
|
||
rule := NewGoogleCloudAssetFolderFeedInvalidContentTypeRule() | ||
|
||
for _, tc := range cases { | ||
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content}) | ||
|
||
if err := rule.Check(runner); err != nil { | ||
t.Fatalf("Unexpected error occurred: %s", err) | ||
} | ||
|
||
helper.AssertIssues(t, tc.Expected, runner.Issues) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/terraform-linters/tflint-ruleset-google/tools | ||
|
||
go 1.15 |