add Dockerfiles for tfenv, tfswitch
diff --git a/scripts/development/Dockerfile.tfenv b/scripts/development/Dockerfile.tfenv new file mode 100644 index 0000000..16a5ee6 --- /dev/null +++ b/scripts/development/Dockerfile.tfenv
@@ -0,0 +1,21 @@ +FROM golang:1.15-alpine + +RUN apk update && apk add bash git unzip curl + +# install tfenv +RUN git clone https://github.com/tfutils/tfenv.git ~/.tfenv && \ + ln -s ~/.tfenv/bin/* /usr/local/bin + +# initialise go program +RUN mkdir ~/example +COPY main.go ~/example/ +WORKDIR ~/example +RUN go mod init github.com/kmoe/example + +# run test program without any terraform version installed +RUN go run main.go + +# install 0.13.4 via tfenv +RUN tfenv install 0.13.4 && tfenv use 0.13.4 + +RUN go run main.go \ No newline at end of file
diff --git a/scripts/development/Dockerfile.tfswitch b/scripts/development/Dockerfile.tfswitch new file mode 100644 index 0000000..ddd7c71 --- /dev/null +++ b/scripts/development/Dockerfile.tfswitch
@@ -0,0 +1,20 @@ +FROM golang:1.15-alpine + +RUN apk update && apk add bash git unzip curl + +# install tfswitch +RUN go get github.com/warrensbox/terraform-switcher + +# initialise go program +RUN mkdir ~/example +COPY main.go ~/example/ +WORKDIR ~/example +RUN go mod init github.com/kmoe/example + +# run test program without any terraform version installed +RUN go run main.go + +# install 0.13.4 via tfswitch +RUN terraform-switcher 0.13.4 + +RUN go run main.go \ No newline at end of file
diff --git a/scripts/development/main.go b/scripts/development/main.go new file mode 100644 index 0000000..82a75e6 --- /dev/null +++ b/scripts/development/main.go
@@ -0,0 +1,35 @@ +// an example application using tfexec +package main + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-exec/tfexec" + "github.com/hashicorp/terraform-exec/tfinstall" +) + +func main() { + execPath, err := tfinstall.Find(context.Background(), tfinstall.LookPath(), tfinstall.ExactVersion("0.13.3", "/tmp")) + if err != nil { + panic(err) + } + + workingDir := "/tmp" + tf, err := tfexec.NewTerraform(workingDir, execPath) + if err != nil { + panic(err) + } + + err = tf.Init(context.Background()) + if err != nil { + panic(err) + } + + tfVersion, _, err := tf.Version(context.Background(), true) + if err != nil { + panic(err) + } + + fmt.Printf("successfully initialised Terraform version %s", tfVersion) +}