Skip to content

Instantly share code, notes, and snippets.

@nicosingh
Last active May 10, 2023 19:33
Show Gist options
  • Save nicosingh/900c55c92632c7f7372a6c34cc39a804 to your computer and use it in GitHub Desktop.
Save nicosingh/900c55c92632c7f7372a6c34cc39a804 to your computer and use it in GitHub Desktop.
# create some variables
variable "cluster_name" {
type = string
description = "EKS cluster name."
}
variable "cluster_endpoint" {
type = string
description = "Endpoint for your Kubernetes API server."
}
variable "cluster_certificate_authority_data" {
type = string
description = "Base64 encoded certificate data required to communicate with the cluster."
}
variable "spot_termination_handler_chart_name" {
type = string
description = "EKS Spot termination handler Helm chart name."
}
variable "spot_termination_handler_chart_repo" {
type = string
description = "EKS Spot termination handler Helm repository name."
}
variable "spot_termination_handler_chart_version" {
type = string
description = "EKS Spot termination handler Helm chart version."
}
variable "spot_termination_handler_chart_namespace" {
type = string
description = "Kubernetes namespace to deploy EKS Spot termination handler Helm chart."
}
# get EKS authentication for being able to manage k8s objects from terraform
provider "kubernetes" {
host = var.cluster_endpoint
cluster_ca_certificate = base64decode(var.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
provider "helm" {
kubernetes {
host = var.cluster_endpoint
cluster_ca_certificate = base64decode(var.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
}
# deploy spot termination handler
resource "helm_release" "spot_termination_handler" {
name = var.spot_termination_handler_chart_name
chart = var.spot_termination_handler_chart_name
repository = var.spot_termination_handler_chart_repo
version = var.spot_termination_handler_chart_version
namespace = var.spot_termination_handler_chart_namespace
wait_for_jobs = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment