This Terraform project automates the provisioning of AWS infrastructure, including a Virtual Private Cloud (VPC), public subnet, internet gateway, route table, security group, and an EC2 instance. The project is designed to be flexible, allowing customization through variables for different environments.
Before running the Terraform scripts, ensure you have the following prerequisites:
-
Terraform Installation: Install Terraform on your machine. You can download it from Terraform Downloads.
-
AWS Credentials: Make sure you have AWS credentials configured on your machine with the necessary permissions for resource creation.
-
Clone the Repository: Clone this repository to your local machine.
git clone https://github.com/metahedgehog/terraform-aws-deploy.git
-
Navigate to the Project Directory: Change into the project directory.
cd terraform-aws-deploy
-
Initialize Terraform: Run the following command to initialize Terraform in the project directory.
terraform init
-
Review and Modify Variables (Optional): Open the
variables.tf
file and review the variables. Modify them as needed based on your requirements. -
Run Terraform Plan: Execute the following command to see the plan of what Terraform will create.
terraform plan
-
Apply Terraform Changes: If the plan looks good, apply the changes.
terraform apply
-
Review Outputs: After the Terraform apply is complete, review the outputs to get information about the created resources.
terraform output
Save the outputs in a file for future reference.
The following outputs are provided by the Terraform script:
- ec2_public_ip: Public IP address of the EC2 instance.
- ec2_ami: AMI ID of the launched EC2 instance.
- ec2_type: Instance type used for the EC2 instance.
- public_vpc_id: ID of the created VPC.
- ec2_subnet_id: ID of the public subnet where the EC2 instance is deployed.
- public_subnet_AZ: Availability Zone of the public subnet.
- ec2_region: AWS region where the infrastructure is deployed.
To avoid incurring unnecessary costs, it's essential to destroy the created resources when they are no longer needed.
-
Run the following command to see the plan for resource destruction:
terraform plan -destroy
-
If the plan looks correct, execute the following command to destroy the resources:
terraform destroy