@@ -213,3 +213,74 @@ func TestExamplesCompleteDisabled(t *testing.T) {
213213 match := re .FindString (results )
214214 assert .Equal (t , "Resources: 0 added, 0 changed, 0 destroyed." , match , "Applying with enabled=false should not create any resources" )
215215}
216+
217+ func TestExamplesAutoMode (t * testing.T ) {
218+ // Generate a random ID for resource uniqueness
219+ randId := strings .ToLower (random .UniqueId ())
220+ attributes := []string {randId }
221+
222+ // Configure Terraform options for the test
223+ terraformOptions := & terraform.Options {
224+ TerraformDir : "../../examples/complete" ,
225+ Upgrade : true ,
226+ VarFiles : []string {"fixtures.us-east-2.tfvars" },
227+ Vars : map [string ]interface {}{
228+ "attributes" : attributes ,
229+ "cluster_auto_mode_enabled" : true , // Enable EKS auto mode
230+ "bootstrap_self_managed_addons_enabled" : false , // Disable bootstrap addons
231+ "create_node_role" : true , // Create node IAM role
232+ "node_pools" : []string {"system" , "general-purpose" },// Define node pools
233+ },
234+ }
235+
236+ // Ensure resources are destroyed on test crash or completion
237+ defer runtime .HandleCrash (func (i interface {}) {
238+ terraform .Destroy (t , terraformOptions )
239+ })
240+ defer terraform .Destroy (t , terraformOptions )
241+
242+ // Initialize and apply Terraform configuration
243+ terraform .InitAndApply (t , terraformOptions )
244+
245+ // Validate VPC CIDR output
246+ vpcCidr := terraform .Output (t , terraformOptions , "vpc_cidr" )
247+ assert .Equal (t , "172.16.0.0/16" , vpcCidr )
248+
249+ // Validate private subnet CIDRs
250+ privateSubnetCidrs := terraform .OutputList (t , terraformOptions , "private_subnet_cidrs" )
251+ assert .Equal (t , []string {"172.16.0.0/19" , "172.16.32.0/19" }, privateSubnetCidrs )
252+
253+ // Validate public subnet CIDRs
254+ publicSubnetCidrs := terraform .OutputList (t , terraformOptions , "public_subnet_cidrs" )
255+ assert .Equal (t , []string {"172.16.96.0/19" , "172.16.128.0/19" }, publicSubnetCidrs )
256+
257+ // Validate EKS cluster ID output
258+ eksClusterId := terraform .Output (t , terraformOptions , "eks_cluster_id" )
259+ assert .Equal (t , "eg-test-eks-" + randId + "-cluster" , eksClusterId )
260+
261+ // In auto mode, node group outputs should be empty
262+ eksNodeGroupId := terraform .Output (t , terraformOptions , "eks_node_group_id" )
263+ assert .Equal (t , "" , eksNodeGroupId )
264+
265+ eksNodeGroupRoleName := terraform .Output (t , terraformOptions , "eks_node_group_role_name" )
266+ assert .Equal (t , "" , eksNodeGroupRoleName )
267+
268+ eksNodeGroupStatus := terraform .Output (t , terraformOptions , "eks_node_group_status" )
269+ assert .Equal (t , "" , eksNodeGroupStatus )
270+
271+ // Create AWS session for EKS API calls
272+ sess := session .Must (session .NewSession (& aws.Config {
273+ Region : aws .String ("us-east-2" ),
274+ }))
275+
276+ // Describe the EKS cluster to verify its status
277+ eksSvc := eks .New (sess )
278+ input := & eks.DescribeClusterInput {
279+ Name : aws .String ("eg-test-eks-" + randId + "-cluster" ),
280+ }
281+ result , err := eksSvc .DescribeCluster (input )
282+ assert .NoError (t , err )
283+ assert .Equal (t , "ACTIVE" , aws .StringValue (result .Cluster .Status ), "Expected EKS cluster status to be 'ACTIVE', but got '%s'" , aws .StringValue (result .Cluster .Status ))
284+
285+ fmt .Println ("EKS cluster is available (Auto Mode)" )
286+ }
0 commit comments