-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddons.sh
More file actions
executable file
·137 lines (129 loc) · 6.1 KB
/
Copy pathaddons.sh
File metadata and controls
executable file
·137 lines (129 loc) · 6.1 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
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
#!/usr/bin/env bash
export ROOT_DIR="$(
cd -- "$(dirname "${0}")" >/dev/null 2>&1
pwd -P
)"
source ${ROOT_DIR}/variables.sh
export ACTION=${1}
if [[ ${ACTION} = "deploy_load-balancer-controller" ]]; then
source ${ROOT_DIR}/k8s_auth.sh refresh
cd "${ROOT_DIR}/../addons/aws/load-balancer-controller"
export AWS_K8S_CLUSTERS=$(echo ${TFVARS} | jq -c ".k8s_clusters.aws")
export AWS_K8S_CLUSTERS_COUNT=$(echo ${AWS_K8S_CLUSTERS} | jq length)
for i in $(seq 1 ${AWS_K8S_CLUSTERS_COUNT}); do
index=$(($i - 1))
cluster_name=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].name')
region=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].region')
k8s_version=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].version')
if [[ "$cluster_name" == "null" ]]; then
cluster_name=$NAME_PREFIX-$index-$region
fi
terraform workspace new aws-$index-$region || true
terraform workspace select aws-$index-$region
terraform init
terraform apply ${TERRAFORM_APPLY_ARGS} -var-file="../../../terraform.tfvars.json" \
-var=cluster_id=$index -var=region=$region
terraform output ${TERRAFORM_OUTPUT_ARGS} | jq . >../../../outputs/terraform_outputs/terraform-aws-load-balancer-controller-$index-$cluster_name.json
terraform workspace select default
done
cd "../../.."
fi
if [[ ${ACTION} = "destroy_load-balancer-controller" ]]; then
source ${ROOT_DIR}/k8s_auth.sh refresh
cd "${ROOT_DIR}/../addons/aws/load-balancer-controller"
export AWS_K8S_CLUSTERS=$(echo ${TFVARS} | jq -c ".k8s_clusters.aws")
export AWS_K8S_CLUSTERS_COUNT=$(echo ${AWS_K8S_CLUSTERS} | jq length)
for i in $(seq 1 ${AWS_K8S_CLUSTERS_COUNT}); do
index=$(($i - 1))
cluster_name=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].name')
region=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].region')
k8s_version=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].version')
if [[ "$cluster_name" == "null" ]]; then
cluster_name=$NAME_PREFIX-$index-$region
fi
terraform workspace new aws-$index-$region || true
terraform workspace select aws-$index-$region
terraform init
terraform destroy ${TERRAFORM_APPLY_ARGS} -var-file="../../../terraform.tfvars.json" \
-var=cluster_id=$index -var=region=$region
terraform workspace select default
done
cd "../../.."
fi
if [[ ${ACTION} = "deploy_route53-controller" ]]; then
source ${ROOT_DIR}/k8s_auth.sh refresh
cd "${ROOT_DIR}/../addons/aws/route53-controller"
export AWS_K8S_CLUSTERS=$(echo ${TFVARS} | jq -c ".k8s_clusters.aws")
export AWS_K8S_CLUSTERS_COUNT=$(echo ${AWS_K8S_CLUSTERS} | jq length)
for i in $(seq 1 ${AWS_K8S_CLUSTERS_COUNT}); do
index=$(($i - 1))
cluster_name=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].name')
region=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].region')
k8s_version=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].version')
external_dns_zone=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].external_dns_zone')
if [[ "$cluster_name" == "null" ]]; then
cluster_name=$NAME_PREFIX-$index-$region
fi
if [[ "$external_dns_zone" != "null" ]]; then
terraform workspace new aws-$index-$region || true
terraform workspace select aws-$index-$region
terraform init
terraform apply ${TERRAFORM_APPLY_ARGS} -var-file="../../../terraform.tfvars.json" \
-var=cluster_id=$index -var=region=$region -var=external_dns_aws_dns_zone=$external_dns_zone
terraform output ${TERRAFORM_OUTPUT_ARGS} | jq . >../../../outputs/terraform_outputs/terraform-aws-route53-controller-$index-$cluster_name.json
terraform workspace select default
fi
done
cd "../../.."
fi
if [[ ${ACTION} = "destroy_route53-controller" ]]; then
source ${ROOT_DIR}/k8s_auth.sh refresh
cd "${ROOT_DIR}/../addons/aws/route53-controller"
export AWS_K8S_CLUSTERS=$(echo ${TFVARS} | jq -c ".k8s_clusters.aws")
export AWS_K8S_CLUSTERS_COUNT=$(echo ${AWS_K8S_CLUSTERS} | jq length)
for i in $(seq 1 ${AWS_K8S_CLUSTERS_COUNT}); do
index=$(($i - 1))
cluster_name=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].name')
region=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].region')
k8s_version=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].version')
external_dns_zone=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].external_dns_zone')
if [[ "$cluster_name" == "null" ]]; then
cluster_name=$NAME_PREFIX-$index-$region
fi
if [[ "$external_dns_zone" != "null" ]]; then
terraform workspace new aws-$index-$region || true
terraform workspace select aws-$index-$region
terraform init
terraform destroy ${TERRAFORM_APPLY_ARGS} -var-file="../../../terraform.tfvars.json" \
-var=cluster_id=$index -var=region=$region -var=external_dns_aws_dns_zone=$external_dns_zone -target=module.route53-controller.aws_iam_policy.policy_service_account \
-target=module.route53-controller.aws_iam_role.role_service_account -target=module.route53-controller.aws_iam_role_policy_attachment.policy_attachment_service_account \
-target=module.route53-controller.kubernetes_service_account.service_account -target=module.route53-controller.local_file.aws_cleanup \
-target=module.route53-controller.null_resource.aws_cleanup
terraform workspace select default
fi
done
cd "../../.."
fi
if [[ ${ACTION} = "deploy_fluxcd" ]]; then
source ${ROOT_DIR}/k8s_auth.sh refresh
cd "${ROOT_DIR}/../addons/fluxcd"
export AWS_K8S_CLUSTERS=$(echo ${TFVARS} | jq -c ".k8s_clusters.aws")
export AWS_K8S_CLUSTERS_COUNT=$(echo ${AWS_K8S_CLUSTERS} | jq length)
for i in $(seq 1 ${AWS_K8S_CLUSTERS_COUNT}); do
index=$(($i - 1))
cluster_name=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].name')
region=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].region')
k8s_version=$(echo $AWS_K8S_CLUSTERS | jq -cr '.['$index'].version')
if [[ "$cluster_name" == "null" ]]; then
cluster_name=$NAME_PREFIX-$index-$region
fi
terraform workspace new aws-$index-$region || true
terraform workspace select aws-$index-$region
terraform init
terraform apply ${TERRAFORM_APPLY_ARGS} -var-file="../../terraform.tfvars.json" \
-var=cluster_id=$index -var=region=$region
terraform output ${TERRAFORM_OUTPUT_ARGS} | jq . >../../outputs/terraform_outputs/terraform-fluxcd-$index-$cluster_name.json
terraform workspace select default
done
cd "../.."
fi