Skip to content

Commit c42f497

Browse files
added tf
1 parent a47656a commit c42f497

File tree

9 files changed

+90
-44
lines changed

9 files changed

+90
-44
lines changed

aws_module_project/backend_infra.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.

aws_module_project/main.tf

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,36 @@ module "dev-app" {
44
source = "./my_app_infra_module"
55
my_env = "dev"
66
instance_type = "t2.micro"
7-
ami = "ami-007855ac798b5175e"
7+
ami = "ami-0e9085e60087ce171"
88
}
99

1010
#prd
1111
module "prd-app" {
1212
source = "./my_app_infra_module"
1313
my_env = "prd"
1414
instance_type = "t2.medium"
15-
ami = "ami-007855ac798b5175e"
15+
ami = "ami-0e9085e60087ce171"
1616
}
1717

1818
#stg
1919
module "stg-app" {
2020
source = "./my_app_infra_module"
2121
my_env = "stg"
2222
instance_type = "t2.small"
23-
ami = "ami-007855ac798b5175e"
23+
ami = "ami-0e9085e60087ce171"
2424

25+
}
26+
output "dev_app_public_ips" {
27+
value = module.dev-app.ec2_instances_public_ips
28+
description = "Public IPs of the dev environment EC2 instances"
29+
}
30+
31+
output "prd_app_public_ips" {
32+
value = module.prd-app.ec2_instances_public_ips
33+
description = "Public IPs of the prd environment EC2 instances"
34+
}
35+
36+
output "stg_app_public_ips" {
37+
value = module.stg-app.ec2_instances_public_ips
38+
description = "Public IPs of the stg environment EC2 instances"
2539
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "ec2_instances_public_ips" {
2+
value = aws_instance.my_app_server[*].public_ip
3+
description = "Public IP addresses of the EC2 instances"
4+
}

aws_module_project/my_app_infra_module/my_server.tf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
1+
resource "aws_key_pair" "deployer" {
2+
key_name = "${var.my_env}-terra-automate-key"
3+
public_key = file("terra-key.pub")
4+
5+
}
6+
7+
resource "aws_default_vpc" "default" {
8+
9+
}
10+
11+
resource "aws_security_group" "allow_user_to_connect" {
12+
name = "${var.my_env}-allow-TLS"
13+
description = "Allow user to connect"
14+
vpc_id = aws_default_vpc.default.id
15+
ingress {
16+
description = "port 22 allow"
17+
from_port = 22
18+
to_port = 22
19+
protocol = "tcp"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
23+
egress {
24+
description = " allow all outgoing traffic "
25+
from_port = 0
26+
to_port = 0
27+
protocol = "-1"
28+
cidr_blocks = ["0.0.0.0/0"]
29+
}
30+
31+
ingress {
32+
description = "port 80 allow"
33+
from_port = 80
34+
to_port = 80
35+
protocol = "tcp"
36+
cidr_blocks = ["0.0.0.0/0"]
37+
}
38+
39+
ingress {
40+
description = "port 443 allow"
41+
from_port = 443
42+
to_port = 443
43+
protocol = "tcp"
44+
cidr_blocks = ["0.0.0.0/0"]
45+
}
46+
47+
tags = {
48+
Name = "${var.my_env}-mysecurity"
49+
}
50+
}
51+
152
resource "aws_instance" "my_app_server" {
253
count = 2
354
ami = var.ami
455
instance_type = var.instance_type
56+
key_name = aws_key_pair.deployer.key_name
57+
security_groups = [aws_security_group.allow_user_to_connect.name]
58+
root_block_device {
59+
volume_size = 10
60+
volume_type = "gp3"
61+
}
562
tags = {
663
Name = "${var.my_env}-tws-demo-app-server"
764
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHgXqutmPuLFCDk1TAiKgusEp/1E35SFEz+x0GzvUR4e [email protected]

aws_module_project/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
provider "aws" {
2-
region = var.aws_region
2+
region = "eu-west-1"
33
}

aws_module_project/terra-key.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHgXqutmPuLFCDk1TAiKgusEp/1E35SFEz+x0GzvUR4e [email protected]

aws_module_project/terraform.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,4 @@ terraform {
55
version = "4.66.1"
66
}
77
}
8-
backend "s3" {
9-
bucket = "batch3-demo-state-bucket"
10-
key = "terraform.tfstate"
11-
region = "us-east-1"
12-
dynamodb_table = "batch3-demo-state-table"
13-
}
148
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "1.10.0",
4+
"serial": 66,
5+
"lineage": "2ee018c5-3d26-1456-a70f-ba34c882e429",
6+
"outputs": {},
7+
"resources": [],
8+
"check_results": null
9+
}

0 commit comments

Comments
 (0)