Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision cloud infrastructure using a high-level configuration language known as Hashicorp Configuration Language (HCL).
The main advantage of using Terraform is that it allows you to define your infrastructure as code once and then deploy it in multiple environments, having always the same result.
We will provision a simple infrastructure that we can use to deploy the my-awesome-app example. This infrastructure will consist of a VPC, a public subnet, an internet gateway, a security group, and an EKS instance.
Requirements:
- Make sure you have the terraform CLI installed
To provision the infrastructure in AWS, we will use the AWS Terraform provider. You can find the Terraform code in the aws directory.
Requirements:
- Make sure you have the AWS CLI installed
- You need to have an AWS account and the AWS CLI configured
- Select the cloud provider you want to use and follow the instructions in the respective directory. In this example,
we will use AWS.
cd aws - Adjust the values in the _config.tf file to match your environment.
- Initialize the Terraform working directory and download the AWS provider plugin.
terraform init
- Create an execution plan.
terraform plan -out tfplan
- Apply the changes to the infrastructure.
terraform apply tfplan
Once the infrastructure is provisioned, you can update your kubeconfig file to connect to the EKS cluster by running the following command:
aws eks --region us-east-1 update-kubeconfig --name learn-devopsOnce you are done with the infrastructure, you can destroy it by running the following command:
terraform destroy