Please refer to the SETUP document, if you don't have AWS cli and Terraform installed. You will also need to setup some AWS credentials.
Shoutout to David Thurn (@packetmonster) since I got most of the documentation and the main.tf from his workshop at SaintCon2023. Credits to him as I will using some of that code
git clone https://github.com/solidshadw/terraSliv.git
Explanation of terraform commands is below:
cd terraSlivterraform initterraform fmtterraform planterraform applyPlease wait a few minutes for the bash script to complete after EC2 has been deployed
After you are done, destroy your environment. If not, you will be charged by AWS after your free tier hours are up. Don't tell I didn't tell you...
terraform destroyRename the following "example" to your desired name:
resource "aws_vpc" "example"
resource "aws_internet_gateway" "example"
resource "aws_subnet" "example"
resource "aws_route_table" "example"
resource "aws_route" "default_route"
resource "aws_route_table_association" "example"
resource "aws_security_group" "example"
resource "aws_instance" "example"
value = aws_instance.example.public_ip
Once your have chosen your friendly names, update the associated references in the main.tf file.
Each line below represents a reference that needs to be updated.
vpc_id = aws_vpc.example.id
vpc_id = aws_vpc.example.id
vpc_id = aws_vpc.example.id
route_table_id = aws_route_table.example.id
gateway_id = aws_internet_gateway.example.id
subnet_id = aws_subnet.example.id
route_table_id = aws_route_table.example.id
vpc_id = aws_vpc.example.id
subnet_id = aws_subnet.example.id
aws_security_group.example.id
value = aws_instance.example.public_ip
Modify the security group with your current IP.
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["66.0.0.97/32"] # Change this to your current ip
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["66.0.0.97/32"] # Change this to your current ip
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["66.0.0.97/32"] # Change this to your current ip
}
terraform initis used to initialize a new or existing Terraform project. When you run this command in a directory containing your Terraform configuration files (usually with a main.tf file), Terraform initializes the working directory by downloading any required provider plugins and modules defined in your configuration.
terraform initterraform fmtis used to format (auto-format) your Terraform configuration files to adhere to a consistent and standardized style.
terraform fmtterraform planis used to create an execution plan for your Terraform configuration. When you run this command, Terraform analyzes your configuration and infrastructure state and provides a detailed preview of the changes it's going to make when you apply your configuration.
terraform planterraform applyis used to apply the changes defined in your Terraform configuration to your infrastructure. After runningterraform planand reviewing the execution plan, you can useterraform applyto enact the changes. This command will create, update, or delete resources as specified in your configuration.
terraform apply- USE only to destroy environment
terraform destroyis used to destroy the infrastructure and resources created by your Terraform configuration. When you run this command, Terraform will determine which resources are managed by your configuration and initiate the process of destroying them
terraform destroy