@@ -40,6 +40,8 @@ View **[Dockerfile](https://github.com/cytopia/docker-terragrunt-fmt/blob/master
40
40
[ ![ Docker hub] ( http://dockeri.co/image/cytopia/terragrunt-fmt?&kill_cache=1 )] ( https://hub.docker.com/r/cytopia/terragrunt-fmt )
41
41
42
42
Tiny Alpine-based multistage-build dockerized version of [ Terraform] ( https://github.com/hashicorp/terraform ) <sup >[ 1] </sup > with the ability to do ` terraform fmt ` on Terragrunt files (` .hcl ` ).
43
+ This is achieved by creating a temporary file within the container with an ` .tf ` extension and then running ` terraform fmt ` on it.
44
+ Additionally the wrapper has been extended with a ** ` -ignore ` argument** to be able to ignore files and directory or wildcards.
43
45
The image is built nightly against multiple stable versions and pushed to Dockerhub.
44
46
45
47
<sub >[ 1] Official project: https://github.com/hashicorp/terraform </sub >
@@ -98,56 +100,148 @@ Options:
98
100
99
101
## Examples
100
102
101
- #### List filenames that need to be fixed
103
+ ### List filenames that need to be fixed
102
104
``` bash
103
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -list
105
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -list
106
+
107
+ [INFO] Finding files: for file in * .hcl; do
108
+ terraform fmt -list=true -write=true validate.hcl
109
+ ../tmp/validate.hcl.tf
104
110
` ` `
105
111
106
- #### Show diff of files that need to be fixed
112
+ # ## Show diff of files that need to be fixed
107
113
` ` ` bash
108
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -diff
114
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -diff
115
+
116
+ [INFO] Finding files: for file in * .hcl; do
117
+ terraform fmt -list=true -write=false -diff validate.hcl
118
+ ../tmp/validate.hcl.tf
119
+ --- old/../tmp/validate.hcl.tf
120
+ +++ new/../tmp/validate.hcl.tf
121
+ @@ -35,9 +35,9 @@
122
+ # which is not being used (disable_init)
123
+ remote_state {
124
+ backend = " s3"
125
+ - config = {
126
+ - bucket = " none"
127
+ - key = " none"
128
+ + config = {
129
+ + bucket = " none"
130
+ + key = " none"
131
+ region = " eu-central-1"
132
+ }
109
133
` ` `
110
134
111
- #### Fix files
135
+ # ## Fix files
112
136
` ` ` bash
113
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write
137
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write
138
+
139
+ [INFO] Finding files: for file in * .hcl; do
140
+ terraform fmt -list=true -write=true validate.hcl
141
+ ../tmp/validate.hcl.tf
114
142
` ` `
115
143
116
- #### Fix files and show diff
144
+ # ## Fix files and show diff
117
145
` ` ` bash
118
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write -diff
146
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write -diff
147
+
148
+ [INFO] Finding files: for file in * .hcl; do
149
+ terraform fmt -list=true -write=false -diff validate.hcl
150
+ ../tmp/validate.hcl.tf
151
+ --- old/../tmp/validate.hcl.tf
152
+ +++ new/../tmp/validate.hcl.tf
153
+ @@ -35,9 +35,9 @@
154
+ # which is not being used (disable_init)
155
+ remote_state {
156
+ backend = " s3"
157
+ - config = {
158
+ - bucket = " none"
159
+ - key = " none"
160
+ + config = {
161
+ + bucket = " none"
162
+ + key = " none"
163
+ region = " eu-central-1"
164
+ }
119
165
` ` `
120
166
121
- #### List filenames that need to be fixed recursively
167
+ # ## List filenames that need to be fixed recursively
122
168
` ` ` bash
123
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -list -recursive
169
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -list -recursive
170
+
171
+ [INFO] Finding files: find . -name ' *.hcl' -type f
172
+ terraform fmt -list=true -write=false ./prod/eu-central-1/microservice/terragrunt.hcl
173
+ ../tmp/terragrunt.hcl.tf
174
+ terraform fmt -list=true -write=false ./prod/eu-central-1/infra/terragrunt.hcl
175
+ ../tmp/terragrunt.hcl.tf
124
176
` ` `
125
177
126
- #### Show diff of files that need to be fixed recursively
178
+ # ## Show diff of files that need to be fixed recursively
127
179
` ` ` bash
128
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -diff -recursive
180
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -diff -recursive
181
+
182
+ [INFO] Finding files: find . -name ' *.hcl' -type f
183
+ terraform fmt -list=true -write=false -diff ./prod/eu-central-1/microservice/terragrunt.hcl
184
+ ../tmp/terragrunt.hcl.tf
185
+ --- old/../tmp/terragrunt.hcl.tf
186
+ +++ new/../tmp/terragrunt.hcl.tf
187
+ @@ -1,5 +1,5 @@
188
+ terraform {
189
+ - source = " github.com/cytopia/terraform-aws-iam-cross-account?ref=v0.1.3"
190
+ + source = " github.com/cytopia/terraform-aws-iam-cross-account?ref=v0.1.3"
191
+ }
192
+ terraform fmt -list=true -write=false -diff ./prod/eu-central-1/infra/terragrunt.hcl
193
+ ../tmp/terragrunt.hcl.tf
194
+ --- old/../tmp/terragrunt.hcl.tf
195
+ +++ new/../tmp/terragrunt.hcl.tf
196
+ @@ -1,5 +1,5 @@
197
+ terraform {
198
+ - source = " github.com/cytopia/terraform-aws-iam-cross-account?ref=v0.1.3"
199
+ + source = " github.com/cytopia/terraform-aws-iam-cross-account?ref=v0.1.3"
200
+ }
129
201
` ` `
130
202
131
- #### Fix recursively
203
+ # ## Fix recursively
132
204
` ` ` bash
133
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write -recursive
205
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -write -recursive
206
+
207
+ [INFO] Finding files: find . -name ' *.hcl' -type f
208
+ terraform fmt -list=true -write=true ./prod/eu-central-1/microservice/terragrunt.hcl
209
+ ../tmp/terragrunt.hcl.tf
210
+ terraform fmt -list=true -write=true ./prod/eu-central-1/infra/terragrunt.hcl
211
+ ../tmp/terragrunt.hcl.tf
134
212
` ` `
135
213
136
- #### Ignore files and directories
214
+ # ## Ignore files and directories
137
215
138
216
Ignore all files named ` terragrunt.hcl` .
139
217
` ` ` bash
140
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* terragrunt.hcl
218
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* terragrunt.hcl
219
+
220
+ [INFO] Finding files: find . -not \( -path " ./*terragrunt.hcl*" \) -name ' *.hcl' -type f
221
+ terraform fmt -list=true -write=false ./aws/validate.hcl
222
+ ../tmp/validate.hcl.tf
141
223
` ` `
142
224
143
225
Ignore all directories named ` dev/` and everything inside.
144
226
` ` ` bash
145
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* /dev/
227
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* /dev/
228
+
229
+ [INFO] Finding files: find . -not \( -path " ./*/dev/*" \) -name ' *.hcl' -type f
230
+ terraform fmt -list=true -write=false ./prod/eu-central-1/microservice/terragrunt.hcl
231
+ ../tmp/terragrunt.hcl.tf
232
+ terraform fmt -list=true -write=false ./prod/eu-central-1/infra/terragrunt.hcl
233
+ ../tmp/terragrunt.hcl.tf
146
234
` ` `
147
235
148
236
Ignore all directories named ` dev/` and ` testing/` and everything inside.
149
237
` ` ` bash
150
- docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* /dev/,* /testing/
238
+ $ docker run --rm -v $( pwd) :/data cytopia/terragrunt-fmt -recursive -ignore=* /dev/,* /testing/
239
+
240
+ [INFO] Finding files: find . -not \( -path " ./*/dev/*" -o -path " ./*/testing/*" \) -name ' *.hcl' -type f
241
+ terraform fmt -list=true -write=false ./prod/eu-central-1/microservice/terragrunt.hcl
242
+ ../tmp/terragrunt.hcl.tf
243
+ terraform fmt -list=true -write=false ./prod/eu-central-1/infra/terragrunt.hcl
244
+ ../tmp/terragrunt.hcl.tf
151
245
` ` `
152
246
153
247
0 commit comments