{"id":13490880,"url":"https://github.com/hashicorp/terraform-exec","last_synced_at":"2025-05-13T16:08:16.959Z","repository":{"id":37821811,"uuid":"260272619","full_name":"hashicorp/terraform-exec","owner":"hashicorp","description":"Terraform CLI commands via Go.","archived":false,"fork":false,"pushed_at":"2025-04-17T08:48:39.000Z","size":814,"stargazers_count":718,"open_issues_count":61,"forks_count":120,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-23T21:53:43.683Z","etag":null,"topics":["go","terraform","terraform-sdk"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hashicorp/terraform-exec","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashicorp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-04-30T17:17:52.000Z","updated_at":"2025-04-22T13:48:24.000Z","dependencies_parsed_at":"2023-02-17T23:15:59.375Z","dependency_job_id":"8468cb3d-4cd8-4520-b34c-53b484372109","html_url":"https://github.com/hashicorp/terraform-exec","commit_stats":{"total_commits":500,"total_committers":45,"mean_commits":11.11111111111111,"dds":0.8180000000000001,"last_synced_commit":"ae771c90d1cd3d4cdd958dd3c09fd5de8f2e5b32"},"previous_names":["kmoe/terraform-exec"],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fterraform-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fterraform-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fterraform-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fterraform-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashicorp","download_url":"https://codeload.github.com/hashicorp/terraform-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253980052,"owners_count":21994042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","terraform","terraform-sdk"],"created_at":"2024-07-31T19:00:51.737Z","updated_at":"2025-05-13T16:08:16.940Z","avatar_url":"https://github.com/hashicorp.png","language":"Go","funding_links":[],"categories":["Go","Terraform Tools and Services"],"sub_categories":[],"readme":"[![PkgGoDev](https://pkg.go.dev/badge/github.com/hashicorp/terraform-exec)](https://pkg.go.dev/github.com/hashicorp/terraform-exec)\n\n# terraform-exec\n\nA Go module for constructing and running [Terraform](https://terraform.io) CLI commands. Structured return values use the data types defined in [terraform-json](https://github.com/hashicorp/terraform-json).\n\nThe [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework) is the canonical Go interface (SDK) 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.\n\nWhile 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.\n\nWe strictly follow [semantic versioning](https://semver.org).\n\n## Go compatibility\n\nThis library is built in Go, and uses the [support policy](https://golang.org/doc/devel/release.html#policy) of Go as its support policy. The two latest major releases of Go are supported by terraform-exec.\n\nCurrently, that means Go **1.23** or later must be used.\n\n## Terraform compatibility\n\nWe generally follow [Terraform's own compatibility promises](https://developer.hashicorp.com/terraform/language/v1-compatibility-promises). i.e. **we recommend Terraform v1.x to be used alongside this library**.\n\nGiven the nature of this library being used in automation, we maintain compatibility **on best effort basis** with latest minor versions from `0.12` and later. This does not imply coverage of all features or CLI surface, just that it shouldn't break in unexpected ways.\n\n## Usage\n\nThe `Terraform` struct must be initialised with `NewTerraform(workingDir, execPath)`. \n\nTop-level Terraform commands each have their own function, which will return either `error` or `(T, error)`, where `T` is a `terraform-json` type.\n\n\n### Example\n\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/hashicorp/go-version\"\n\t\"github.com/hashicorp/hc-install/product\"\n\t\"github.com/hashicorp/hc-install/releases\"\n\t\"github.com/hashicorp/terraform-exec/tfexec\"\n)\n\nfunc main() {\n\tinstaller := \u0026releases.ExactVersion{\n\t\tProduct: product.Terraform,\n\t\tVersion: version.Must(version.NewVersion(\"1.0.6\")),\n\t}\n\n\texecPath, err := installer.Install(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"error installing Terraform: %s\", err)\n\t}\n\n\tworkingDir := \"/path/to/working/dir\"\n\ttf, err := tfexec.NewTerraform(workingDir, execPath)\n\tif err != nil {\n\t\tlog.Fatalf(\"error running NewTerraform: %s\", err)\n\t}\n\n\terr = tf.Init(context.Background(), tfexec.Upgrade(true))\n\tif err != nil {\n\t\tlog.Fatalf(\"error running Init: %s\", err)\n\t}\n\n\tstate, err := tf.Show(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"error running Show: %s\", err)\n\t}\n\n\tfmt.Println(state.FormatVersion) // \"0.1\"\n}\n```\n\n## Testing Terraform binaries\n\nThe terraform-exec test suite contains end-to-end tests which run realistic workflows against a real Terraform binary using `tfexec.Terraform{}`.\n\nTo run these tests with a local Terraform binary, set the environment variable `TFEXEC_E2ETEST_TERRAFORM_PATH` to its path and run:\n```sh\ngo test -timeout=20m ./tfexec/internal/e2etest\n```\n\nFor more information on terraform-exec's test suite, please see Contributing below.\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](./CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fterraform-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashicorp%2Fterraform-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fterraform-exec/lists"}