Provisioning the EKS cluster using terraform module.

  1. Create the terraform module which defines the code for the creation of the EKS cluster.

  2. Apply the terraform module to create an EKS cluster.

Create of Terraform Module:

  • Modules in Terraform:

    In Terraform, modules are self-contained, reusable units of infrastructure configuration that allow you to encapsulate and abstract infrastructure components. Modules enable you to create and manage infrastructure resources in a modular and scalable manner.

  • 📑 Directory Structure:

    The module directory structure has the following key files:

    1. provider.tf: Defines the provider required for the module to work properly. You can also think of it as dependencies required for the module. This module needs the AWS module from Hashicorp (creators of Terraform). The AWS module will allow us to use the resources available in AWS to create our desired infrastructure.

    2. variable.tf: It contains the input variables required by the module to complete its task. For this project, I have set default values to the variables, but they can be easily made required by removing the default value.\

    3. cluster.tf: Define the terraform code to provision the EKS cluster.

    4. add_on.tf: Defines the terraform code required to create the cluster add-ons like autoscaler, Load balancer.

    5. node_group.tf: Contain the terraform code to create managed node group.

    6. securitygroup.tf: This file maintains the code for launching the security group.

    7. data.tf: It contains the terraform data.

Apply the Terraform Module Code to Create EKS.

  • Step 1:

    Create a connection between AWS and Terraform using the “terraform provider”:

    To launch EKS, terraform first needs to build the connection with AWS. To give the connection information to Terraform “provider” keyword is used.

  • Step 2:

    Create a main.tf file to call the module:

    This main.tf file contains the code which can call the eks module which is created in the first part.

  • Step 3:

    Create a variable.tf file to define the variables:

    variable.tf file contains the variables used in the main file which is used to call the module.

  • Step 3:

    Create terraform.tfvars file to the pass value to the variable.

  • Step 4:

    Run Terraform Code to Provision EKS:

    • Initialize Directory:

    • Check Plan:

    • Apply Changes:

Result:

After successfully applying the terraform module it provisions the EKS cluster, Policies required for the cluster, Managed node group and autoscaling group for that cluster.

THANK YOU.