Skip to content

Commit 8f6126f

Browse files
committed
fix errors
1 parent 4057299 commit 8f6126f

3 files changed

Lines changed: 226 additions & 3 deletions

File tree

.github/workflows/python-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a single version of Python
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
33

4-
name: Python application
4+
name: Python application Testing
55

66
on:
77
push:

compose.yaml renamed to docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ version: '3.8'
33
services:
44
db:
55
image: postgres:15.0
6-
platform: linux/amd64
76
# volumes:
87
# - ~/volumes/jhipster/baseapi/postgresql/:/var/lib/postgresql/data/
98
environment:
@@ -16,7 +15,6 @@ services:
1615
- 127.0.0.1:5432:5432
1716
app:
1817
image: maxiplux/fastapidevops-auth:latest
19-
platform: linux/amd64
2018
container_name: app
2119
restart: on-failure
2220
depends_on:

main.tf

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.0"
6+
}
7+
}
8+
}
9+
10+
11+
resource "tls_private_key" "ssh" {
12+
algorithm = "RSA"
13+
rsa_bits = "4096"
14+
}
15+
16+
resource "aws_key_pair" "generated_key" {
17+
key_name = "terraform-pem-ansible-dec04"
18+
public_key = tls_private_key.ssh.public_key_openssh
19+
20+
21+
}
22+
23+
resource "local_file" "private_key" {
24+
content = tls_private_key.ssh.private_key_pem
25+
filename = "terraform-pem-ansible-dec04.pem"
26+
file_permission = "0600"
27+
}
28+
29+
30+
31+
# Configure the AWS Provider
32+
provider "aws" {
33+
region = "us-east-1"
34+
}
35+
36+
resource "aws_vpc" "terraform_vpc" {
37+
cidr_block = "172.16.0.0/16"
38+
enable_dns_hostnames = "true"
39+
40+
tags = {
41+
Name = "Terraform"
42+
}
43+
}
44+
resource "aws_internet_gateway" "terraform_vpc_internet_gateway" {
45+
vpc_id = aws_vpc.terraform_vpc.id
46+
tags = {
47+
Name = "Terraform"
48+
}
49+
}
50+
resource "aws_route_table" "terraform_aws_route_table" {
51+
vpc_id = aws_vpc.terraform_vpc.id
52+
route {
53+
cidr_block = "0.0.0.0/0"
54+
gateway_id = aws_internet_gateway.terraform_vpc_internet_gateway.id
55+
}
56+
}
57+
58+
59+
60+
resource "aws_subnet" "terraform_subnet" {
61+
vpc_id = aws_vpc.terraform_vpc.id
62+
cidr_block = "172.16.10.0/24"
63+
availability_zone = "us-east-1a"
64+
map_public_ip_on_launch = true
65+
66+
tags = {
67+
Name = "Terraform"
68+
}
69+
}
70+
resource "aws_eip" "terraform_eip" {
71+
vpc = true
72+
tags = {
73+
Name = "Terraform"
74+
}
75+
}
76+
resource "aws_nat_gateway" "terraform_aws_nat_gateway" {
77+
allocation_id = aws_eip.terraform_eip.id
78+
subnet_id = aws_subnet.terraform_subnet.id
79+
tags = {
80+
Name = "Terraform"
81+
}
82+
depends_on = [ aws_internet_gateway.terraform_vpc_internet_gateway ]
83+
84+
}
85+
86+
87+
88+
resource "aws_route_table_association" "terraform_aws_route_table_association" {
89+
subnet_id = aws_subnet.terraform_subnet.id
90+
route_table_id = aws_route_table.terraform_aws_route_table.id
91+
}
92+
93+
resource "aws_network_interface" "terraform_network_interface" {
94+
subnet_id = aws_subnet.terraform_subnet.id
95+
private_ips = ["172.16.10.100"]
96+
97+
tags = {
98+
Name = "Terraform",
99+
}
100+
}
101+
102+
# ------------------------------------------------------
103+
# Define un grupo de seguridad con acceso al puerto 8080
104+
# ------------------------------------------------------
105+
resource "aws_security_group" "terraform_security_group" {
106+
name = "terraform_security_group-sg"
107+
vpc_id = aws_vpc.terraform_vpc.id
108+
ingress {
109+
cidr_blocks = ["0.0.0.0/0"]
110+
ipv6_cidr_blocks = ["::/0"]
111+
description = "HTTP access"
112+
from_port = 8080
113+
to_port = 8080
114+
protocol = "TCP"
115+
}
116+
117+
118+
119+
egress {
120+
from_port = 0
121+
to_port = 0
122+
protocol = "-1"
123+
cidr_blocks = ["0.0.0.0/0"]
124+
}
125+
126+
tags = {
127+
Name = "Terraform",
128+
}
129+
}
130+
131+
132+
133+
resource "aws_security_group" "terraform_security_icmp_group" {
134+
name = "terraform_security_group-icmp-sg"
135+
vpc_id = aws_vpc.terraform_vpc.id
136+
ingress {
137+
//cidr_blocks = ["0.0.0.0/0"]
138+
description = "Acceso al puerto ICMP desde el exterior"
139+
140+
from_port = -1
141+
to_port = -1
142+
protocol = "icmp"
143+
cidr_blocks = ["0.0.0.0/0"]
144+
ipv6_cidr_blocks = ["::/0"]
145+
}
146+
tags = {
147+
Name = "Terraform",
148+
}
149+
}
150+
151+
resource "aws_security_group" "terraform_security_ssh_group" {
152+
name = "terraform_security_ssh_group-sg"
153+
vpc_id = aws_vpc.terraform_vpc.id
154+
ingress {
155+
cidr_blocks = ["0.0.0.0/0"]
156+
description = "Acceso al puerto 22 desde el exterior"
157+
from_port = 22
158+
to_port = 22
159+
protocol = "TCP"
160+
}
161+
162+
tags = {
163+
Name = "Terraform",
164+
}
165+
}
166+
provider "tls" {}
167+
168+
169+
170+
resource "aws_instance" "terraform_instance_master" {
171+
ami = "ami-053b0d53c279acc90"
172+
key_name = aws_key_pair.generated_key.key_name
173+
174+
instance_type = "t2.micro"
175+
subnet_id = aws_subnet.terraform_subnet.id
176+
177+
178+
vpc_security_group_ids = [aws_security_group.terraform_security_icmp_group.id,aws_security_group.terraform_security_group.id, aws_security_group.terraform_security_ssh_group.id]
179+
tags = {
180+
Name = "Master",
181+
}
182+
user_data = <<-EOF
183+
#!/bin/bash
184+
sudo apt update -y
185+
sudo apt-get install ec2-instance-connect wget -y
186+
sudo apt-get install ca-certificates curl
187+
sudo install -m 0755 -d /etc/apt/keyrings
188+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
189+
sudo chmod a+r /etc/apt/keyrings/docker.asc
190+
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git -y
191+
git clone
192+
193+
194+
195+
196+
197+
198+
199+
200+
sudo bash -c 'echo your very first web server > /var/www/html/index.html'
201+
EOF
202+
}
203+
204+
205+
206+
output "server_private_ip" {
207+
value = [aws_instance.terraform_instance_master.private_ip]
208+
}
209+
210+
output "server_public_dns" {
211+
value = [aws_instance.terraform_instance_master.public_dns]
212+
}
213+
214+
output "server_public_ipv4" {
215+
value = [aws_instance.terraform_instance_master.public_ip]
216+
}
217+
output "server_id" {
218+
value = [aws_instance.terraform_instance_master.id]
219+
}
220+
221+
//terraform output -raw private_key > terraform.pem
222+
output "private_key" {
223+
value = tls_private_key.ssh.private_key_pem
224+
sensitive = true
225+
}

0 commit comments

Comments
 (0)