-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
52 lines (40 loc) · 1.8 KB
/
Makefile
File metadata and controls
52 lines (40 loc) · 1.8 KB
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
ENV ?= staging
apply: apply-remote-state apply-secrets apply-env apply-k8s-utils
## remove state file only if exit code 0 from terraform apply
apply-remote-state:
pushd terraform/bootstrap/remote-state && \
terraform init && \
terraform apply -var "environment=$(ENV)" && \
rm ./terraform.tfstate
apply-secrets:
pushd terraform/bootstrap/secrets && \
terraform init && \
terraform apply && \
rm ./terraform.tfstate
apply-env:
pushd terraform/environments/$(ENV); \
terraform init && \
terraform apply
apply-k8s-utils: update-k8s-conf
pushd kubernetes/terraform/environments/$(ENV) && \
terraform init && \
terraform apply
update-k8s-conf:
aws eks --region <% index .Params `region` %> update-kubeconfig --name <% .Name %>-$(ENV)-<% index .Params `region` %>
teardown: teardown-k8s-utils teardown-env teardown-secrets teardown-remote-state
teardown-remote-state:
export AWS_PAGER='' && \
aws s3 rb s3://<% .Name %>-$(ENV)-terraform-state --force && \
aws dynamodb delete-table --table-name <% .Name %>-$(ENV)-terraform-state-locks
teardown-secrets:
export AWS_PAGER='' && \
aws secretsmanager list-secrets --query "SecretList[?Tags[?Key=='project' && Value=='<% .Name %>']].[Name] | [0][0]" | xargs aws secretsmanager delete-secret --secret-id && \
aws iam delete-access-key --user-name <% .Name %>-ci-user --access-key-id $(shell aws iam list-access-keys --user-name <% .Name %>-ci-user --query "AccessKeyMetadata[0].AccessKeyId" | sed 's/"//g') && \
aws iam delete-user --user-name <% .Name %>-ci-user
teardown-env:
pushd terraform/environments/$(ENV) && \
terraform destroy
teardown-k8s-utils:
pushd kubernetes/terraform/environments/$(ENV) && \
terraform destroy
.PHONY: apply apply-remote-state apply-secrets apply-env apply-k8s-utils teardown-k8s-utils teardown-env teardown-secrets teardown-remote-state