-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.cue
180 lines (151 loc) · 4.04 KB
/
project.cue
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
// project cuefile for Dagger CI and other development tooling related to this project.
package main
import "dagger.io/dagger"
import "universe.dagger.io/bash"
import "universe.dagger.io/docker"
// Convenience cuelang build for formatting, etc.
#CueBuild: {
// client filesystem
filesystem: dagger.#FS
// output from the build
output: _cue_build.output
// cuelang pre-build
_cue_pre_build: docker.#Build & {
steps: [
docker.#Pull & {
source: "golang:latest"
},
docker.#Run & {
command: {
name: "mkdir"
args: ["/workdir"]
}
},
docker.#Run & {
command: {
name: "go"
args: ["install", "cuelang.org/go/cmd/cue@latest"]
}
},
]
}
// cue build for actions in this plan
_cue_build: docker.#Build & {
steps: [
docker.#Copy & {
input: _cue_pre_build.output
contents: filesystem
source: "./project.cue"
dest: "/workdir/project.cue"
},
]
}
}
#TFLintBuild: {
// client filesystem
filesystem: dagger.#FS
// output from the build
output: _tf_build.output
// tf build
_tf_build: docker.#Build & {
steps: [
docker.#Pull & {
source: "ghcr.io/antonbabenko/pre-commit-terraform:v1.88.4"
},
docker.#Set & {
config: {
workdir: "/lint"
}
},
docker.#Copy & {
contents: filesystem
source: "./"
dest: "/workdir"
},
bash.#Run & {
script: contents: """
# cd into the workdir
cd /workdir
# remove already existing test content
rm -rf ./tests/lab-initiative-bucket
# install poetry and env
python3 -m pip install --no-cache-dir --upgrade poetry
poetry install --no-interaction --no-ansi
# run cookiecutter to create project from template
poetry run cookiecutter . --no-input --output-dir tests
# move project from template into lintable dir for container
cp -ra /workdir/tests/lab-initiative-bucket/. /lint
# reinit git for the cookiecutter project
rm -rf /lint/.git
cd /lint
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git init
git add .
git commit -m "example message"
"""
},
]
}
}
dagger.#Plan & {
client: {
filesystem: {
"./": read: contents: dagger.#FS
"./project.cue": write: contents: actions.format.cue.export.files."/workdir/project.cue"
}
}
actions: {
// an internal cue build for formatting/cleanliness
_cue_build: #CueBuild & {
filesystem: client.filesystem."./".read.contents
}
// an internal terraform build for use with this repo
_tf_lint_build: #TFLintBuild & {
filesystem: client.filesystem."./".read.contents
}
// applied code and/or file formatting
format: {
// code formatting for cuelang
cue: docker.#Run & {
input: _cue_build.output
workdir: "/workdir"
command: {
name: "cue"
args: ["fmt", "/workdir/project.cue"]
}
export: {
files: "/workdir/project.cue": _
}
}
}
test: {
// run pre-commit checks
test_pre_commit: bash.#Run & {
input: _tf_lint_build.output
script: contents: """
pre-commit run -a
"""
}
// run pre-commit checks
test_tfvars: bash.#Run & {
input: _tf_lint_build.output
script: contents: """
# change dir to where the cookiecutter created project lives
# to simulate the use of the directory after it's been used
cd /lint
# set terraform to use mock credentials for testing
export GOOGLE_APPLICATION_CREDENTIALS=/workdir/tests/data/gcp-mock-credentials.json
# initialize terraform for plan
terraform -chdir=terraform/state-management init
# run plan without explicit input from cli
# note: we expect variables to be inherited from terraform.tfvars or similar
# this command will fail when unable to read a related tfvars file
# see the following for more info:
# https://developer.hashicorp.com/terraform/language/values/variables#variable-definition-precedence
terraform -chdir=terraform/state-management plan -input=false
"""
}
}
}
}