Skip to content

Instantly share code, notes, and snippets.

@away168
Last active October 12, 2022 22:46
Show Gist options
  • Save away168/9eb7b69ebdfa5ffe40d4414b45320e93 to your computer and use it in GitHub Desktop.
Save away168/9eb7b69ebdfa5ffe40d4414b45320e93 to your computer and use it in GitHub Desktop.
consuming env0 EKS terraform module
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "~>1.14.0"
}
}
}
// providers.tf
provider "aws" {
region = var.region
}
data "aws_eks_cluster" "cluster" {
name = var.cluster_exists ? var.cluster_name : module.env0-agent-eks.cluster_id
}
data "aws_eks_cluster_auth" "cluster" {
name = var.cluster_exists ? var.cluster_name : module.env0-agent-eks.cluster_id
}
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", data.aws_eks_cluster.cluster.name]
# command = "aws"
# }
}
provider "kubectl" {
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", data.aws_eks_cluster.cluster.name]
# command = "aws"
# }
load_config_file = false
}
provider "helm" {
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", data.aws_eks_cluster.cluster.name]
# command = "aws"
# }
}
}
variable "region" {
type = string
default = "us-east-1"
}
variable "cluster-name" {
type = string
default = "env0 agent eks"
}
variable "cluster_exists" {
type = bool
default = false
}
module "env0-agent-eks" {
source = "git@github.com:env0/k8s-modules.git//aws"
region = var.region
cluster_name = var.cluster-name
//us-west-2 only has four AZs so reduce subnets to 4
//private_subnets = ["172.16.0.0/21", "172.16.16.0/21", "172.16.32.0/21", "172.16.48.0/21"]
//public_subnets = ["172.16.8.0/22", "172.16.24.0/22", "172.16.40.0/22", "172.16.56.0/22"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment