{"id":21148858,"url":"https://github.com/vjftw/please-terraform","last_synced_at":"2026-02-14T02:03:52.110Z","repository":{"id":55524486,"uuid":"389254184","full_name":"VJftw/please-terraform","owner":"VJftw","description":"Terraform integration w/ the Please build system","archived":false,"fork":false,"pushed_at":"2024-11-28T22:01:11.000Z","size":145,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T11:11:43.330Z","etag":null,"topics":["build","build-system","opa","please","please-build","terraform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VJftw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-07-25T03:46:35.000Z","updated_at":"2025-03-18T18:19:59.000Z","dependencies_parsed_at":"2024-02-14T20:39:48.184Z","dependency_job_id":"aaa19676-3d95-408c-8610-52b1f793dab8","html_url":"https://github.com/VJftw/please-terraform","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":"0.20833333333333337","last_synced_commit":"5235afa7e93b151c1d3fdb9b6c52fb14139bddd6"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/VJftw/please-terraform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VJftw%2Fplease-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VJftw%2Fplease-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VJftw%2Fplease-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VJftw%2Fplease-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VJftw","download_url":"https://codeload.github.com/VJftw/please-terraform/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VJftw%2Fplease-terraform/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29431593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T22:20:51.549Z","status":"online","status_checked_at":"2026-02-14T02:00:07.626Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["build","build-system","opa","please","please-build","terraform"],"created_at":"2024-11-20T09:29:31.079Z","updated_at":"2026-02-14T02:03:52.098Z","avatar_url":"https://github.com/VJftw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# please-terraform\nTerraform integration w/ the Please build system.\n\nThis includes support for the following:\n * `terraform_toolchain`: Easy management of multiple versions of Terraform.\n * `terraform_module`: Terraform modules from the local filesystem.\n * `terraform_registry_module`: Terraform Modules from the Terraform Registry.\n * `terraform_root`: Terraform root configuration management.\n\n\n## `terraform_toolchain`\n\nThis build rule allows you to specify a Terraform version to download and re-use in `terraform_root` rules. You can repeat this for multiple versions if you like, see `//third_party/terraform/BUILD` for examples.\n\n## `terraform_module`\n\nThis build rule allows you to specify a [Terraform module](https://www.terraform.io/docs/language/modules/index.html) to re-use in your `terraform_root` rules or as dependencies in other `terraform_module` rules. These Terraform modules are sourced locally on the filesystem. For externally sourced modules, see `terraform_registry_module`.\n\nSee `//examples/\u003cversion\u003e/my_module/BUILD` for examples of `terraform_module`s.\n\nIn your Terraform source code, you should refer to your modules by their canonical build label. e.g.:\n\n```typescript\nmodule \"my_module\" {\n    source = \"//examples/0.12/my_module:my_module\"\n}\n```\n\nIf your module has providers or required providers configuration, you must include them as deps.\n\n\n## `terraform_registry_module`\n\nThis build rule allows you to specify a [Terraform Module]() from the a Terraform Registry to re-use in your `terraform_root` rules or as dependencies in other `terraform_module` rules.\n\nSet `//example/third_party/terraform/module/BUILD` for examples of `terraform_registry_module`s.\n\n```typescript\nmodule \"remote_module\" {\n    source = \"//examples/third_party/modules:my_module\"\n}\n```\n\n## `terraform_root`\n\nThis build rule allows to specify a [Terraform root module](https://www.terraform.io/docs/language/modules/index.html#the-root-module) which is the root configuration where Terraform will be executed. In this build rule, you reference the `srcs` for the root module as well as the providers and modules those `srcs` use.\n\nTerraform Providers are mirrored into a local directory for Terraform to source them from (https://www.terraform.io/docs/cli/config/config-file.html#explicit-installation-method-configuration).\n\n\nWe support substitution of the following please build environment variables into your source terraform files:\n - `PKG`\n - `PKG_DIR`\n - `NAME`\n - `ARCH`\n - `OS`\nThis allows you to template Terraform code to keep your code DRY. for example: A terraform remote state configuration can that can be re-used in all `terraform_root`s:\n```\nterraform {\n  backend \"s3\" {\n    region         = \"eu-west-1\"\n    bucket         = \"my-terraform-state\"\n    key            = \"$PKG/$NAME.tfstate\"\n    dynamodb_table = \"my-terraform-state-lock\"\n    encrypt        = true\n  }\n}\n```\nThe above will result in a terraform state tree consistent with the structure of your repository.\n\nThis build rule generates the following subrules which perform the Terraform workflows:\n * `\u003cname\u003e`: for all workflows. This sets up a Virtual Environment where `terraform` can be called directly. For example:\n    * `plz run //my_infrastructure_tf -- terraform init`\n    * `plz run //my_infrastructure_tf -- \"terraform init \u0026\u0026 terraform console\"`\n * `_plan`\n * `_apply`\n * `_destroy`\n * `` for all other workflows e.g.\n\nFor all of these workflows, we support passing in flags via please as expected, e.g.:\n```\n$ plz run //my_tf:my_tf_plan -- -lock=false\n$ plz run //my_tf:my_tf_import -- resource_type.my_resource resource_id\n```\n\nSee `//example/\u003cversion\u003e/BUILD` for examples of `terraform_root`.\n\n**NOTE**: This build rule utilises a [Terraform working directory](https://www.terraform.io/docs/cli/init/index.html) in `plz-out`, so whilst this is okay for demonstrations, you must use [Terraform Remote State](https://www.terraform.io/docs/language/state/remote.html) for your regular work. This can be added either simply through your `srcs` or through a `pre_binaries` binary.\n\n---\n\n## Usage\n\n\n### Please Plugin\n\n```ini\n; .plzconfig\n\n; Support the non *-rules repo name format of Please plugins.\nPluginRepo = [\"https://github.com/{owner}/{plugin}/archive/{revision}.zip\"]\n\n[Plugin \"terraform\"]\nTarget = //third_party/plugins:terraform\nToolVersion = \"v0.0.1\" ; Skipping ToolVersion will build the Tool from source.\n```\n\n```python\n# //third_party/plugins/BUILD\nplugin_repo(\n    name = \"terraform\",\n    owner = \"VJftw\",\n    plugin = \"please-terraform\",\n    revision = \"v0.0.1\",\n)\n```\n\n### Please Remote Files\n\n```python\n# //third_party/defs/BUILD\nTERRAFORM_DEF_VERSION=\"\u003cversion\u003e\"\nTERRAFORM_TOOL=\"//third_party/defs:terraform_tool\"\nTERRAFORM_DEFAULT_TOOLCHAIN=\"//third_party/terraform:1.0\"\n\nremote_file(\n    name = \"_terraform#download\",\n    url = f\"https://raw.githubusercontent.com/VJftw/please-terraform/{TERRAFORM_DEF_VERSION}/build/defs/terraform.build_defs\",\n    hashes = [\"95289dba7ae82131a7bb69976b5cdbedb4e7563c889a5b0d10da01d643be4540\"],\n)\n\nremote_file(\n    name = \"terraform_tool\",\n    url = f\"https://github.com/VJftw/please-terraform/releases/download/{TERRAFORM_DEF_VERSION}/please-terraform\",\n    visibility = [\"PUBLIC\"],\n    binary = True,\n)\n\ngenrule(\n    name = \"terraform\",\n    srcs = [\":_terraform#download\"],\n    outs = [\"terraform_custom.build_defs\"],\n    cmd = [\n        \"mv $SRCS $OUTS\",\n        # Replace CONFIG.TERRAFORM.TOOL with your tool.\n        f\"sed -i 's#CONFIG.TERRAFORM.TOOL#{TERRAFORM_TOOL}#g' $OUTS\",\n        # Replace CONFIG.TERRAFORM.DEFAULT_TOOLCHAIN with your tool.\n        f\"sed -i 's#CONFIG.TERRAFORM.DEFAULT_TOOLCHAIN#{TERRAFORM_DEFAULT_TOOLCHAIN}#g' $OUTS\",\n    ],\n    visibility = [\"PUBLIC\"],\n)\n```\n\n\n## Future Work\n\n* `terraform_module`:\n    * Support uploading these Terraform Modules to the Terraform Registry for promotion-based configuration.\n\n* `terraform_root`:\n    * Add optional additional rules for linting:\n        * `terraform fmt -check`\n        * `terraform init -lock=false \u0026\u0026 terraform validate`\n\n\n### Future Work - Examples\n\n- Extending with [Terratest](https://terratest.gruntwork.io/).\n- Extending with [OPA](https://www.openpolicyagent.org/docs/latest/terraform/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjftw%2Fplease-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvjftw%2Fplease-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjftw%2Fplease-terraform/lists"}