This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheniconfig.tf
54 lines (43 loc) · 1.53 KB
/
eniconfig.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
###############################################################################
# Kubernetes provider configuration
###############################################################################
data "aws_eks_cluster_auth" "cluster" {
name = var.cluster_name
}
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.cluster.token
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
resource "kubernetes_manifest" "eniconfig_subnets" {
for_each = var.vpc_eni_subnets
depends_on = [
helm_release.karpenter
]
manifest = {
"apiVersion" = "crd.k8s.amazonaws.com/v1alpha1"
"kind" = "ENIConfig"
"metadata" = {
"name" = each.key
}
"spec" = {
"subnet" = "eni-${each.value}"
"securityGroups" = [
var.worker_security_group_id
]
}
}
}
resource "null_resource" "rotate_nodes_after_eniconfig_creation" {
count = var.rotate_nodes_after_eniconfig_creation ? 1 : 0
provisioner "local-exec" {
command = <<-EOT
aws ec2 terminate-instances --instance-ids $(aws ec2 describe-instances --filter "Name=tag:Name,Values=$CLUSTER_NAME-general" "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].[InstanceId]" --output text) --output text
EOT
}
}