Skip to content

Commit 4f5acaf

Browse files
Nicholas M. IodiceTechnicallyWilliams
andauthored
Adding TF bootstrap for Gitlab and corresponding CICD templates (#409)
* Adding TF bootstrap for Gitlab and corresponding CICD templates * Remove reference to old project * Addressing PR feedback by @TechnicallyWilliams * Apply suggestions from code review Incorporating PR feedback from @TechnicallyWilliams Co-authored-by: Dexter Williams <[email protected]> * PR Feedback Co-authored-by: Dexter Williams <[email protected]>
1 parent df6eaf8 commit 4f5acaf

31 files changed

+1010
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
az login --service-principal -u "$ARM_CLIENT_ID" -p "$ARM_CLIENT_SECRET" --tenant "$ARM_TENANT_ID"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file contains the variables and jobs for the dev stage
2+
3+
.dev-vars: &dev-vars
4+
ARM_CLIENT_ID: $DEV_ARM_CLIENT_ID
5+
ARM_CLIENT_SECRET: $DEV_ARM_CLIENT_SECRET
6+
AZURE_STORAGE_ACCOUNT_NAME: $DEV_AZURE_STORAGE_ACCOUNT_NAME
7+
AZURE_STORAGE_ACCOUNT_CONTAINER: $DEV_AZURE_STORAGE_ACCOUNT_CONTAINER
8+
AZURE_STORAGE_ACCOUNT_SUBSCRIPTION: $DEV_AZURE_STORAGE_ACCOUNT_SUBSCRIPTION
9+
VAR_FILE_NAME: 'DEV_TF_VARS'
10+
ENVIRONMENT: 'dev'
11+
12+
DevBuild:
13+
extends: .build
14+
stage: Dev-Build
15+
variables:
16+
<<: *dev-vars
17+
only:
18+
- master
19+
- merge_requests
20+
- web
21+
22+
DevRelease:
23+
extends: .release
24+
stage: Dev-Release
25+
variables:
26+
<<: *dev-vars
27+
needs:
28+
- job: DevBuild
29+
artifacts: true
30+
when: on_success
31+
only:
32+
- master
33+
- merge_requests
34+
- web
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file contains the variables and jobs for the integration stage
2+
3+
.integration-vars: &integration-vars
4+
ARM_CLIENT_ID: $INTEGRATION_ARM_CLIENT_ID
5+
ARM_CLIENT_SECRET: $INTEGRATION_ARM_CLIENT_SECRET
6+
AZURE_STORAGE_ACCOUNT_NAME: $INTEGRATION_AZURE_STORAGE_ACCOUNT_NAME
7+
AZURE_STORAGE_ACCOUNT_CONTAINER: $INTEGRATION_AZURE_STORAGE_ACCOUNT_CONTAINER
8+
AZURE_STORAGE_ACCOUNT_SUBSCRIPTION: $INTEGRATION_AZURE_STORAGE_ACCOUNT_SUBSCRIPTION
9+
VAR_FILE_NAME: 'INTEGRATION_TF_VARS'
10+
ENVIRONMENT: 'integration'
11+
12+
IntegrationBuild:
13+
extends: .build
14+
stage: Integration-Build
15+
variables:
16+
<<: *integration-vars
17+
only:
18+
- master
19+
needs:
20+
- job: DevRelease
21+
artifacts: false
22+
23+
IntegrationRelease:
24+
extends: .release
25+
stage: Integration-Release
26+
variables:
27+
<<: *integration-vars
28+
needs:
29+
- job: IntegrationBuild
30+
artifacts: true
31+
when: manual
32+
allow_failure: false
33+
only:
34+
- master
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file contains all of the checks that need to happen
2+
# before a build and release.
3+
4+
# Cache dependent modules + proviers and upload an artifact. We need to
5+
# make sure that the backend configuration is not configured, since it will
6+
# need to be done for each stage. The configuration per stage may differ, so
7+
# it makes sense to defer the initialization.
8+
InitTF:
9+
stage: Init
10+
script: .ci/tf-init-without-backend.sh
11+
artifacts:
12+
paths:
13+
- .terraform/
14+
only:
15+
- master
16+
- merge_requests
17+
18+
# Lint check terraform files
19+
LintTF:
20+
stage: Pre-Build
21+
script: .ci/tf-lint.sh
22+
only:
23+
- master
24+
- merge_requests
25+
26+
# Validate terraform configuration
27+
ValidateTF:
28+
stage: Pre-Build
29+
script: .ci/tf-validate.sh
30+
needs:
31+
- job: InitTF
32+
artifacts: true
33+
only:
34+
- master
35+
- merge_requests
36+
37+
# Lint check go files
38+
lintGo:
39+
stage: Pre-Build
40+
script: .ci/go-lint.sh
41+
only:
42+
- master
43+
- merge_requests
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file contains the variables and jobs for the prod stage
2+
3+
.prod-vars: &prod-vars
4+
ARM_CLIENT_ID: $PROD_ARM_CLIENT_ID
5+
ARM_CLIENT_SECRET: $PROD_ARM_CLIENT_SECRET
6+
AZURE_STORAGE_ACCOUNT_NAME: $PROD_AZURE_STORAGE_ACCOUNT_NAME
7+
AZURE_STORAGE_ACCOUNT_CONTAINER: $PROD_AZURE_STORAGE_ACCOUNT_CONTAINER
8+
AZURE_STORAGE_ACCOUNT_SUBSCRIPTION: $PROD_AZURE_STORAGE_ACCOUNT_SUBSCRIPTION
9+
VAR_FILE_NAME: 'PROD_TF_VARS'
10+
ENVIRONMENT: 'prod'
11+
12+
ProdBuild:
13+
extends: .build
14+
stage: Prod-Build
15+
variables:
16+
<<: *prod-vars
17+
only:
18+
- master
19+
needs:
20+
- job: IntegrationRelease
21+
artifacts: false
22+
23+
ProdRelease:
24+
extends: .release
25+
stage: Prod-Release
26+
variables:
27+
<<: *prod-vars
28+
needs:
29+
- job: ProdBuild
30+
artifacts: true
31+
when: manual
32+
allow_failure: false
33+
only:
34+
- master
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file contains jobs that can be extended by stage-specific
2+
# build and release steps
3+
4+
# Generic terraform build job
5+
.build:
6+
environment:
7+
name: $ENVIRONMENT
8+
artifacts:
9+
paths:
10+
- .terraform/
11+
- "$PLAN_FILE"
12+
script:
13+
- .ci/az-login.sh
14+
- .ci/tf-init-for-stage.sh
15+
- .ci/tf-workspace-select.sh
16+
- .ci/tf-plan.sh
17+
18+
# Generic terraform release job
19+
.release:
20+
environment:
21+
name: $ENVIRONMENT
22+
allow_failure: false
23+
script:
24+
- .ci/az-login.sh
25+
- .ci/tf-init-for-stage.sh
26+
- .ci/tf-workspace-select.sh
27+
- .ci/tf-apply.sh
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Note: the omission of the `pipefail` flag is intentional. It allows this
4+
# step to succeede in the case that there are no `*.go` files in the
5+
# infrastructure repository.
6+
set -euox
7+
8+
echo "Linting Go Files... If this fails, run 'go fmt ./...' to fix"
9+
10+
# This runs a go fmt on each file without using the 'go fmt ./...' syntax.
11+
# This is advantageous because it avoids having to download all of the go
12+
# dependencies that would have been triggered by using the './...' syntax.
13+
FILES_WITH_FMT_ISSUES=$(find . -name "*.go" | grep -v '.terraform' | xargs gofmt -l | wc -l)
14+
15+
# convert to integer...
16+
FILES_WITH_FMT_ISSUES=$(($FILES_WITH_FMT_ISSUES + 0))
17+
18+
# set exit code accordingly
19+
exit $FILES_WITH_FMT_ISSUES
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
terraform apply -input=false -auto-approve $PLAN_FILE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# #!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
terraform init -backend-config "storage_account_name=$AZURE_STORAGE_ACCOUNT_NAME" -backend-config "container_name=$AZURE_STORAGE_ACCOUNT_CONTAINER"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
terraform init -backend=false

0 commit comments

Comments
 (0)