DEV Community

Cover image for Creating an EC2 instance with SSH access using Terraform:
Albine Peter
Albine Peter

Posted on

Creating an EC2 instance with SSH access using Terraform:

Introduction :
*.Terraform is an open-source infrastructure as code (IaC) tool that allows you to define and provision data center infrastructure using a high-level configuration language. One of the most common use cases for Terraform is managing cloud resources, such as creating and managing Amazon Web Services (AWS) EC2 instances.

Steps to Create an EC2 Instance with SSH Access:

1)** Setup Terraform Configuration:** Write a Terraform configuration file (main.tf) **that specifies the desired infrastructure, including the EC2 instance, security groups, and SSH key pair.
2)_
Initialize Terraform*_: Run terraform init to initialize the working directory containing the Terraform configuration files. This will download the necessary provider plugins.
3)
_ Plan Infrastructure Changes_: Run terraform plan to create an execution plan. This command shows the changes that will be made to your infrastructure.
4)
_ Apply Configuration: _Run terraform apply to apply the changes and create the EC2 instance. Terraform will prompt you to confirm before making any changes.
5) *
_Access EC2 Instance: _**Once the instance is created, use the public IP address output by Terraform to SSH into the instance and verify the setup.

Conclusion:
By following these steps, you can efficiently deploy EC2 instances and manage your AWS infrastructure with greater confidence and control. As you continue to explore and use Terraform, you will find it an invaluable asset in your DevOps toolkit, helping you to achieve more with less effort.

Top comments (0)