1+ data "aws_caller_identity" "current" {}
2+
3+ provider "castai" {
4+ api_url = var. castai_api_url
5+ api_token = var. castai_api_token
6+ }
7+
8+ resource "aws_eks_access_entry" "access_entry" {
9+ cluster_name = module. eks . cluster_name
10+ principal_arn = module. castai-eks-role-iam . instance_profile_role_arn
11+ type = " EC2_LINUX"
12+ }
13+
14+ # Configure EKS cluster connection using CAST AI eks-cluster module.
15+ resource "castai_eks_clusterid" "cluster_id" {
16+ account_id = data. aws_caller_identity . current . account_id
17+ region = var. region
18+ cluster_name = var. cluster_name
19+ depends_on = [module . eks , helm_release . calico , aws_eks_access_entry . access_entry ]
20+ }
21+
22+ resource "castai_eks_user_arn" "castai_user_arn" {
23+ cluster_id = castai_eks_clusterid. cluster_id . id
24+ }
25+
26+ # Create AWS IAM policies and a user to connect to CAST AI.
27+ module "castai-eks-role-iam" {
28+ source = " castai/eks-role-iam/castai"
29+
30+ aws_account_id = data. aws_caller_identity . current . account_id
31+ aws_cluster_region = var. region
32+ aws_cluster_name = var. cluster_name
33+ aws_cluster_vpc_id = module. vpc . vpc_id
34+
35+ castai_user_arn = castai_eks_user_arn. castai_user_arn . arn
36+
37+ create_iam_resources_per_cluster = true
38+ }
39+
40+ module "castai-eks-cluster" {
41+ source = " castai/eks-cluster/castai"
42+
43+ delete_nodes_on_disconnect = var. delete_nodes_on_disconnect
44+
45+ aws_account_id = data. aws_caller_identity . current . account_id
46+ aws_cluster_region = var. region
47+ aws_cluster_name = module. eks . cluster_name
48+ aws_assume_role_arn = module. castai-eks-role-iam . role_arn
49+ api_url = var. castai_api_url
50+ castai_api_token = var. castai_api_token
51+ grpc_url = var. castai_grpc_url
52+ wait_for_cluster_ready = true
53+
54+ // Default node configuration will be used for all CAST provisioned nodes unless specific configuration is requested.
55+ default_node_configuration = module. castai-eks-cluster . castai_node_configurations [" default" ]
56+
57+ node_configurations = {
58+ default = {
59+ subnets = module.vpc.private_subnets
60+ instance_profile_arn = module.castai- eks- role- iam.instance_profile_arn
61+ security_groups = [
62+ module.eks.node_security_group_id,
63+ ]
64+ init_script = base64encode (file (" eks-init-script.sh" ))
65+ container_runtime = " containerd"
66+ eks_image_family = " al2023"
67+ }
68+ }
69+
70+ node_templates = {
71+ # Already contains live binaries on nodes
72+ default_by_castai = {
73+ name = " default-by-castai"
74+ configuration_id = module.castai- eks- cluster.castai_node_configurations[" default" ]
75+ is_default = true
76+ is_enabled = true
77+ should_taint = false
78+
79+ constraints = {
80+ on_demand = true
81+ spot = true
82+ use_spot_fallbacks = true
83+ fallback_restore_rate_seconds = 1800
84+
85+ enable_spot_diversity = false
86+ spot_diversity_price_increase_limit_percent = 20
87+
88+ architectures = [" amd64" ]
89+ }
90+ }
91+
92+ # Same setup as default, but with the goal to forcefully bring nodes with Live binaries installed, based on the NT node selector
93+ live-enabled = {
94+ name = " live-enabled"
95+ configuration_id = module.castai- eks- cluster.castai_node_configurations[" default" ]
96+ is_enabled = true
97+ should_taint = false
98+
99+ constraints = {
100+ on_demand = true
101+ spot = true
102+ use_spot_fallbacks = true
103+ fallback_restore_rate_seconds = 1800
104+
105+ enable_spot_diversity = false
106+ spot_diversity_price_increase_limit_percent = 20
107+
108+ architectures = [" amd64" ]
109+ }
110+ }
111+ }
112+
113+ autoscaler_settings = {
114+ enabled = true
115+ node_templates_partial_matching_enabled = false
116+
117+ unschedulable_pods = {
118+ enabled = true
119+ }
120+
121+ node_downscaler = {
122+ enabled = true
123+
124+ empty_nodes = {
125+ enabled = true
126+ }
127+
128+ evictor = {
129+ aggressive_mode = false
130+ cycle_interval = " 5s10s"
131+ dry_run = false
132+ enabled = true
133+ node_grace_period_minutes = 10
134+ scoped_mode = false
135+ }
136+ }
137+
138+ cluster_limits = {
139+ enabled = true
140+
141+ cpu = {
142+ max_cores = 100
143+ min_cores = 1
144+ }
145+ }
146+ }
147+ }
0 commit comments