-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskfile-infra.yml
70 lines (61 loc) · 2.21 KB
/
taskfile-infra.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
#
# Used by Jenkins to create the ECR repository
#
version: '3'
vars:
AWS_REGION: "eu-west-2"
CONFIG:
sh: 'aws secretsmanager get-secret-value --secret-id uec-sf-sfrunner/deployment --region {{.AWS_REGION}} --output json | jq -r ".SecretString | fromjson"'
ECR_HOST:
sh: jq -nr '{{.CONFIG}}.ECR_HOST'
REPO_NAME:
sh: jq -nr '{{.CONFIG}}.REPO_NAME'
ECR_REPO: '{{.ECR_HOST}}/{{.REPO_NAME}}'
tasks:
create-plugin-cache-dir:
desc: Create the plugin cache directory
vars:
HOME_DIR:
sh: if [ -n "$GEODESIC_VERSION" ]; then echo "/localhost"; else echo "$JENKINS_AGENT_WORKDIR"; fi
cmds:
- 'mkdir -p {{.HOME_DIR}}/.terraform.d/plugin-cache'
init:
desc: Initialise the terraform root
dir: '{{.ROOT_DIR}}/infrastructure/stacks/ecr'
vars:
TERRAFORM_STATE_STORE:
sh: jq -nr '{{.CONFIG}}.TERRAFORM_STATE_STORE'
TERRAFORM_STATE_LOCK:
sh: jq -nr '{{.CONFIG}}.TERRAFORM_STATE_LOCK'
TERRAFORM_STATE_KEY:
sh: jq -nr '{{.CONFIG}}.TERRAFORM_STATE_KEY'
REPO_NAME:
sh: jq -nr '{{.CONFIG}}.REPO_NAME'
cmds:
- terraform --version
- task: create-plugin-cache-dir
- terraform init -no-color -backend-config="bucket={{.TERRAFORM_STATE_STORE}}" -backend-config="dynamodb_table={{.TERRAFORM_STATE_LOCK}}" -backend-config="encrypt=true" -backend-config="key={{.TERRAFORM_STATE_KEY}}/terraform.state" -backend-config="region={{.AWS_REGION}}" -backend-config="workspace_key_prefix=uec-sf/sfrunner"
plan:
desc: Plan the infrastructure changes
dir: '{{.ROOT_DIR}}/infrastructure/stacks/ecr'
vars:
REPO_NAME:
sh: jq -nr '{{.CONFIG}}.REPO_NAME'
env:
TF_VAR_aws_region: '{{.AWS_REGION}}'
TF_VAR_repo_name: '{{.REPO_NAME}}'
cmds:
- echo "TF_VAR_repo_name=$TF_VAR_repo_name"
- terraform plan -out=tfplan -no-color
apply:
desc: Apply the infrastructure changes
dir: '{{.ROOT_DIR}}/infrastructure/stacks/ecr'
vars:
REPO_NAME:
sh: jq -nr '{{.CONFIG}}.REPO_NAME'
env:
TF_VAR_aws_region: '{{.AWS_REGION}}'
TF_VAR_repo_name: '{{.REPO_NAME}}'
cmds:
- echo "TF_VAR_repo_name=$TF_VAR_repo_name"
- terraform apply "tfplan" -no-color