Skip to content

Commit

Permalink
Merge pull request #2 from thetestlabs/feat/add-terraform-config
Browse files Browse the repository at this point in the history
feat: add terraform config to deploy eks and supporting resources
  • Loading branch information
thetestlabs authored Dec 31, 2024
2 parents 084aa89 + 26d396a commit c5da32f
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
8 changes: 8 additions & 0 deletions terraform/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "aws_availability_zones" "available" {
# Exclude local zones
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

6 changes: 6 additions & 0 deletions terraform/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locals {
vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

cluster_version = "1.31"
}
19 changes: 19 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module "eks_auto_mode" {
source = "terraform-aws-modules/eks/aws"
version = "20.31.6"

cluster_name = var.service
cluster_version = local.cluster_version
cluster_endpoint_public_access = true

enable_cluster_creator_admin_permissions = true

cluster_compute_config = {
enabled = true
node_pools = ["general-purpose"]
}

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

}
12 changes: 12 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
provider "aws" {
region = var.region

default_tags {
tags = {
"Technical:TerraformStack" = var.terraform_stack
"Technical:Environment" = var.environment
"Technical:Service" = var.service
}
}

}
27 changes: 27 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "region" {
description = "(Required) The AWS Region to create the Terraform State Backend resources in."
type = string
default = "eu-west-2"

}

variable "terraform_stack" {
description = "The name of the Terraform stack, which should be the name of the repository where the Terraform configuration is stored"
type = string
default = "deploy-eks-auto-mode-with-terraform"

}

variable "environment" {
description = "The environment that resources are being deployed to, for example Dev/Prod etc"
type = string
default = "dev"

}

variable "service" {
description = "The service that resources are being deployed to support, for example the application name"
type = string
default = "ttl-blog"

}
11 changes: 11 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = "~> 1.10.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}

}
}
24 changes: 24 additions & 0 deletions terraform/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"

name = var.service
cidr = local.vpc_cidr

azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
intra_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 52)]

enable_nat_gateway = true
single_nat_gateway = true

public_subnet_tags = {
"kubernetes.io/role/elb" = 1
}

private_subnet_tags = {
"kubernetes.io/role/internal-elb" = 1
}

}

0 comments on commit c5da32f

Please sign in to comment.