-
Notifications
You must be signed in to change notification settings - Fork 19
/
Taskfile.yml
235 lines (205 loc) · 8.5 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
version: "3"
includes:
clean: ./tasks/clean.yaml
aws: ./tasks/aws.yaml
gcp: ./tasks/gcp.yaml
tasks:
docker:oneliner:
deps:
- docker-init
- build
- docker
cmds:
- "Loading container..."
docker:init:
desc: Create and cache your Docker container
cmds:
- docker volume rm cache_terraform || true
- docker volume rm repository_results || true
- docker volume create cache_terraform || true
- docker volume create repository_results || true
docker:
desc: Create and cache your Docker container
deps:
- build
cmds:
- docker run -it --rm --name freetf freetf:latest
build:
desc: Create and cache your Docker container
cmds:
- docker build -t ghcr.io/gruberdev/freetf:latest -t docker.io/grubertech/freetf:latest --no-cache .
run:
cmds:
- docker run -v $(pwd):/project -it ghcr.io/gruberdev/freetf:latest /bin/sh
build:all:
desc: Build executable binary with GoReleaser.
cmds:
- goreleaser --snapshot --skip-publish --rm-dist
docs:gen:
preconditions:
- sh: 'which terraform-docs'
msg: 'terraform-docs {{.PATH_ERROR}}'
desc: Build documentation using Terraform-docs and the task command
cmds:
- terraform-docs markdown -c .terraform-docs.yml . --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/aws --output-file README.md --header-from "header.md"
- terraform-docs markdown -c .terraform-docs.yml ./modules/aws/ec2 --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/aws/vpc --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/aws/rds --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/gcp --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/gcp/compute --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/gcp/firewall --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/gcp/vpc --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/azure --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/azure/compute --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/azure/db --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/azure/vpc --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./modules/gcp/storage --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./examples/aws/e2e --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./examples/aws/unit/rds --output-file README.md
- terraform-docs markdown -c .terraform-docs.yml ./examples/aws/unit/ec2 --output-file README.md
docs:
desc: Initialize module and build cache, and remake go.sum file on root directory.
deps:
- stop-docs
cmds:
- cd docs && docker build -t tf-free:docs .
- cd docs && docker-compose up --build -d
docs-deploy:
desc: Initialize module and build cache, and remake go.sum file on root directory.
deps:
- stop-docs
cmds:
- cd docs && docker build -t tf-free:docs .
- cd docs && docker-compose -f build.yml up --build
- cd docs && rm -rf .public || true
- cd docs && mkdir .public
- cp -r docs/build/* docs/.public/
- cp docs/vercel.json docs/.public/
stop-docs:
cmds:
- cd docs && docker-compose down || true
- cd docs && docker-compose -f build.yml down || true
lint:
desc: Linter built on Docker.
cmds:
- go mod verify
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.40.1 golangci-lint run --enable gosec --timeout 3m0s ./...
sources:
- ./go.mod
- "**/*.go"
graph:
desc: Create beautiful Terraform Graphs
cmds:
- go get github.com/pcasteran/terraform-graph-beautifier
- terraform graph | terraform-graph-beautifier --exclude="module.root.provider" --output-type=cyto-html > graph.html
full:test:local:
desc: Terraform testing all providers.
deps:
- gcp-test
- aws-test
- docker-test
cmds:
- echo "Finished testing."
apply:local:
desc: Terraform standard local apply command
cmds:
- terraform init
- terraform apply -auto-approve
destroy:local:
desc: Terraform standard local destroy command
cmds:
- terraform destroy -auto-approve
init:
desc: Terraform standard local init command
cmds:
- terraform init -upgrade
init:apply:
desc: Terraform standard initial apply command (w/ Backend)
cmds:
- terraform init -reconfigure
- terraform apply -auto-approve
- terraform init -force-copy
init:docker:
cmds:
- cd test/docker && rm go.mod || true
- cd test/docker && rm go.sum || true
- cd test/docker && go mod init "github.com/gruberdev/tf-free" && go mod tidy
docker:test:
desc: Terraform standard initialization
deps:
- init-docker
cmds:
- cd test/docker && go test -v -timeout 45m -run TestDockerBuild
lastdestroy:
desc: Terraform standard initialization
cmds:
- terraform apply -var backend_destroy=true -var prevents_destroy=false -target module.terraform_state_backend -auto-approve
- terraform init -force-copy
- terraform destroy -target module.aws.module.rds.aws_db_instance.rds -auto-approve
- terraform destroy -auto-approve
docker:lint:
desc: Terraform standard initialization
cmds:
- docker run --rm -i hadolint/hadolint < Dockerfile || true
backend:enable:
desc: How to transfer the backend to S3 (Remote)
cmds:
- terraform init -force-copy
backend:disable:
desc: How to destroy the backend stored in S3
cmds:
- terraform apply -target module.terraform_state_backend -auto-approve
- terraform init -force-copy
destroy:aws:
desc: Terraform standard initialization
cmds:
- cd modules/aws && terraform destroy -auto-approve
restart-aws:
desc: Terraform standard initialization
cmds:
- cd modules/aws && terraform destroy -auto-approve
- cd modules/aws && terraform apply -auto-approve
heavy:artillery:
desc: Destroy all resources but the S3 Backend and the DynamoDB instances on AWS.
cmds:
- terraform destroy -target module.google_cloud -auto-approve
- terraform destroy -target module.aws -auto-approve
tf:clean:
desc: Terraform standard initialization
cmds:
- rm -rf ./.terraform || true
- rm -rf ./.blast || true
- rm terraform.tfstate || true
- rm terraform.tfstate.backup || true
- rm ./.terraform.lock.hcl || true
- rm backend.tf || true
- rm errored.tfstate || true
- rm graph.html || true
- rm index.html || true
- rm plan.json || true
- rm plan.out || true
- rm gcp.json || true
- cd modules && cd gcp && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd gcp && cd vpc && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd gcp && cd firewall && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd gcp && cd compute && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd aws && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd aws && cd ec2 && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- cd modules && cd aws && cd rds && rm -rf ./.terraform && rm ./.terraform.lock.hcl || true
- rm examples/aws/unit/ec2/.terraform.lock.hcl || true
- rm -rf examples/aws/unit/ec2/.terraform || true
- rm examples/aws/unit/ec2/terraform.tfstate || true
- rm examples/aws/unit/ec2/terraform.tfstate.backup || true
- rm examples/aws/unit/rds/.terraform.lock.hcl || true
- rm -rf examples/aws/unit/rds/.terraform || true
- rm examples/aws/unit/rds/terraform.tfstate || true
- rm examples/aws/unit/rds/terraform.tfstate.backup || true
drone:init:
desc: Terraform standard initialization
cmds:
- apk add build-base git curl
- apk add --no-cache terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
blastradius:
cmds:
- docker run --rm -it -p 5013:5000 -v $(pwd):/data:ro -v $(pwd)/blast:/tmp/results --security-opt apparmor:unconfined --cap-add=SYS_ADMIN blastradius:local