Skip to content

Commit ee5bf09

Browse files
Add an example when EKS cluster is created and it is Omni onboarded in one go
1 parent 372ad6c commit ee5bf09

File tree

6 files changed

+328
-0
lines changed

6 files changed

+328
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module "eks" {
2+
source = "terraform-aws-modules/eks/aws"
3+
version = "~> 21.0"
4+
5+
name = var.cluster_name
6+
kubernetes_version = var.kubernetes_version
7+
endpoint_public_access = true
8+
9+
addons = {
10+
coredns = {
11+
most_recent = true
12+
}
13+
kube-proxy = {
14+
most_recent = true
15+
}
16+
vpc-cni = {
17+
most_recent = true
18+
before_compute = true
19+
}
20+
}
21+
22+
vpc_id = module.vpc.vpc_id
23+
subnet_ids = module.vpc.private_subnets
24+
25+
enable_cluster_creator_admin_permissions = true
26+
27+
self_managed_node_groups = {
28+
node_group_1 = {
29+
name = "${var.cluster_name}-ng-1"
30+
instance_type = "m5.large"
31+
max_size = 5
32+
min_size = 2
33+
desired_size = 2
34+
35+
metadata_options = {
36+
http_endpoint = "enabled"
37+
http_tokens = "required"
38+
http_put_response_hop_limit = 2
39+
}
40+
}
41+
}
42+
}
43+
44+
# Example additional security group.
45+
resource "aws_security_group" "additional" {
46+
name_prefix = "${var.cluster_name}-additional"
47+
vpc_id = module.vpc.vpc_id
48+
49+
ingress {
50+
from_port = 22
51+
to_port = 22
52+
protocol = "tcp"
53+
cidr_blocks = [
54+
"10.0.0.0/8",
55+
]
56+
}
57+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Configure Data sources and providers required for CAST AI connection.
2+
data "aws_caller_identity" "current" {}
3+
4+
# Configure EKS cluster connection using CAST AI eks-cluster module.
5+
resource "castai_eks_clusterid" "cluster_id" {
6+
account_id = data.aws_caller_identity.current.account_id
7+
region = var.cluster_region
8+
cluster_name = var.cluster_name
9+
}
10+
11+
resource "castai_eks_user_arn" "castai_user_arn" {
12+
cluster_id = castai_eks_clusterid.cluster_id.id
13+
}
14+
15+
# Create AWS IAM policies and a user to connect to CAST AI.
16+
module "castai_eks_role_iam" {
17+
source = "castai/eks-role-iam/castai"
18+
version = "~> 2.0"
19+
20+
aws_account_id = data.aws_caller_identity.current.account_id
21+
aws_cluster_region = var.cluster_region
22+
aws_cluster_name = var.cluster_name
23+
aws_cluster_vpc_id = module.vpc.vpc_id
24+
25+
castai_user_arn = castai_eks_user_arn.castai_user_arn.arn
26+
27+
create_iam_resources_per_cluster = true
28+
}
29+
30+
# CAST AI access entry for nodes to join the cluster.
31+
resource "aws_eks_access_entry" "castai" {
32+
cluster_name = module.eks.cluster_name
33+
principal_arn = module.castai_eks_role_iam.instance_profile_role_arn
34+
type = "EC2_LINUX"
35+
}
36+
37+
module "castai_eks_cluster" {
38+
source = "castai/eks-cluster/castai"
39+
version = "~> 14.1"
40+
api_url = var.castai_api_url
41+
castai_api_token = var.castai_api_token
42+
grpc_url = var.castai_grpc_url
43+
wait_for_cluster_ready = true
44+
45+
aws_account_id = data.aws_caller_identity.current.account_id
46+
aws_cluster_region = var.cluster_region
47+
aws_cluster_name = module.eks.cluster_name
48+
49+
aws_assume_role_arn = module.castai_eks_role_iam.role_arn
50+
51+
default_node_configuration = module.castai_eks_cluster.castai_node_configurations["default"]
52+
53+
node_configurations = {
54+
default = {
55+
subnets = module.vpc.private_subnets
56+
tags = var.tags
57+
security_groups = [
58+
module.eks.cluster_security_group_id,
59+
module.eks.node_security_group_id,
60+
aws_security_group.additional.id,
61+
]
62+
instance_profile_arn = module.castai_eks_role_iam.instance_profile_arn
63+
}
64+
}
65+
66+
depends_on = [module.castai_eks_role_iam]
67+
}
68+
69+
module "castai_omni_cluster" {
70+
source = "../.."
71+
72+
k8s_provider = "eks"
73+
api_url = var.castai_api_url
74+
api_token = var.castai_api_token
75+
organization_id = var.organization_id
76+
cluster_id = castai_eks_clusterid.cluster_id.id
77+
cluster_name = var.cluster_name
78+
cluster_region = var.cluster_region
79+
80+
pod_cidr = module.vpc.vpc_cidr_block
81+
api_server_address = module.eks.cluster_endpoint
82+
service_cidr = module.eks.cluster_service_cidr
83+
84+
skip_helm = var.skip_helm
85+
}
86+
87+
module "castai_omni_edge_location_aws" {
88+
source = "castai/omni-edge-location-aws/castai"
89+
version = "~> 1.0"
90+
91+
providers = {
92+
aws = aws.eu_west_1
93+
}
94+
95+
cluster_id = module.castai_omni_cluster.cluster_id
96+
organization_id = module.castai_omni_cluster.organization_id
97+
region = "eu-west-1"
98+
zones = ["eu-west-1a", "eu-west-1b"]
99+
100+
tags = {
101+
ManagedBy = "terraform"
102+
}
103+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
terraform {
2+
required_version = ">= 1.10"
3+
4+
required_providers {
5+
castai = {
6+
source = "castai/castai"
7+
version = ">= 8.4.0"
8+
}
9+
aws = {
10+
source = "hashicorp/aws"
11+
version = ">= 6.23.0"
12+
}
13+
helm = {
14+
source = "hashicorp/helm"
15+
version = ">= 3.1.1"
16+
}
17+
kubernetes = {
18+
source = "hashicorp/kubernetes"
19+
version = ">= 2.35.0"
20+
}
21+
null = {
22+
source = "hashicorp/null"
23+
version = ">= 3.2.4"
24+
}
25+
external = {
26+
source = "hashicorp/external"
27+
version = ">= 2.3.5"
28+
}
29+
}
30+
}
31+
32+
provider "aws" {
33+
alias = "eu_west_1"
34+
region = "eu-west-1"
35+
}
36+
37+
provider "aws" {
38+
region = var.cluster_region
39+
}
40+
41+
provider "helm" {
42+
kubernetes = {
43+
host = module.eks.cluster_endpoint
44+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
45+
exec = {
46+
api_version = "client.authentication.k8s.io/v1beta1"
47+
command = "aws"
48+
args = [
49+
"eks",
50+
"get-token",
51+
"--cluster-name",
52+
module.eks.cluster_name,
53+
"--region",
54+
var.cluster_region
55+
]
56+
}
57+
}
58+
}
59+
60+
provider "kubernetes" {
61+
host = module.eks.cluster_endpoint
62+
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
63+
exec {
64+
api_version = "client.authentication.k8s.io/v1beta1"
65+
command = "aws"
66+
args = [
67+
"eks",
68+
"get-token",
69+
"--cluster-name",
70+
module.eks.cluster_name,
71+
"--region",
72+
var.cluster_region
73+
]
74+
}
75+
}
76+
77+
provider "castai" {
78+
api_token = var.castai_api_token
79+
api_url = var.castai_api_url
80+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cluster_region = "<placeholder>"
2+
cluster_name = "<placeholder>"
3+
4+
castai_api_url = "https://api.cast.ai"
5+
castai_grpc_url = "grpc.cast.ai:443"
6+
castai_api_token = "<placeholder>"
7+
organization_id = "<placeholder>"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variable "cluster_region" {
2+
description = "EKS cluster region"
3+
type = string
4+
}
5+
6+
variable "cluster_name" {
7+
description = "EKS Cluster Name"
8+
type = string
9+
}
10+
11+
variable "kubernetes_version" {
12+
description = "Kubernetes version used by EKS"
13+
type = string
14+
default = "1.32"
15+
}
16+
17+
variable "castai_api_url" {
18+
description = "Cast AI API URL"
19+
type = string
20+
default = "https://api.cast.ai"
21+
}
22+
23+
variable "castai_grpc_url" {
24+
description = "Cast AI gRPC URL"
25+
type = string
26+
default = "https://api.cast.ai"
27+
}
28+
29+
variable "castai_api_token" {
30+
description = "Cast AI API Token"
31+
type = string
32+
sensitive = true
33+
}
34+
35+
variable "organization_id" {
36+
description = "Cast AI Organization ID"
37+
type = string
38+
}
39+
40+
variable "skip_helm" {
41+
description = "Skip installing any helm release; allows managing helm releases using GitOps"
42+
type = bool
43+
default = false
44+
}
45+
46+
variable "tags" {
47+
type = map(any)
48+
description = "Optional tags for new cluster nodes. This parameter applies only to new nodes - tags for old nodes are not reconciled."
49+
default = {}
50+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
data "aws_availability_zones" "available" {}
2+
3+
module "vpc" {
4+
source = "terraform-aws-modules/vpc/aws"
5+
version = "5.0.0"
6+
7+
name = var.cluster_name
8+
cidr = "10.0.0.0/16"
9+
10+
azs = data.aws_availability_zones.available.names
11+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
12+
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
13+
14+
enable_nat_gateway = true
15+
single_nat_gateway = true
16+
one_nat_gateway_per_az = false
17+
18+
tags = {
19+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
20+
}
21+
22+
public_subnet_tags = {
23+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
24+
"kubernetes.io/role/elb" = 1
25+
}
26+
27+
private_subnet_tags = {
28+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
29+
"kubernetes.io/role/internal-elb" = 1
30+
}
31+
}

0 commit comments

Comments
 (0)