Provisioning an AWS VPC (Virtual Private Cloud) using Terraform involves defining the desired infrastructure as code and then using Terraform to create and manage those resources on AWS.
Perquisites:
Installed to be on your Local Machine.
For Installing All for this , Follow the Official Document of that tools.
Terraform
VS Code
Aws CLI
Aws Account
Install Terraform
You have to install Terraform on your local machine. You can download it from the official Terraform website (https://www.terraform.io/downloads.html) and follow the installation instructions for your operating system.
Configure AWS Credentials:
Then we need to create a user on the AWS and after creating the user , generate the Access & Secrete Access Key, for the connecting the AWS with Terraform.
after Creating the user we need to some access/permissions to this user. creating & managing the terraform permissions or provide the aws Administrator permissions/access.
provider.tf
The provider.tf file is used to define the provider configuration. A Terraform provider is responsible for managing the lifecycle of a particular type of infrastructure, such as AWS, Azure, Google Cloud, etc. It specifies the details of the cloud provider you are using and any necessary authentication or configuration parameters.
main.tf
The main.tf file is typically the main entry point for your Terraform configuration. It contains the resource definitions and configurations necessary for your infrastructure. In the context of provisioning AWS EKS with Terraform, it would include the definition of your EKS cluster, associated networking resources, and any other dependencies.
Terraform init
Run the command in your Terraform project directory to initialize the project. This downloads the necessary provider plugins and sets up the working directory.
terraform.lock.hcl File:
The terraform.lock.hcl file is related to Terraform modules and is used to pin module versions. It's created automatically when you use the terraform init command to initialize a Terraform configuration that uses modules.
terraform validate
The terraform validate command checks the syntax and structure of your Terraform configuration files. It ensures that your configurations are correctly written and that all the necessary providers and modules are available.
terraform plan
The terraform plan command is used to create an execution plan. It provides a preview of the changes that Terraform will make to your infrastructure based on your configuration. This is a critical step before actually applying any changes to your infrastructure.
terraform apply
Apply the Terraform configuration to create the AWS resources. This step might take some time as it provisions the EKS cluster, associated networking resources, and other dependencies.
Output- VPC Created
Created subnets
Created route table
Created Internet Gateway
terraform destroy
This Command for destroy all of those resources , which was created by terraform.