-
Notifications
You must be signed in to change notification settings - Fork 6
/
vpc.tf
66 lines (54 loc) · 1.42 KB
/
vpc.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
data "aws_vpc" "eks_vpc" {
tags = {
Name = var.vpc_name
}
}
data "aws_subnets" "public" {
filter {
name = "vpc-id"
values = [data.aws_vpc.eks_vpc.id]
}
tags = {
Type = "Public"
}
}
data "aws_subnets" "private" {
filter {
name = "vpc-id"
values = [data.aws_vpc.eks_vpc.id]
}
tags = {
Type = "Private"
}
}
# TODO: use aws_ec2_tag instead of kubectl
resource "null_resource" "tag_subnets" {
triggers = {
subnet_ids = join(" ", setunion(data.aws_subnets.public.ids, data.aws_subnets.private.ids))
cluster_name = var.cluster_name
region = var.region
profile = var.profile
}
provisioner "local-exec" {
command = <<-EOT
aws ec2 create-tags \
--resource ${self.triggers.subnet_ids} \
--tags "Key=kubernetes.io/cluster/${self.triggers.cluster_name},Value=shared" \
--region=${self.triggers.region} \
--profile ${self.triggers.profile}
EOT
interpreter = ["bash", "-c"]
}
provisioner "local-exec" {
when = destroy
command = <<-EOT
aws ec2 delete-tags \
--resource ${self.triggers.subnet_ids} \
--tags "Key=kubernetes.io/cluster/${self.triggers.cluster_name},Value=shared" \
--region=${self.triggers.region} \
--profile ${self.triggers.profile}
EOT
interpreter = ["bash", "-c"]
}
depends_on = [null_resource.check_aws_credentials_are_available]
}