commit | 1ec9fc1a13842a90f1087b90bc039bbaa4007bbb | [log] [tgz] |
---|---|---|
author | Kent 'picat' Gruber <kent@hashicorp.com> | Mon Nov 09 15:53:53 2020 -0500 |
committer | Katy Moe <katy@katy.moe> | Fri Nov 27 17:41:13 2020 +0000 |
tree | b3a89c3a7c8a90357e04e995e609fa0273f4a94a | |
parent | 1cc2776a0b654c01c431639926ee090310dd12ae [diff] |
Bump go-getter to v1.5.0 github.com/ulikunitz/xz@0.5.5 used by github.com/hashicorp/go-getter@1.4.0 contains a DoS where it is possible to create an infinite read loop due to the usage of the ReadUvarint and ReadVarint function when encoding/binary via invalid inputs. https://github.com/hashicorp/go-getter/pull/278
A Go module for constructing and running Terraform CLI commands. Structured return values use the data types defined in terraform-json.
The Terraform Plugin SDK is the canonical Go interface for Terraform plugins using the gRPC protocol. This library is intended for use in Go programs that make use of Terraform's other interface, the CLI. Importing this library is preferable to importing github.com/hashicorp/terraform/command
, because the latter is not intended for use outside Terraform Core.
While terraform-exec is already widely used, please note that this module is not yet at v1.0.0, and that therefore breaking changes may occur in minor releases.
We strictly follow semantic versioning.
The Terraform
struct must be initialised with NewTerraform(workingDir, execPath)
.
Top-level Terraform commands each have their own function, which will return either error
or (T, error)
, where T
is a terraform-json
type.
package main import ( "context" "fmt" "io/ioutil" "os" "github.com/hashicorp/terraform-exec/tfexec" "github.com/hashicorp/terraform-exec/tfinstall" ) func main() { tmpDir, err := ioutil.TempDir("", "tfinstall") if err != nil { panic(err) } defer os.RemoveAll(tmpDir) execPath, err := tfinstall.Find(tfinstall.LatestVersion(tmpDir, false)) if err != nil { panic(err) } workingDir := "/path/to/working/dir" tf, err := tfexec.NewTerraform(workingDir, execPath) if err != nil { panic(err) } err = tf.Init(context.Background(), tfexec.Upgrade(true), tfexec.LockTimeout("60s")) if err != nil { panic(err) } state, err := tf.Show(context.Background()) if err != nil { panic(err) } fmt.Println(state.FormatVersion) // "0.1" }
Please see CONTRIBUTING.md.