-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
180 lines (177 loc) · 6.29 KB
/
template.yaml
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
# Define common go-template variables for templating
{{- $createVpcCIDR := "10.8.0.0/18" -}}
{{- $region := .variables.region -}}
{{- $azs := list "" -}}
{{- if .variables.azs -}}
{{- $azs = .variables.azs -}}
{{- else -}}
{{- $azs = list (printf "%sa" $region) (printf "%sb" $region) (printf "%sc" $region) -}}
{{- end -}}
{{- $azs_count := len $azs -}}
# Define common used anchors
_p: &provider_aws
- aws:
region: {{ .variables.region }}
# Define template
kind: StackTemplate
name: aws-eks
cliVersion: ">= 0.7.15"
# Define units itself
units:
- name: route53
type: tfmodule
source: github.com/shalb/cluster.dev-domain?ref=v0.1.0
inputs:
region: {{ .variables.region }}
cluster_name: {{ .variables.cluster_name }}
cluster_domain: {{ .variables.domain }}
zone_delegation: {{ if eq .variables.domain "cluster.dev" }}true{{ else }}false{{ end }}
{{- if not .variables.vpc_id }}
-
name: vpc
type: tfmodule
providers: *provider_aws
source: terraform-aws-modules/vpc/aws
version: "5.1.1"
inputs:
name: {{ .variables.environment }}
cidr: {{ $createVpcCIDR }}
enable_nat_gateway: true
single_nat_gateway: true
one_nat_gateway_per_az: false
enable_dns_hostnames: true
enable_dns_support: true
create_egress_only_igw: true
enable_vpn_gateway: true
create_database_subnet_group: true
public_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 $index }}
{{- end }}
private_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 (add $index $azs_count ) }}
{{- end }}
database_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 (add $index $azs_count $azs_count ) }}
{{- end }}
public_subnet_tags:
"kubernetes.io/cluster/{{ .variables.cluster_name }}": "owned"
"kubernetes.io/role/lb": 1
private_subnet_tags:
"kubernetes.io/cluster/{{ .variables.cluster_name }}": "owned"
"kubernetes.io/role/internal-lb": 1
azs: {{ insertYAML $azs }}
{{- end }}
- name: eks
type: tfmodule
pre_hook:
on_apply: false
on_destroy: true
command: echo "waiting 2 minutes for LB deletion" && sleep 120
providers:
- aws:
region: {{ .variables.region }}
create_files:
- file: ./kubernetes_provider.tf
mode: 0644
content: |
{{ readFile "./files/kube_provider.tf" | indent 8 }}
source: "terraform-aws-modules/eks/aws"
version: "19.6.0"
inputs:
cluster_name: {{ .variables.cluster_name }}
cluster_version: {{ .variables.eks_version | quote }}
cluster_endpoint_private_access: true
cluster_endpoint_public_access: true
enable_irsa: true
tags: {{ insertYAML .variables.tags }}
create_aws_auth_configmap: false
manage_aws_auth_configmap: true
cluster_addons:
coredns:
most_recent: true
kube-proxy:
most_recent: true
vpc-cni:
most_recent: true
configuration_values: |
{
"env": {
"ENABLE_PREFIX_DELEGATION": "true",
"WARM_PREFIX_TARGET": "1"
}
}
aws-ebs-csi-driver:
most_recent: true
vpc_id: {{ remoteState "this.vpc.vpc_id" }}
subnet_ids: {{ remoteState "this.vpc.private_subnets" }}
node_security_group_additional_rules:
ingress_istio_tcp:
description: "Access Istio inside nodes."
protocol: "tcp"
from_port: 15017
to_port: 15017
type: "ingress"
source_cluster_security_group: true
{{- if .variables.eks_managed_node_groups }}
eks_managed_node_groups: {{ insertYAML .variables.eks_managed_node_groups }} # https://github.com/terraform-aws-modules/terraform-aws-eks#eks-managed-node-groups
{{- end }}
{{- if .variables.self_managed_node_groups }}
self_managed_node_groups: {{ insertYAML .variables.self_managed_node_groups }} # https://github.com/terraform-aws-modules/terraform-aws-eks#self-managed-node-groups
{{- end }}
{{- if .variables.aws_auth_roles }}
aws_auth_roles: {{ .variables.aws_auth_roles }}
{{- end }}
{{- if .variables.aws_auth_users }}
aws_auth_users: {{ .variables.aws_auth_users }}
{{- end }}
{{- if .variables.aws_auth_accounts }}
aws_auth_accounts: {{ .variables.aws_auth_accounts }}
{{- end }}
-
name: eks-addons
type: tfmodule
providers:
- aws:
region: {{ .variables.region }}
source: "github.com/shalb/terraform-eks-addons?ref=v0.0.3"
depends_on: this.eks
inputs:
cluster_name: {{ .variables.cluster_name }}
cluster_oidc_issuer_url: {{ remoteState "this.eks.cluster_oidc_issuer_url" }}
cluster_oidc_provider_arn: {{ remoteState "this.eks.oidc_provider_arn" }}
cluster_subnets: {{ remoteState "this.vpc.public_subnets" }}
route53_domain: {{ remoteState "this.route53.domain" }}
region: {{ .variables.region }}
email: {{ .variables.email }}
route53_zone_id: {{ remoteState "this.route53.zone_id" }}
{{- if .variables.eks_addons }} {{- .variables.eks_addons | toYaml | nindent 6 }} {{ end }}
-
name: kubeconfig
type: shell
force_apply: true
apply:
commands:
- cd ../../../
- echo {{ output "this.eks-addons.kubeconfig" }} | base64 -d > $(pwd)/kubeconfig
- echo "kubeconfig_path=$(pwd)/kubeconfig"
outputs:
type: separator
separator: "="
-
name: outputs
type: printer
depends_on: this.eks-addons
outputs:
cluster_name: {{ .variables.cluster_name }}
region: {{ .variables.region }}
kubeconfig_path: {{ output "this.kubeconfig.kubeconfig_path" }}
eks_version: {{ .variables.eks_version | quote }}
domain: {{ remoteState "this.route53.domain" }}
get_kubeconfig: aws eks update-kubeconfig --name {{ .variables.cluster_name }} --region {{ .variables.region }}
{{- if eq .variables.eks_addons.enable_argocd true }}
argocd_password: kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
argocd_url: https://argocd.{{ .variables.cluster_namel }}.{{ .variables.domain }}
{{- end }}