Skip to content

Commit

Permalink
TER-410 fix t8 generate edge case (#166)
Browse files Browse the repository at this point in the history
there was an edge case where the t8 generate command was failing for a
specific platform.

the case use to occur specifically when there is a terraform block
that is not linked to a file. and the platform path is an absolute path
not relative path.

this change fixes the issue by skipping such terraform blocks.
  • Loading branch information
Kanak Singhal authored Dec 15, 2023
1 parent 2ec56ff commit 640b4dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/cli/cmd/generate/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cldcvr/terrarium/src/pkg/testutils/clitesting"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCmd(t *testing.T) {
Expand All @@ -22,6 +23,9 @@ func TestCmd(t *testing.T) {
},
}

wd, err := os.Getwd()
require.NoError(t, err)

testSetup.RunTests(t, []clitesting.CLITestCase{
{
Name: "No components provided",
Expand Down Expand Up @@ -107,6 +111,38 @@ func TestCmd(t *testing.T) {
return pass
},
},
{
Name: "Success (edge case absolute path empty block)",
Args: []string{
"--platform-dir",
path.Clean(path.Join(wd, "../../../../examples/lz/platforms/03-team-env")),
"--output-dir",
"./testdata/.terrarium",
"--app",
path.Clean(path.Join(wd, "../../../../examples/lz/requirements/team-aa.yaml")),
},
ValidateOutput: func(ctx context.Context, t *testing.T, cmdOpts clitesting.CmdOpts, output []byte) bool {
pass := assert.Equal(t, "Successfully pulled 8 of 10 terraform blocks at: ./testdata/.terrarium\n", string(output))
pass = assertFilesExists(t,
"./testdata/.terrarium",
[]string{ // shouldExist
"app_aa.env.mustache",
"bucket.tf",
"database.tf",
"remote_state.tf",
"tr_gen_locals.tf",
"variable.tf",
},
[]string{ // shouldNotExist
"dev.tfvars",
"prod.tfvars",
"staging.tfvars",
"terrarium.yaml",
},
) && pass
return pass
},
},
{
Name: "Invalid profile name",
Args: []string{"-p", "../../../../examples/platform/", "-a", "../../../../examples/apps/voting-be", "-a", "../../../../examples/apps/voting-worker", "-o", "./testdata/.terrarium", "-c", "Isle"},
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func processBlocks(g platform.Graph, blocks []platform.BlockID, tfModule *tfconf
}

b, found := bID.GetBlock(tfModule)
if !found {
if !found || b.GetPos().Filename == "" {
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions src/cli/cmd/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ func Test_updateRelPath(t *testing.T) {
args args
want string
}{
{
args: args{
line: ` source = "../../modules"`,
srcDir: `/a/b/c`,
destDir: `/a/x/y`,
},
want: ` source = "../../modules"`,
},
{
args: args{
line: ` source = "./../modules"`,
Expand Down

0 comments on commit 640b4dd

Please sign in to comment.