Skip to content

Commit 1eb8225

Browse files
committed
Added terraform example
1 parent 92b78b3 commit 1eb8225

File tree

9 files changed

+38
-2
lines changed

9 files changed

+38
-2
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tfvars-annotations - Update values in terraform.tfvars using annotations
1+
# Update values in terraform.tfvars using annotations
22

33
### This is still WIP, full of bugs, missing core features and docs.
44

@@ -8,7 +8,7 @@ As of today, Terraform 0.11 and 0.12 support only static (known, fixed, already
88

99
While 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.
1010

11-
Some 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.
11+
Some 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`).
1212

1313

1414
## Use cases
@@ -24,6 +24,17 @@ Some languages I know have concepts like annotations and decorators, so at first
2424
- [ ] terraform_output
2525
- [ ] data-sources generic
2626

27+
## How to use
28+
29+
Run `tfvars-annotations` before `terraform plan, apply, refresh`.
30+
31+
It will process tfvars file in the current directory and set updated values.
32+
33+
E.g.:
34+
35+
$ tfvars-annotations update
36+
$ terraform plan
37+
2738
## How to disable processing entirely
2839

2940
Put `@modulestf:disable_values_updates` anywhere in the `terraform.tfvars` to not process the file.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @ modulestf:disable_values_updates
2+
3+
vpc_id = "vpc-443a8116aae25c7e9" # @modulestf:terraform_output.vpc.vpc_id
4+
5+
public_subnets = ["subnet-297e8b509d8aeebfe","subnet-3f831847e5802071c","subnet-6c6f959a9063d32b2"] # @modulestf:terraform_output.vpc.public_subnets
6+
7+
something = "" # @modulestf:terraform_output.something.id
8+
9+
vpc4_id = "vpc-443a8116aae25c7e9" # @modulestf:terraform_output.vpc.vpc_id
10+
11+
the end!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"sensitive": false,
3+
"type": "list",
4+
"value": [
5+
"subnet-297e8b509d8aeebfe",
6+
"subnet-3f831847e5802071c",
7+
"subnet-6c6f959a9063d32b2"
8+
]
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sensitive": false,
3+
"type": "string",
4+
"value": "vpc-443a8116aae25c7e9"
5+
}

0 commit comments

Comments
 (0)