forked from ViktorUJ/cks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathami.tf
56 lines (44 loc) · 1.42 KB
/
ami.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
data "aws_ec2_instance_type" "master" {
instance_type = var.k8s_master.instance_type
}
data "aws_ami" "master" {
most_recent = true
filter {
name = "name"
values = join("", data.aws_ec2_instance_type.master.supported_architectures) == "x86_64" ? ["ubuntu/images/hvm-ssd/ubuntu-*-${var.k8s_master.ubuntu_version}-amd64-server-*"] : ["ubuntu/images/hvm-ssd/ubuntu-*-${var.k8s_master.ubuntu_version}-arm64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"]
}
data "aws_ec2_instance_type" "worker" {
for_each = var.k8s_worker
instance_type = each.value.instance_type
}
locals {
worker_ami_arh = {
for key, instance in var.k8s_worker :
key => {
name = join("", data.aws_ec2_instance_type.master.supported_architectures) == "x86_64" ? "amd64" : "arm64"
filter = join("", data.aws_ec2_instance_type.master.supported_architectures) == "x86_64" ? "ubuntu/images/hvm-ssd/ubuntu-*-${instance.ubuntu_version}-amd64-server-*" : "ubuntu/images/hvm-ssd/ubuntu-*-${instance.ubuntu_version}-arm64-server-*"
}
}
}
#output "worker_arch" {
# value = local.worker_ami_arh
#}
data "aws_ami" "worker" {
for_each = var.k8s_worker
most_recent = true
filter {
name = "name"
values = [local.worker_ami_arh["${each.key}"].filter]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"]
}