forked from rancher/terraform-k3s-aws-cluster
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdata.tf
132 lines (117 loc) · 3.65 KB
/
data.tf
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
data "aws_vpc" "default" {
default = false
id = var.vpc_id
}
data "aws_subnets" "available" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}
data "aws_route53_zone" "dns_zone" {
count = local.use_route53
provider = aws.r53
name = local.r53_domain
}
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "architecture"
values = ["arm64"]
}
}
data "cloudinit_config" "k3s_server" {
gzip = true
base64_encode = true
# Main cloud-config configuration file.
part {
filename = "init.cfg"
content_type = "text/cloud-config"
content = templatefile("${path.module}/files/cloud-config-base.yaml",
{
ssh_keys = var.ssh_keys
})
}
part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/k3s-install.sh",
{
install_k3s_version = local.install_k3s_version,
k3s_exec = local.server_k3s_exec,
k3s_cluster_secret = local.k3s_cluster_secret,
is_k3s_server = true,
k3s_url = aws_lb.server-lb.dns_name,
k3s_datastore_endpoint = local.k3s_datastore_endpoint,
k3s_datastore_cafile = local.k3s_datastore_cafile,
k3s_disable_agent = local.k3s_disable_agent,
k3s_tls_san = local.k3s_tls_san
})
}
part {
content_type = "text/x-shellscript"
content = templatefile(
"${path.module}/files/rancher-install.sh",
{ certmanager_version = local.certmanager_version,
letsencrypt_email = local.letsencrypt_email,
letsencrypt_environment = local.letsencrypt_environment,
rancher_version = local.rancher_version,
rancher_hostname = "${local.subdomain}.${local.domain}",
install_nginx = local.install_nginx,
nginx_version = local.nginx_version,
install_rancher = local.install_rancher,
install_certmanager = local.install_certmanager,
rancher_password = local.rancher_password,
features = local.rancher_features
})
}
part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/register-to-rancher.sh",
{
is_k3s_server = true,
install_rancher = local.install_rancher,
registration_command = local.registration_command
})
}
}
data "cloudinit_config" "k3s_agent" {
gzip = true
base64_encode = true
# Main cloud-config configuration file.
part {
filename = "init.cfg"
content_type = "text/cloud-config"
content = templatefile("${path.module}/files/cloud-config-base.yaml",
{
ssh_keys = var.ssh_keys
})
}
part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/k3s-install.sh",
{
install_k3s_version = local.install_k3s_version,
k3s_exec = local.agent_k3s_exec,
k3s_cluster_secret = local.k3s_cluster_secret,
is_k3s_server = false,
k3s_url = aws_lb.server-lb.dns_name,
k3s_datastore_endpoint = local.k3s_datastore_endpoint,
k3s_datastore_cafile = local.k3s_datastore_cafile,
k3s_disable_agent = local.k3s_disable_agent,
k3s_tls_san = local.k3s_tls_san
})
}
}