Skip to content

Commit 2d6580d

Browse files
committed
Refactoring terraform
1 parent 06c0bb1 commit 2d6580d

File tree

13 files changed

+243
-114
lines changed

13 files changed

+243
-114
lines changed

ai-ml/bionemo/eks.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,10 @@ module "eks" {
143143
}
144144
}
145145
}
146+
147+
148+
data "aws_availability_zones" "available" {}
149+
150+
data "aws_eks_cluster_auth" "this" {
151+
name = module.eks.cluster_name
152+
}

ai-ml/bionemo/locals.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#---------------------------------------------------------------
2+
# Local variables
3+
#---------------------------------------------------------------
4+
locals {
5+
name = var.name
6+
region = var.region
7+
8+
# Routable Private subnets only for Private NAT Gateway -> Transit Gateway -> Second VPC for overlapping CIDRs
9+
# e.g., var.vpc_cidr = "10.1.0.0/21" => output: ["10.1.0.0/24", "10.1.1.0/24"] => 256-2 = 254 usable IPs per subnet/AZ
10+
private_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 3, k)]
11+
# Routable Public subnets with NAT Gateway and Internet Gateway
12+
# e.g., var.vpc_cidr = "10.1.0.0/21" => output: ["10.1.2.0/26", "10.1.2.64/26"] => 64-2 = 62 usable IPs per subnet/AZ
13+
public_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 5, k + 8)]
14+
15+
database_private_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 3, k + 5)]
16+
# RFC6598 range 100.64.0.0/16 for EKS Data Plane for two subnets(32768 IPs per Subnet) across two AZs for EKS Control Plane ENI + Nodes + Pods
17+
# e.g., var.secondary_cidr_blocks = "100.64.0.0/16" => output: ["100.64.0.0/17", "100.64.128.0/17"] => 32768-2 = 32766 usable IPs per subnet/AZ
18+
secondary_ip_range_private_subnets = [for k, v in local.azs : cidrsubnet(element(var.secondary_cidr_blocks, 0), 1, k)]
19+
20+
vpc_cidr = var.vpc_cidr
21+
azs = slice(data.aws_availability_zones.available.names, 0, 2)
22+
23+
tags = {
24+
Blueprint = local.name
25+
GithubRepo = "github.com/awslabs/data-on-eks"
26+
}
27+
}

ai-ml/bionemo/providers.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
provider "kubernetes" {
6+
host = module.eks.cluster_endpoint
7+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
8+
token = data.aws_eks_cluster_auth.this.token
9+
}
10+
11+
# ECR always authenticates with `us-east-1` region
12+
# Docs -> https://docs.aws.amazon.com/AmazonECR/latest/public/public-registries.html
13+
provider "aws" {
14+
alias = "ecr"
15+
region = "us-east-1"
16+
}
17+
18+
provider "helm" {
19+
kubernetes {
20+
host = module.eks.cluster_endpoint
21+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
22+
token = data.aws_eks_cluster_auth.this.token
23+
}
24+
}
25+
26+
provider "kubectl" {
27+
apply_retry_count = 10
28+
host = module.eks.cluster_endpoint
29+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
30+
load_config_file = false
31+
token = data.aws_eks_cluster_auth.this.token
32+
}

ai-ml/bionemo/vpc.tf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
locals {
2-
# Routable Private subnets only for Private NAT Gateway -> Transit Gateway -> Second VPC for overlapping CIDRs
3-
# e.g., var.vpc_cidr = "10.1.0.0/21" => output: ["10.1.0.0/24", "10.1.1.0/24"] => 256-2 = 254 usable IPs per subnet/AZ
4-
private_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 3, k)]
5-
# Routable Public subnets with NAT Gateway and Internet Gateway
6-
# e.g., var.vpc_cidr = "10.1.0.0/21" => output: ["10.1.2.0/26", "10.1.2.64/26"] => 64-2 = 62 usable IPs per subnet/AZ
7-
public_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 5, k + 8)]
8-
9-
database_private_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 3, k + 5)]
10-
# RFC6598 range 100.64.0.0/16 for EKS Data Plane for two subnets(32768 IPs per Subnet) across two AZs for EKS Control Plane ENI + Nodes + Pods
11-
# e.g., var.secondary_cidr_blocks = "100.64.0.0/16" => output: ["100.64.0.0/17", "100.64.128.0/17"] => 32768-2 = 32766 usable IPs per subnet/AZ
12-
secondary_ip_range_private_subnets = [for k, v in local.azs : cidrsubnet(element(var.secondary_cidr_blocks, 0), 1, k)]
13-
}
14-
151
#---------------------------------------------------------------
162
# VPC
173
#---------------------------------------------------------------

ai-ml/ray/terraform/locals.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#---------------------------------------------------------------
2+
# Locals
3+
#---------------------------------------------------------------
4+
locals {
5+
name = var.name
6+
region = var.region
7+
8+
vpc_cidr = "10.0.0.0/16"
9+
secondary_vpc_cidr = "100.64.0.0/16"
10+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
11+
12+
cluster_version = var.eks_cluster_version
13+
14+
tags = {
15+
Blueprint = local.name
16+
GithubRepo = "github.com/awslabs/data-on-eks"
17+
}
18+
}

ai-ml/ray/terraform/main.tf

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,3 @@
1-
#---------------------------------------------------------------
2-
# Providers
3-
#---------------------------------------------------------------
4-
5-
provider "aws" {
6-
region = local.region
7-
}
8-
9-
# Used for Karpenter Helm chart
10-
provider "aws" {
11-
region = "us-east-1"
12-
alias = "ecr_public_region"
13-
}
14-
15-
provider "kubernetes" {
16-
host = module.eks.cluster_endpoint
17-
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
18-
19-
exec {
20-
api_version = "client.authentication.k8s.io/v1beta1"
21-
command = "aws"
22-
# This requires the awscli to be installed locally where Terraform is executed
23-
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
24-
}
25-
}
26-
27-
provider "helm" {
28-
kubernetes {
29-
host = module.eks.cluster_endpoint
30-
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
31-
32-
exec {
33-
api_version = "client.authentication.k8s.io/v1beta1"
34-
command = "aws"
35-
# This requires the awscli to be installed locally where Terraform is executed
36-
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
37-
}
38-
}
39-
}
40-
41-
provider "kubectl" {
42-
apply_retry_count = 5
43-
host = module.eks.cluster_endpoint
44-
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
45-
load_config_file = false
46-
47-
exec {
48-
api_version = "client.authentication.k8s.io/v1beta1"
49-
command = "aws"
50-
# This requires the awscli to be installed locally where Terraform is executed
51-
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
52-
}
53-
}
54-
551
#---------------------------------------------------------------
562
# Data Sources
573
#---------------------------------------------------------------
@@ -63,26 +9,6 @@ data "aws_ecrpublic_authorization_token" "token" {
639
provider = aws.ecr_public_region
6410
}
6511

66-
#---------------------------------------------------------------
67-
# Locals
68-
#---------------------------------------------------------------
69-
70-
locals {
71-
name = var.name
72-
region = var.region
73-
74-
vpc_cidr = "10.0.0.0/16"
75-
secondary_vpc_cidr = "100.64.0.0/16"
76-
azs = slice(data.aws_availability_zones.available.names, 0, 3)
77-
78-
cluster_version = var.eks_cluster_version
79-
80-
tags = {
81-
Blueprint = local.name
82-
GithubRepo = "github.com/awslabs/data-on-eks"
83-
}
84-
}
85-
8612
#---------------------------------------------------------------
8713
# EKS Cluster
8814
#---------------------------------------------------------------

ai-ml/ray/terraform/providers.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#---------------------------------------------------------------
2+
# Providers
3+
#---------------------------------------------------------------
4+
5+
provider "aws" {
6+
region = local.region
7+
}
8+
9+
# Used for Karpenter Helm chart
10+
provider "aws" {
11+
region = "us-east-1"
12+
alias = "ecr_public_region"
13+
}
14+
15+
provider "kubernetes" {
16+
host = module.eks.cluster_endpoint
17+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
18+
19+
exec {
20+
api_version = "client.authentication.k8s.io/v1beta1"
21+
command = "aws"
22+
# This requires the awscli to be installed locally where Terraform is executed
23+
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
24+
}
25+
}
26+
27+
provider "helm" {
28+
kubernetes {
29+
host = module.eks.cluster_endpoint
30+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
31+
32+
exec {
33+
api_version = "client.authentication.k8s.io/v1beta1"
34+
command = "aws"
35+
# This requires the awscli to be installed locally where Terraform is executed
36+
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
37+
}
38+
}
39+
}
40+
41+
provider "kubectl" {
42+
apply_retry_count = 5
43+
host = module.eks.cluster_endpoint
44+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
45+
load_config_file = false
46+
47+
exec {
48+
api_version = "client.authentication.k8s.io/v1beta1"
49+
command = "aws"
50+
# This requires the awscli to be installed locally where Terraform is executed
51+
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
52+
}
53+
}

ai-ml/ray/terraform/variables.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
variable "region" {
22
description = "Region"
33
type = string
4-
default = "us-west-2"
54
}
65

76
variable "name" {
87
description = "Name of the VPC, EKS Cluster and Ray cluster"
9-
default = "ray-cluster"
108
type = string
119
}
1210

1311
variable "eks_cluster_version" {
1412
description = "EKS Cluster version"
15-
default = "1.25"
1613
type = string
1714
}

ai-ml/trainium-inferentia/eks.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
#---------------------------------------------------------------
2+
# Data Sources
3+
#---------------------------------------------------------------
4+
5+
data "aws_ecrpublic_authorization_token" "token" {
6+
provider = aws.ecr
7+
}
8+
9+
data "aws_caller_identity" "current" {}
10+
11+
data "aws_iam_session_context" "current" {
12+
arn = data.aws_caller_identity.current.arn
13+
}
14+
115
#---------------------------------------------------------------
216
# EKS Cluster
317
#---------------------------------------------------------------

ai-ml/trainium-inferentia/jupyterhub.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
#-----------------------------------------------------------------------------------------
2-
# JupyterHub Single User IRSA, maybe that block could be incorporated in add-on registry
3-
#-----------------------------------------------------------------------------------------
4-
resource "kubernetes_namespace_v1" "jupyterhub" {
5-
count = var.enable_jupyterhub ? 1 : 0
6-
7-
metadata {
8-
name = "jupyterhub"
9-
}
10-
}
11-
121
module "jupyterhub_single_user_irsa" {
132
count = var.enable_jupyterhub ? 1 : 0
143

@@ -28,6 +17,17 @@ module "jupyterhub_single_user_irsa" {
2817
}
2918
}
3019

20+
#-----------------------------------------------------------------------------------------
21+
# JupyterHub Single User IRSA, maybe that block could be incorporated in add-on registry
22+
#-----------------------------------------------------------------------------------------
23+
resource "kubernetes_namespace_v1" "jupyterhub" {
24+
count = var.enable_jupyterhub ? 1 : 0
25+
26+
metadata {
27+
name = "jupyterhub"
28+
}
29+
}
30+
3131
resource "kubernetes_service_account_v1" "jupyterhub_single_user_sa" {
3232
count = var.enable_jupyterhub ? 1 : 0
3333

0 commit comments

Comments
 (0)