Skip to content

Commit e29a760

Browse files
committed
Rewritting step-by-step
1 parent 4c0e236 commit e29a760

File tree

7 files changed

+444
-173
lines changed

7 files changed

+444
-173
lines changed

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ Some languages I know have concepts like annotations and decorators, so at first
2020
## Features
2121

2222
1. Supported annotations:
23-
- [x] terragrunt_output
23+
- [x] terragrunt_output:
24+
- `@tfvars:terragrunt_output.vpc.vpc_id`
25+
- `@tfvars:terragrunt_output.security-group.this_security_group_id`
2426
- [ ] terraform_output
2527
- [ ] data-sources generic
28+
1. Type wrapping:
29+
- `to_list`: Wrap original value with `[]` to make it it as a list
2630

2731
## How to use
2832

@@ -32,12 +36,12 @@ It will process tfvars file in the current directory and set updated values.
3236

3337
E.g.:
3438

35-
$ tfvars-annotations update
39+
$ tfvars-annotations examples/project1-terragrunt/eu-west-1/app
3640
$ terraform plan
3741

3842
## How to disable processing entirely
3943

40-
Put `@modulestf:disable_values_updates` anywhere in the `terraform.tfvars` to not process the file.
44+
Put `@tfvars:disable_annotations` anywhere in the `terraform.tfvars` to not process the file.
4145

4246
## Examples
4347

@@ -55,26 +59,36 @@ See `examples` for some basics.
5559
4. functions (limit(2), to_list)
5660
5. rewrite in go (invoke like this => update_dynamic_values_in_tfvars ${get_parent_tfvars_dir()}/${path_relative_to_include()})
5761
6. make it much faster, less verbose
58-
7. Proposed syntax:
62+
7. add dry-run flag
63+
8. Proposed syntax:
5964

60-
- `@tfvars:terragrunt_output`
61-
62-
- `@modulestf:terragrunt_output.security-group_5.this_security_group_id.to_list`
65+
- `@tfvars:terragrunt_output.security-group_5.this_security_group_id.to_list`
6366

64-
- `@modulestf:terragrunt_output.["eu-west-1/security-group_5"].this_security_group_id.to_list`
67+
- `@tfvars:terragrunt_output.["eu-west-1/security-group_5"].this_security_group_id.to_list`
6568

66-
- `@modulestf:terragrunt_output.["global/route53-zones"].zone_id`
69+
- `@tfvars:terragrunt_output.["global/route53-zones"].zone_id`
6770

68-
- `@modulestf:terragrunt_data.aws_region.zone_id`
71+
- `@tfvars:terragrunt_data.aws_region.zone_id`
6972

70-
- `@modulestf:terragrunt_data.aws_region[{current=true}].zone_id`
73+
- `@tfvars:terragrunt_data.aws_region[{current=true}].zone_id`
74+
75+
## Bugs
76+
77+
1. Add support for `maps` (and lists of maps). Strange bugs with rendering comments in wrong places.
7178

7279
## How to install
7380

7481
`go get github.com/antonbabenko/tfvars-annotations`
7582

76-
Or download built releases for your platform [here](https://github.com/antonbabenko/tfvars-annotations/releases)
83+
Or download release for your platform [here](https://github.com/antonbabenko/tfvars-annotations/releases)
84+
85+
```
86+
go run . -debug examples/project1-terragrunt/eu-west-1/app
87+
```
7788

89+
```
90+
go run . examples/project1-terragrunt/eu-west-1/app
91+
```
7892

7993
## Authors
8094

examples/project1-terragrunt/eu-west-1/app/full.tfvars

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ name = "Anton Babenko" # @tfvars:terragrunt_output.core.name
1818

1919
score = "37" # @tfvars:terragrunt_output.core.score
2020

21+
name_as_list = ["Anton Babenko"] # @tfvars:terragrunt_output.core.name.to_list
22+
2123
love_sailing = "true" # @tfvars:terragrunt_output.core.love_sailing
2224

2325
understand_how_to_use_twitter = "false" # @tfvars:terragrunt_output.core.understand_how_to_use_twitter
2426

25-
languages = ["ukrainian", "russian", "english", "norwegian", "spanish"] # @tfvars:terragrunt_output.core.languages
26-
27-
list_of_properties = "" # @tfvars:terragrunt_output.core.list_of_properties
28-
29-
map_of_properties = "" # @tfvars:terragrunt_output.core.map_of_properties
30-
31-
mixed_value = "" # @tfvars:terragrunt_output.core.mixed_value
27+
languages = [
28+
"ukrainian",
29+
"russian",
30+
"english",
31+
"norwegian",
32+
"spanish",
33+
] # @tfvars:terragrunt_output.core.languages
3234

3335
###############
3436
# Compositions
@@ -37,5 +39,14 @@ mixed_value = "" # @tfvars:terragrunt_output.core.mixed_value
3739
custom_map = {
3840
Score = "37" # @tfvars:terragrunt_output.core.score
3941
Name = "Anton Babenko" # @tfvars:terragrunt_output.core.name
40-
MixedValue = "" # @tfvars:terragrunt_output.core.mixed_value
42+
MixedValue = "" # @ tfvars:terragrunt_output.core.mixed_value <-- same reason as below. Maps are tricky.
4143
}
44+
45+
######
46+
# These don't work yet because there are `maps` inside of them.
47+
######
48+
list_of_properties = "" # @ tfvars:terragrunt_output.core.list_of_properties
49+
50+
map_of_properties = "" # @ tfvars:terragrunt_output.core.map_of_properties
51+
52+
mixed_value = "" # @ tfvars:terragrunt_output.core.mixed_value

examples/project1-terragrunt/eu-west-1/app/terraform.tfvars

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ name = "Anton Babenko" # @tfvars:terragrunt_output.core.name
1818

1919
score = "37" # @tfvars:terragrunt_output.core.score
2020

21+
name_as_list = ["Anton Babenko"] # @tfvars:terragrunt_output.core.name.to_list
22+
2123
love_sailing = "true" # @tfvars:terragrunt_output.core.love_sailing
2224

2325
understand_how_to_use_twitter = "false" # @tfvars:terragrunt_output.core.understand_how_to_use_twitter
@@ -30,8 +32,18 @@ languages = [
3032
"spanish",
3133
] # @tfvars:terragrunt_output.core.languages
3234

35+
###############
36+
# Compositions
37+
###############
38+
39+
custom_map = {
40+
Score = "37" # @tfvars:terragrunt_output.core.score
41+
Name = "Anton Babenko" # @tfvars:terragrunt_output.core.name
42+
MixedValue = "" # @ tfvars:terragrunt_output.core.mixed_value <-- same reason as below. Maps are tricky.
43+
}
44+
3345
######
34-
# These don't work because there are "=" in values. Changed annotation
46+
# These don't work yet because there are `maps` inside of them.
3547
######
3648
list_of_properties = "" # @ tfvars:terragrunt_output.core.list_of_properties
3749

go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ module github.com/antonbabenko/tfvars-annotations
33
go 1.12
44

55
require (
6+
github.com/davecgh/go-spew v1.1.1
7+
github.com/hashicorp/hcl v1.0.0
68
github.com/pkg/errors v0.8.1
7-
github.com/vosmith/pancake v0.0.0-20170503023453-935e4f9b30d6
8-
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d // indirect
9-
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
10-
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 // indirect
9+
github.com/rodaine/hclencoder v0.0.0-20190213202847-fb9757bb536e
10+
github.com/sirupsen/logrus v1.4.1
1111
golang.org/x/sys v0.0.0-20190425145619-16072639606e // indirect
12-
golang.org/x/text v0.3.1 // indirect
13-
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc // indirect
1412
)

go.sum

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
4+
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
5+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
6+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
17
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
28
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3-
github.com/vosmith/pancake v0.0.0-20170503023453-935e4f9b30d6 h1:3SzMzlTh7DuJDNn12Aj5jKmQRfXob6DOGjyqJcjKOI4=
4-
github.com/vosmith/pancake v0.0.0-20170503023453-935e4f9b30d6/go.mod h1:gMEF5lHy21yX/Gdo/xix2o2KKjlPs2vsS4/cwNmDd8E=
5-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
6-
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
7-
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
8-
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
9-
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
10-
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
11-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
12-
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
13-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
14-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
15-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/rodaine/hclencoder v0.0.0-20190213202847-fb9757bb536e h1:H9k4BAinsVIlHvkUQxmLq194u5Av7VofhxtPGBOAhAo=
12+
github.com/rodaine/hclencoder v0.0.0-20190213202847-fb9757bb536e/go.mod h1:hkWgI+PWPCjkVbx8rdk7GhVkpbc/zCLrY/9yF5xGSzI=
13+
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
14+
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
15+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
17+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
18+
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
19+
golang.org/x/sys v0.0.0-20190425145619-16072639606e h1:4ktJgTV34+N3qOZUc5fAaG3Pb11qzMm3PkAoTAgUZ2I=
1720
golang.org/x/sys v0.0.0-20190425145619-16072639606e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19-
golang.org/x/text v0.3.1/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
20-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
21-
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
22-
golang.org/x/tools v0.0.0-20190424031103-cb2dda6eabdf h1:Yv3pKbXQqpdhrt53r+Yr1XveoqVgIFTCQdaamSalWwM=
23-
golang.org/x/tools v0.0.0-20190424031103-cb2dda6eabdf/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
24-
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc h1:N3zlSgxkefUH/ecsl37RWTkESTB026kmXzNly8TuZCI=
25-
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

0 commit comments

Comments
 (0)