Skip to content

Commit

Permalink
Feat: support terragrunt (#151)
Browse files Browse the repository at this point in the history
* Feat: support terragrunt

* added test verification
  • Loading branch information
TomerHeber authored Jul 24, 2022
1 parent 78e207b commit a0387ff
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,44 @@ jobs:
- name: Test
run: |
go test -v -run ^TestTerraform${{ steps.test-suite.outputs.result }}$
terragrunt-integration-tests:
name: Terragrunt Integration Tests
runs-on: ubuntu-latest

steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go mod tidy
- name: Install Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.2.5

- name: Print Terraform version
run: |
terraform --version
- name: Install Terragrunt
uses: autero1/[email protected]
with:
terragrunt_version: 0.38.5

- name: Print Terragrunt version
run: |
terragrunt --version
- name: Test
run: |
go test -v -run ^TestTerragruntWithCache$
35 changes: 34 additions & 1 deletion terratag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package terratag

import (
"bytes"
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -107,7 +109,7 @@ func TestTerragruntWithCache(t *testing.T) {
itShouldRunTerragruntInit(out, g)
itShouldRunTerratagTerragruntMode(out, g)
itShouldRunTerragruntValidate(out, g)
//itShouldGenerateExpectedTerratagFiles(tt.suiteDir, g)
itShouldGenerateExpectedTerragruntTerratagFiles(entryDir, g)
}

func testTerraform(t *testing.T, version string) {
Expand Down Expand Up @@ -170,6 +172,37 @@ func itShouldGenerateExpectedTerratagFiles(suiteDir string, g *GomegaWithT) {
}
}

func getFileSha256(filename string, g *GomegaWithT) string {
f, err := os.Open(filename)
g.Expect(err).To(BeNil())
defer f.Close()
h := sha256.New()
_, err = io.Copy(h, f)
g.Expect(err).To(BeNil())

return string(h.Sum(nil))
}

func itShouldGenerateExpectedTerragruntTerratagFiles(entryDir string, g *GomegaWithT) {
expectedPattern := entryDir + "/expected/**/*.tf"
expectedTerratag, _ := doublestar.Glob(expectedPattern)

actualTerratag, _ := doublestar.Glob(entryDir + "/out/**/.terragrunt-cache/**/*.tf")
actualTerratag = filterSymlink(actualTerratag)

hashmap := make(map[string]string)

for _, acctualTerratagFile := range actualTerratag {
hashmap[getFileSha256(acctualTerratagFile, g)] = acctualTerratagFile
}

for _, expectedTerratagFile := range expectedTerratag {
hash := getFileSha256(expectedTerratagFile, g)
_, ok := hashmap[hash]
g.Expect(ok).To(BeTrue())
}
}

func itShouldRunTerraformValidate(entryDir string, g *GomegaWithT) {
err := run_terraform(entryDir, "validate")
g.Expect(err).To(BeNil(), "terraform validate failed")
Expand Down

0 comments on commit a0387ff

Please sign in to comment.