This Terraform project sets up an AWS EC2 instance with an attached EBS volume, installs Docker, and runs an Nginx container. It demonstrates the power of Infrastructure as Code (IaC) for automating the deployment of a simple web server.
- Terraform installed on your local machine.
- An AWS account with the necessary permissions to create EC2 instances, EBS volumes, and key pairs.
- An SSH key pair for AWS EC2 with commands:
$ ssh-keygen -t rsa -b 4096 -C "aws_key" -f "aws_key"
$ chmod 644 aws_key.pub && chmod 400 aws_key
- Ensure your SSH keys are available at current directory.
-
Clone the Repository: Clone this repository to your local machine or download the files.
git clone https://github.com/Artem-Ushenko/aws_ec2_ebs_iac_by_terraform.git
-
Navigate to the Project Directory: Change into the project directory.
cd aws_ec2_ebs_iac_by_terraform
-
Initialize Terraform: Initialize the Terraform project to install necessary plugins.
terraform init
-
Create a Terraform Plan: Generate an execution plan for Terraform.
terraform plan
-
Apply the Terraform Configuration: Apply the configuration to start the provisioning process. You will be prompted to confirm the action.
terraform apply
To automatically approve the plan, you can use:
terraform apply -auto-approve
-
Access Your Instance:
-
After the provisioning process is complete, your EC2 instance will be running with Docker installed and an Nginx container serving a simple webpage.
-
You can access this page via the instance's public IP address what you can find in ouptuts after the provisioning process.
-
Command to check availability of the public IP address:
$ curl -s http://<public_ip_address>
-
- Modules: Modular resources for EC2 instances and EBS volumes are defined in the
./modules
directory. - Main Configuration: The main Terraform configuration is defined in the root directory, setting up the infrastructure, including key pairs, EC2 instance, EBS volume, and the Docker+Nginx setup.
- Ensure your AWS CLI is configured with the correct credentials before running Terraform commands.
- Modify the paths to the SSH keys in the Terraform files if they are located differently in your environment.
- The default instance type is
t2.micro
, which falls under the AWS Free Tier. However, check the current AWS pricing and the Free Tier eligibility.
To destroy the Terraform-managed infrastructure (to avoid unnecessary charges), run:
terraform destroy
Make sure to adjust paths, instance types, and any other configurations as necessary to match your setup and requirements.