Skip to content

Commit f5c306d

Browse files
authored
Merge pull request #7 from cytopia/release-0.4
Release 0.4
2 parents 6100363 + 61777fb commit f5c306d

File tree

2 files changed

+113
-19
lines changed

2 files changed

+113
-19
lines changed

README.md

+112-18
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ View **[Dockerfile](https://github.com/cytopia/docker-terragrunt-fmt/blob/master
4040
[![Docker hub](http://dockeri.co/image/cytopia/terragrunt-fmt?&kill_cache=1)](https://hub.docker.com/r/cytopia/terragrunt-fmt)
4141

4242
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.
4345
The image is built nightly against multiple stable versions and pushed to Dockerhub.
4446

4547
<sub>[1] Official project: https://github.com/hashicorp/terraform</sub>
@@ -98,56 +100,148 @@ Options:
98100

99101
## Examples
100102

101-
#### List filenames that need to be fixed
103+
### List filenames that need to be fixed
102104
```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
104110
```
105111
106-
#### Show diff of files that need to be fixed
112+
### Show diff of files that need to be fixed
107113
```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+
}
109133
```
110134
111-
#### Fix files
135+
### Fix files
112136
```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
114142
```
115143
116-
#### Fix files and show diff
144+
### Fix files and show diff
117145
```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+
}
119165
```
120166
121-
#### List filenames that need to be fixed recursively
167+
### List filenames that need to be fixed recursively
122168
```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
124176
```
125177
126-
#### Show diff of files that need to be fixed recursively
178+
### Show diff of files that need to be fixed recursively
127179
```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+
}
129201
```
130202
131-
#### Fix recursively
203+
### Fix recursively
132204
```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
134212
```
135213
136-
#### Ignore files and directories
214+
### Ignore files and directories
137215
138216
Ignore all files named `terragrunt.hcl`.
139217
```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
141223
```
142224
143225
Ignore all directories named `dev/` and everything inside.
144226
```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
146234
```
147235
148236
Ignore all directories named `dev/` and `testing/` and everything inside.
149237
```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
151245
```
152246
153247

data/terragrunt-fmt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ else
256256

257257
# evaluate ignore paths
258258
if [ -n "${ARG_IGNORE}" ]; then
259-
_EXCLUDE=" -not \( -path \"${ARG_PATH}/$( echo "${ARG_IGNORE}" | sed 's/,/*/g' )\" -o -path \"${ARG_PATH}\/}*\" \)"
259+
_EXCLUDE=" -not \( -path \"${ARG_PATH}/$( echo "${ARG_IGNORE}" | sed "s/,/*\" -o -path \"${ARG_PATH}\//g" )*\" \)"
260260
else
261261
_EXCLUDE=""
262262
fi

0 commit comments

Comments
 (0)