Skip to content

Instantly share code, notes, and snippets.

@limed
Created July 7, 2020 16:05
Show Gist options
  • Save limed/dc8eff9a65ca22a7a680019575c8983e to your computer and use it in GitHub Desktop.
Save limed/dc8eff9a65ca22a7a680019575c8983e to your computer and use it in GitHub Desktop.
terraform for dev eks cluster
data "aws_vpc" "this" {
id = "vpc-09f6a265a28ff8c52"
}
data "aws_subnet_ids" "public" {
vpc_id = data.aws_vpc.this.id
filter {
name = "tag:Name"
values = ["*public*"]
}
}
data "aws_subnet_ids" "private" {
vpc_id = data.aws_vpc.this.id
filter {
name = "tag:Name"
values = ["*private*"]
}
}
data "aws_eks_cluster" "cluster" {
name = module.test-cluster.cluster_id
}
data "aws_eks_cluster_auth" "cluster" {
name = module.test-cluster.cluster_id
}
data "aws_iam_policy_document" "fargate_profile" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = [
"eks.amazonaws.com",
"eks-fargate-pods.amazonaws.com"
]
}
}
}
locals {
cluster_features = {
reloader = false
alb_ingress = false
velero = false
sealed_secrets = false
}
roles = [
{
username = "maws-admin"
rolearn = "arn:aws:iam::517826968395:role/maws-admin"
groups = ["system:masters"]
}
]
node_groups = {
default_ng = {
desired_capacity = "3"
min_capacity = "3"
max_capacity = "10"
instance_type = "t3.small"
subnets = data.aws_subnet_ids.private.ids
additional_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"k8s.io/cluster-autoscaler/enabled" = "true"
}
}
}
}
resource "aws_iam_role" "fargate" {
name = "${module.test-cluster.cluster_id}-fargate-profile"
assume_role_policy = data.aws_iam_policy_document.fargate_profile.json
}
module "test-cluster" {
source = "github.com/mozilla-it/terraform-modules//aws/eks?ref=master"
cluster_name = var.cluster_name
cluster_version = "1.16"
vpc_id = data.aws_vpc.this.id
cluster_subnets = data.aws_subnet_ids.public.ids
map_roles = local.roles
node_groups = local.node_groups
cluster_features = local.cluster_features
}
provider "aws" {
region = "us-west-2"
}
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
load_config_file = false
version = "~> 1"
}
provider "helm" {
version = "~> 1"
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
load_config_file = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment