Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit a9a72d4

Browse files
authored
BATIAI-303 Simplify cluster deployments by making the 1-* scripts part of the TF rollout (#1)
* eni configs * cleanup * remove comments
1 parent d935f2c commit a9a72d4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

eniconfig.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
###############################################################################
2+
# Kubernetes provider configuration
3+
###############################################################################
4+
5+
data "aws_eks_cluster_auth" "cluster" {
6+
name = var.cluster_name
7+
}
8+
9+
provider "kubernetes" {
10+
host = data.aws_eks_cluster.cluster.endpoint
11+
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
12+
token = data.aws_eks_cluster_auth.cluster.token
13+
exec {
14+
api_version = "client.authentication.k8s.io/v1alpha1"
15+
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
16+
command = "aws"
17+
}
18+
}
19+
20+
resource "kubernetes_manifest" "eniconfig_subnets"{
21+
22+
for_each = var.vpc_eni_subnets
23+
24+
depends_on = [
25+
helm_release.karpenter
26+
]
27+
28+
manifest = {
29+
"apiVersion" = "crd.k8s.amazonaws.com/v1alpha1"
30+
"kind" = "ENIConfig"
31+
"metadata" = {
32+
"name" = "${each.key}"
33+
}
34+
"spec" = {
35+
"subnet" = "eni-${each.value}"
36+
"securityGroups" = [
37+
"${var.worker_security_group_id}"
38+
]
39+
}
40+
}
41+
42+
}
43+
44+
resource "null_resource" "rotate_nodes_after_eniconfig_creation" {
45+
46+
count = var.rotate_nodes_after_eniconfig_creation ? 1 : 0
47+
48+
provisioner "local-exec" {
49+
command = <<-EOT
50+
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
51+
EOT
52+
}
53+
54+
}

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,16 @@ variable "helm_name" {
3434
variable "cluster_endpoint" {
3535
default = ""
3636
}
37+
38+
variable "vpc_eni_subnets" {
39+
type = map(any)
40+
}
41+
42+
variable "worker_security_group_id" {
43+
type = string
44+
}
45+
46+
variable "rotate_nodes_after_eniconfig_creation" {
47+
type = bool
48+
default = true
49+
}

0 commit comments

Comments
 (0)