How to use the AWS terraform provider
Here, I am going to implement How to use the AWS terraform provider: by launching the AWS ec2 instance.
To use the AWS Terraform provider, you’ll need to follow several steps to set up your Terraform environment, define your infrastructure in Terraform configuration files, and apply those configurations to provision and manage AWS resources. Let’s walk through these steps in detail
Step 1: Setting Up the AWS account
- Go to AWS Management Console
- Login by using your credentials.
- Now you need to generate an access key to authenticate Terraform with your AWS account
- In the AWS management console in the home screen search for IAM ( Identity and Access Management ) service. Choose Users and click on Add User.
- Give a username and select administration access as the access type. Attach necessary permissions to the user.
- Review the user details and create the user. Now you will see the access key ID and secret access key. Save this information securely as it will be required when configure Terraform.
Step 2: Launch EC2 instance And Install Terraform
Launch An Instance With Configuration:
- AMI- amazon Linux 2
- instance type- t2.micro
- Security group- allow SSH(22),HTTP(80),HTTPS(443) traffic from anywhere
- Configure storage – 8gb with root volume type gp2
- Connect this instance with any CLI terminal by using SSH
ssh -i "pemfile" ec2-user@<instance-public-ip address>compute-1.amazonaws.com
To use the AWS Terraform provider, you’ll need to follow several steps to set up your Terraform environment, define your infrastructure in Terraform configuration files, and apply those configurations to provision and manage AWS resources. Let’s walk through these steps in detail:
Step-3: Installing terraform
- Now install terraform by using following commands
Make sure we have to install terraform in our ec2 instance
- For this we need to download terraform hashicorp related packages and repo.
- I take these keys and repo from terraform official page.
- https://developer.hashicorp.com/terraform/install#linux
- to install terraform in our OS follow the below commands.
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Step 4: Set Up AWS Credentials
- Configure your AWS credentials either through environment variables, the AWS CLI, or a shared credentials file. This allows Terraform to authenticate with your AWS account.
aws configure
How to use the AWS Teraform Provider ?
Using Terraform’s simple and natural linguistic structure, clients can define infrastructure resources, their conditions, and setups in a single Terraform configuration file. These files, written in HashiCorp Setup Language (HCL), portray the ideal condition of the infrastructure, permitting Terraform to productively plan and execute changes.
The AWS Terraform provider consistently integrates with AWS APIs, empowering Terraform to create make, update, and delete resources AWS on the basis of the defined configuration. This gives clients a predictable and reproducible method for overseeing the framework, working with infrastructure automation, variant control, and coordinated effort across groups.
By utilizing the AWS Terraform supplier, clients can outfit the versatility, adaptability, and unwavering quality of AWS cloud administrations while profiting from the straightforwardness and force of Terraform’s foundation-as-code approach.
Here, in this article I will direct you to the most proficient method to utilize AWS terraform supplier and by utilizing AWS supplier we will make AWS assets like vpc,ec2_instance, and so on we desire.