summaryrefslogtreecommitdiff
path: root/playground/ec2-instance-test
diff options
context:
space:
mode:
Diffstat (limited to 'playground/ec2-instance-test')
-rw-r--r--playground/ec2-instance-test/main.tf116
-rw-r--r--playground/ec2-instance-test/network.tf114
2 files changed, 114 insertions, 116 deletions
diff --git a/playground/ec2-instance-test/main.tf b/playground/ec2-instance-test/main.tf
index 8147f2e..7c9d166 100644
--- a/playground/ec2-instance-test/main.tf
+++ b/playground/ec2-instance-test/main.tf
@@ -19,122 +19,6 @@ resource "aws_key_pair" "id_rsa_pub" {
public_key = file("${path.module}/id_rsa.pub")
}
-
-resource "aws_vpc" "my_vpc" {
- cidr_block = "10.0.0.0/16" # Specify your CIDR block
- enable_dns_support = true
- enable_dns_hostnames = true
-
- tags = {
- Name = "${var.environment}-my-vpc"
- }
-}
-
-resource "aws_internet_gateway" "my_igw" {
- vpc_id = aws_vpc.my_vpc.id
-
- tags = {
- Name = "${var.environment}-my-igw"
- }
-}
-
-resource "aws_subnet" "my_public_subnet" {
- vpc_id = aws_vpc.my_vpc.id # Referencing the VPC
- cidr_block = "10.0.1.0/24" # Specify your CIDR block for the subnet
- availability_zone = "eu-central-1a" # Change to your desired AZ
- map_public_ip_on_launch = true
-
- tags = {
- Name = "${var.environment}-my-subnet"
- }
-}
-
-resource "aws_route_table" "my_route_table" {
- vpc_id = aws_vpc.my_vpc.id
-
- route {
- cidr_block = "0.0.0.0/0"
- gateway_id = aws_internet_gateway.my_igw.id
- }
-
- tags = {
- Name = "${var.environment}-my-route-table"
- }
-}
-
-resource "aws_route_table_association" "a" {
- subnet_id = aws_subnet.my_public_subnet.id
- route_table_id = aws_route_table.my_route_table.id
-}
-
-resource "aws_security_group" "allow_ssh" {
- name = "allow_ssh"
- description = "Allow SSH inbound traffic"
- vpc_id = aws_vpc.my_vpc.id
-
- ingress {
- from_port = 22
- to_port = 22
- protocol = "tcp"
- cidr_blocks = ["0.0.0.0/0"]
- }
-
- tags = {
- Name = "${var.environment}-allow-ssh"
- }
-}
-
-resource "aws_security_group" "allow_http" {
- name = "allow_http"
- description = "Allow HTTP inbound traffic"
- vpc_id = aws_vpc.my_vpc.id
-
- ingress {
- from_port = 80
- to_port = 80
- protocol = "tcp"
- cidr_blocks = ["0.0.0.0/0"]
- }
-
- tags = {
- Name = "${var.environment}-allow_http"
- }
-}
-
-resource "aws_security_group" "allow_https" {
- name = "allow_https"
- description = "Allow HTTPS inbound traffic"
- vpc_id = aws_vpc.my_vpc.id
-
- ingress {
- from_port = 443
- to_port = 443
- protocol = "tcp"
- cidr_blocks = ["0.0.0.0/0"]
- }
-
- tags = {
- Name = "${var.environment}-allow-https"
- }
-}
-
-resource "aws_security_group" "allow_outbound" {
- name = "allow_outbound"
- description = "Allow outbound traffic"
- vpc_id = aws_vpc.my_vpc.id
-
- egress {
- from_port = 0
- to_port = 0
- protocol = "-1" # -1 means all protocols
- cidr_blocks = ["0.0.0.0/0"] # Allows outbound traffic to all IP addresses
- }
-
- tags = {
- Name = "${var.environment}-allow-outnound"
- }
-}
-
data "template_file" "user_data" {
template = file("${path.module}/user_data.tpl")
diff --git a/playground/ec2-instance-test/network.tf b/playground/ec2-instance-test/network.tf
new file mode 100644
index 0000000..94cd9d9
--- /dev/null
+++ b/playground/ec2-instance-test/network.tf
@@ -0,0 +1,114 @@
+resource "aws_vpc" "my_vpc" {
+ cidr_block = "10.0.0.0/16" # Specify your CIDR block
+ enable_dns_support = true
+ enable_dns_hostnames = true
+
+ tags = {
+ Name = "${var.environment}-my-vpc"
+ }
+}
+
+resource "aws_internet_gateway" "my_igw" {
+ vpc_id = aws_vpc.my_vpc.id
+
+ tags = {
+ Name = "${var.environment}-my-igw"
+ }
+}
+
+resource "aws_subnet" "my_public_subnet" {
+ vpc_id = aws_vpc.my_vpc.id # Referencing the VPC
+ cidr_block = "10.0.1.0/24" # Specify your CIDR block for the subnet
+ availability_zone = "eu-central-1a" # Change to your desired AZ
+ map_public_ip_on_launch = true
+
+ tags = {
+ Name = "${var.environment}-my-subnet"
+ }
+}
+
+resource "aws_route_table" "my_route_table" {
+ vpc_id = aws_vpc.my_vpc.id
+
+ route {
+ cidr_block = "0.0.0.0/0"
+ gateway_id = aws_internet_gateway.my_igw.id
+ }
+
+ tags = {
+ Name = "${var.environment}-my-route-table"
+ }
+}
+
+resource "aws_route_table_association" "a" {
+ subnet_id = aws_subnet.my_public_subnet.id
+ route_table_id = aws_route_table.my_route_table.id
+}
+
+resource "aws_security_group" "allow_ssh" {
+ name = "allow_ssh"
+ description = "Allow SSH inbound traffic"
+ vpc_id = aws_vpc.my_vpc.id
+
+ ingress {
+ from_port = 22
+ to_port = 22
+ protocol = "tcp"
+ cidr_blocks = ["0.0.0.0/0"]
+ }
+
+ tags = {
+ Name = "${var.environment}-allow-ssh"
+ }
+}
+
+resource "aws_security_group" "allow_http" {
+ name = "allow_http"
+ description = "Allow HTTP inbound traffic"
+ vpc_id = aws_vpc.my_vpc.id
+
+ ingress {
+ from_port = 80
+ to_port = 80
+ protocol = "tcp"
+ cidr_blocks = ["0.0.0.0/0"]
+ }
+
+ tags = {
+ Name = "${var.environment}-allow_http"
+ }
+}
+
+resource "aws_security_group" "allow_https" {
+ name = "allow_https"
+ description = "Allow HTTPS inbound traffic"
+ vpc_id = aws_vpc.my_vpc.id
+
+ ingress {
+ from_port = 443
+ to_port = 443
+ protocol = "tcp"
+ cidr_blocks = ["0.0.0.0/0"]
+ }
+
+ tags = {
+ Name = "${var.environment}-allow-https"
+ }
+}
+
+resource "aws_security_group" "allow_outbound" {
+ name = "allow_outbound"
+ description = "Allow outbound traffic"
+ vpc_id = aws_vpc.my_vpc.id
+
+ egress {
+ from_port = 0
+ to_port = 0
+ protocol = "-1" # -1 means all protocols
+ cidr_blocks = ["0.0.0.0/0"] # Allows outbound traffic to all IP addresses
+ }
+
+ tags = {
+ Name = "${var.environment}-allow-outnound"
+ }
+}