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

Commit

Permalink
BATIAI-303 Simplify cluster deployments by making the 1-* scripts par…
Browse files Browse the repository at this point in the history
…t of the TF rollout (#1)

* eni configs

* cleanup

* remove comments
  • Loading branch information
rcmendo authored Apr 20, 2022
1 parent d935f2c commit a9a72d4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
54 changes: 54 additions & 0 deletions eniconfig.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}

}
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ variable "helm_name" {
variable "cluster_endpoint" {
default = ""
}

variable "vpc_eni_subnets" {
type = map(any)
}

variable "worker_security_group_id" {
type = string
}

variable "rotate_nodes_after_eniconfig_creation" {
type = bool
default = true
}

0 comments on commit a9a72d4

Please sign in to comment.