This project provides a Terraform configuration to provision an AWS EC2 instance.
- An AWS account
- Terraform installed on your local machine
- AWS CLI configured with appropriate permissions
├── main.tf # Main configuration for provisioning the EC2 instance
├── variables.tf # Input variables for the Terraform configuration
├── outputs.tf # Output values after infrastructure creation
├── provider.tf # Provider configuration for AWS
└── README.md # Project documentation
-
Clone the repository (if applicable):
git clone <repository-url> cd terraform-aws-ec2
-
Initialize Terraform: Run the following command to initialize the Terraform configuration:
terraform init
-
Configure Variables: Edit the
variables.tffile to set your desired instance type and AMI ID, or provide them via command line or a.tfvarsfile. -
Plan the Deployment: Generate an execution plan with:
terraform plan
-
Apply the Configuration: To create the EC2 instance, run:
terraform apply
-
Accessing the EC2 Instance: After the instance is created, you can find the public IP address in the output. Use SSH to connect to the instance.
-
Destroying the Infrastructure: To remove the EC2 instance and associated resources, run:
terraform destroy
- Ensure that your AWS credentials are configured properly.
- Modify security group settings in
main.tfas needed to allow access to your instance. - Review the AWS pricing for EC2 instances to understand potential costs.