1
+ # yaml-language-server: $schema=https://taskfile.dev/schema.json
2
+ version : " 3"
3
+
4
+ vars :
5
+ IS_MODULE :
6
+ # The pattern of terraform module name is terraform-cloudavenue-<nameofmodule>.
7
+ # Detect if it's a module with the presence of the terraform-cloudavenue- keyword in the last part of the path
8
+ sh : |
9
+ if [[ $IS_MODULE == "" ]]; then
10
+ awk -F/ '{print $NF}' <<< $(pwd) | grep -q "terraform-cloudavenue-" && echo "true" || echo "false"
11
+ else
12
+ echo $IS_MODULE
13
+ fi
14
+
15
+ includes :
16
+ internal : internal.yml
17
+
18
+ tasks :
19
+ # * Init
20
+ init :
21
+ desc : Initialize the terraform
22
+ silent : true
23
+ internal : true
24
+ cmds :
25
+ - defer : " echo ✅ Terraform are initialized"
26
+ - cmd : terraform init
27
+ - cmd : tflint --init
28
+
29
+ # * Install
30
+ install :
31
+ desc : Install required tools
32
+ cmds :
33
+ - for : [
34
+ hashicorp/tap,
35
+ ]
36
+ task : internal:tools:brew:tap
37
+ vars :
38
+ APP : ' {{.ITEM}}'
39
+ - for : [
40
+ hashicorp/tap/terraform,
41
+ tflint,
42
+ ]
43
+ task : internal:tools:brew
44
+ vars :
45
+ APP : ' {{.ITEM}}'
46
+ - task : install:module
47
+
48
+ install:module :
49
+ desc : Install terraform module
50
+ internal : true
51
+ cmds :
52
+ - for : [
53
+ terraform-docs,
54
+ ]
55
+ task : internal:tools:brew:optional
56
+ vars :
57
+ APP : ' {{.ITEM}}'
58
+ INSTALL_REQUIRED : ' {{.IS_MODULE}}'
59
+
60
+ # * Lint
61
+ lint :
62
+ desc : Run terraform linters
63
+ cmds :
64
+ - for : [
65
+ tf:fmt,
66
+ tf:validate,
67
+ tflint,
68
+ ]
69
+ task : lint:{{.ITEM}}
70
+
71
+ # * Lint with terraform client
72
+ lint:tf:fmt :
73
+ desc : Run terraform fmt
74
+ internal : true
75
+ preconditions :
76
+ - sh : command -v terraform
77
+ msg : " terraform is not installed. Please run `task install`"
78
+ cmds :
79
+ - terraform fmt
80
+
81
+ lint:tf:fmt-specific-dir :
82
+ desc : Run terraform fmt on a specific directory
83
+ internal : true
84
+ preconditions :
85
+ - sh : command -v terraform
86
+ msg : " terraform is not installed. Please run `task install`"
87
+ cmds :
88
+ - find {{.DIRECTORY}} -name "*.tf" -exec terraform fmt {} \;
89
+
90
+ lint:tf:validate :
91
+ desc : Run terraform validate
92
+ internal : true
93
+ preconditions :
94
+ - sh : command -v terraform
95
+ msg : " terraform is not installed. Please run `task install`"
96
+ cmds :
97
+ - terraform validate
98
+
99
+ # * Lint with tflint
100
+ lint:tflint :
101
+ desc : Run tflint
102
+ internal : true
103
+ preconditions :
104
+ - sh : command -v tflint
105
+ msg : " tflint is not installed. Please run `task install`"
106
+ - sh : test -f .tflint.hcl
107
+ msg : " No .tflint.hcl file found."
108
+ cmds :
109
+ - tflint
110
+
111
+ # * Actions
112
+ actions:docs :
113
+ desc : Generate terraform docs
114
+ cmds :
115
+ - terraform-docs markdown . > README.md
0 commit comments