Skip to content

Commit

Permalink
fix(cmd): removed flag parsing when wrapping terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChalk committed Sep 20, 2021
1 parent afb5651 commit 8a456c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/twrapper/cmd/cmd_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ var rootCmd = &cobra.Command{
Use: "twrapper",
Short: "Wrapper for initialising Terraform",
Long: `Sets some things up before running Terraform in a CI environment.`,
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
err := config.checkRequirements()
fatalIfNotNil(err, "%s")

opts := terraform.NewOpts()
opts.WithArguments(ActionArgs(args))
opts.WithBackend(config.Backend())
Expand Down
25 changes: 25 additions & 0 deletions cmd/twrapper/cmd/cmd_root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCmdAllArgs(t *testing.T) {
r := bytes.NewBufferString("")
rootCmd.SetOut(r)

err := os.Setenv("KEY_ID", "2F4A2B8D-9353-44EA-8248-386CB0FE7425")
assert.Nil(t, err)

rootCmd.SetArgs([]string{"terraform", "-version"})
err = rootCmd.Execute()
assert.Nil(t, err)

_, err = ioutil.ReadAll(r)
assert.Nil(t, err)
}
3 changes: 3 additions & 0 deletions cmd/twrapper/cmd/terraform.twrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aws:
backend_key_id_var: KEY_ID
backend_type: local
8 changes: 0 additions & 8 deletions cmd/twrapper/cmd/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"log"
)
Expand All @@ -17,9 +15,3 @@ func fatalIfNotNil(err error, errStr string) {
log.Fatalf(errStr, err.Error())
}
}

func printMarshalled(v interface{}) {
if d, err := json.MarshalIndent(v, "", " "); err == nil {
fmt.Println(string(d))
}
}

0 comments on commit 8a456c2

Please sign in to comment.