{"id":15292472,"url":"https://github.com/antonbabenko/tfvars-annotations","last_synced_at":"2025-10-30T05:09:08.542Z","repository":{"id":57575582,"uuid":"183084064","full_name":"antonbabenko/tfvars-annotations","owner":"antonbabenko","description":"[not-WIP] Update values in terraform.tfvars using annotations","archived":false,"fork":false,"pushed_at":"2019-11-01T09:49:55.000Z","size":54,"stargazers_count":24,"open_issues_count":1,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-07T04:03:26.209Z","etag":null,"topics":["annotations","dynamic","terraform","terraform-scripts","terraform-variables","tfvars"],"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/antonbabenko.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}},"created_at":"2019-04-23T19:37:33.000Z","updated_at":"2025-05-03T14:21:49.000Z","dependencies_parsed_at":"2022-09-26T19:02:20.508Z","dependency_job_id":null,"html_url":"https://github.com/antonbabenko/tfvars-annotations","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Ftfvars-annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Ftfvars-annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Ftfvars-annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Ftfvars-annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonbabenko","download_url":"https://codeload.github.com/antonbabenko/tfvars-annotations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810271,"owners_count":21807759,"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":["annotations","dynamic","terraform","terraform-scripts","terraform-variables","tfvars"],"created_at":"2024-09-30T16:18:05.483Z","updated_at":"2025-10-30T05:09:03.498Z","avatar_url":"https://github.com/antonbabenko.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Update values in terraform.tfvars using annotations\n\n## This project has become redundant (yay!)\n\n## The same functionality is available natively in Terragrunt since [version 0.19.20](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.19.20) (released 15th of August 2019).\n\n### See [PR #3](https://github.com/antonbabenko/tfvars-annotations/pull/3) for the explanation and some extra unreleased code if you want to continue developing this for Terraform.\n\n---\n\n[Terraform](https://www.terraform.io/) is awesome!\n \nAs of today, Terraform 0.11 and 0.12 support only static (known, fixed, already computed) values in `tfvars` files. There is no way to use Terraform interpolation functions, or data-sources inside `tfvars` files in Terraform to update values.\n\nWhile working on [modules.tf](https://github.com/antonbabenko/modules.tf-lambda) (a tool which converts visual diagrams created with [Cloudcraft.co](https://cloudcraft.co/) into Terraform configurations), I had a need to generate code which would chain invocations of [Terraform AWS modules](https://github.com/terraform-aws-modules) and pass arguments between them without requiring any extra Terraform code as a glue. [Terragrunt](https://github.com/gruntwork-io/terragrunt) is a great fit for this, it allows to reduce amount of Terraform configurations by reusing Terraform modules and providing arguments as values in `tfvars` files.\n\nSome languages I know have concepts like annotations and decorators, so at first I made a [shell script](https://github.com/antonbabenko/modules.tf-lambda/blob/v1.2.0/templates/terragrunt-common-layer/common/scripts/update_dynamic_values_in_tfvars.sh) which replaced values in `tfvars` based on annotations and was called by Terragrunt hooks. `tfvars-annotations` shares the same goal and it has no external dependencies (except `terraform` or `terragrunt`).\n\n\n## Use cases\n\n1. modules.tf and Terragrunt (recommended)\n1. Terraform (not implemented yet)\n1. General example - AMI ID, AWS region\n\n## Features\n\n1. Supported annotations:\n  - [x] terragrunt_output:\n     - `@tfvars:terragrunt_output.vpc.vpc_id`\n     - `@tfvars:terragrunt_output.security-group.this_security_group_id`\n  - [ ] terraform_output\n  - [ ] data-sources generic\n1. Type wrapping:\n  - `to_list`: Wrap original value with `[]` to make it it as a list\n\n## How to use\n\nRun `tfvars-annotations` before `terraform plan, apply, refresh`.\n\nIt will process tfvars file in the current directory and set updated values.\n\nE.g.:\n\n    $ tfvars-annotations examples/project1-terragrunt/eu-west-1/app\n    $ terraform plan\n \n## How to disable processing entirely\n\nPut `@tfvars:disable_annotations` anywhere in the `terraform.tfvars` to not process the file.\n\n## Examples\n\nSee `examples` for some basics.\n\n## To-do\n\n1. Get values from other sources:\n - data sources generic\n - aws_account_id or aws_region data sources\n2. terragrunt_outputs from stacks:\n - in any folder\n - in current region\n3. cache values unless stack is changed/updated\n4. functions (limit(2), to_list)\n5. rewrite in go (invoke like this =\u003e update_dynamic_values_in_tfvars ${get_parent_tfvars_dir()}/${path_relative_to_include()})\n6. make it much faster, less verbose\n7. add dry-run flag\n8. Proposed syntax:\n\n - `@tfvars:terragrunt_output.security-group_5.this_security_group_id.to_list`\n\n - `@tfvars:terragrunt_output.[\"eu-west-1/security-group_5\"].this_security_group_id.to_list`\n\n - `@tfvars:terragrunt_output.[\"global/route53-zones\"].zone_id`\n\n - `@tfvars:terragrunt_data.aws_region.zone_id`\n\n - `@tfvars:terragrunt_data.aws_region[{current=true}].zone_id`\n\n## Bugs\n\n1. Add support for `maps` (and lists of maps). Strange bugs with rendering comments in wrong places.\n\n## Installation\n\nOn OSX, install it with Homebrew (not enough github stars to get it to the official repo):\n\n```\nbrew install -s HomebrewFormula/tfvars-annotations.rb\n```\n\nAlternatively, you can download a [release](https://github.com/antonbabenko/tfvars-annotations/releases) suitable for your platform and unzip it. Make sure the `tfvars-annotations` binary is executable, and you're ready to go.\n\nYou can also install it like this:\n\n```\ngo get github.com/antonbabenko/tfvars-annotations\n```\n\nOr run it from source:\n\n```\ngo run . -debug examples/project1-terragrunt/eu-west-1/app\ngo run . examples/project1-terragrunt/eu-west-1/app\n```\n\n## Release\n\n1. Make GitHub Release: `hub release create v0.0.3`. Then Github Actions will build binaries and attach them to Github release.\n2. Update Homebrew version in `HomebrewFormula/tfvars-annotations.rb`. Install locally - `brew install -s HomebrewFormula/tfvars-annotations.rb`\n\n## Authors\n\nThis project is created and maintained by [Anton Babenko](https://github.com/antonbabenko) with the help from [different contributors](https://github.com/antonbabenko/tfvars-annotations/graphs/contributors).\n\n[![@antonbabenko](https://img.shields.io/twitter/follow/antonbabenko.svg?style=social\u0026label=Follow%20@antonbabenko%20on%20Twitter)](https://twitter.com/antonbabenko)\n\n\n## License\n\nThis work is licensed under MIT License. See LICENSE for full details.\n\nCopyright (c) 2019 Anton Babenko\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonbabenko%2Ftfvars-annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonbabenko%2Ftfvars-annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonbabenko%2Ftfvars-annotations/lists"}