Skip to content

Commit 571d9bc

Browse files
committed
refactor: ♻️ create and use ec2-app module
1 parent 057024e commit 571d9bc

37 files changed

Lines changed: 269 additions & 439 deletions

File tree

html-db-website/aws-ec2/one-instance/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ We choose to use a EC2 instance to showcase the utilization of Ansible along wit
2323
│   └── architecture.dot.png # Generated with https://github.com/patrickchugh/terravision.
2424
├── README.md
2525
└── terraform
26-
├── iam.tf # This is needed for AWS SSM.
27-
├── lb.tf # We are using ALB to expose our web page.
2826
├── main.tf
29-
├── network.tf # At least 2 publics subnets in differents AZ are required for ALB creation. We are using NAT gateway for AWS SSM (and for instance internet connectivity).
3027
├── provider.tf
31-
├── s3.tf # S3 bucket is mandatory for the utilization of Ansible along with AWS SSM.
32-
├── security_group.tf
33-
└── variables.tf
28+
└── outputs.tf
3429
```
3530

3631
## Architecture diagram

html-db-website/aws-ec2/one-instance/ansible/ansible.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ force_color = true
33
roles_path = ./roles
44
collections_path = ./collections
55
inventory = ./inventory/
6-
#stdout_callback = yaml
6+
stdout_callback = ansible.builtin.default
7+
result_format = yaml
78
interpreter_python = auto_silent
89
timeout = 300
910
callbacks_enabled = timer, profile_tasks, profile_roles
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
ansible_connection: amazon.aws.aws_ssm
3-
ansible_aws_ssm_bucket_name: ansible-private-s3-bucket
3+
ansible_aws_ssm_bucket_name: html-db-ansible-bucket
44
ansible_user: ubuntu

html-db-website/aws-ec2/one-instance/terraform/lb.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
data "aws_ami" "ubuntu" {
2-
most_recent = true
3-
4-
filter {
5-
name = "name"
6-
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
7-
}
8-
9-
owners = ["099720109477"] # Canonical
10-
}
11-
12-
resource "aws_instance" "nginx_instance" {
13-
ami = data.aws_ami.ubuntu.id
14-
instance_type = "t3.micro"
15-
availability_zone = "us-east-1a"
16-
subnet_id = module.vpc.private_subnet_objects[0].id
17-
vpc_security_group_ids = [aws_security_group.nginx_sg.id]
18-
associate_public_ip_address = false
19-
iam_instance_profile = aws_iam_instance_profile.ssm.name
20-
instance_initiated_shutdown_behavior = "terminate"
21-
22-
tags = {
23-
Name = "nginx_instance"
24-
Project = "nginx"
25-
}
1+
module "web" {
2+
source = "../../../../terraform-modules/aws/ec2-app"
3+
project = "html-db"
4+
app_port = 8080
5+
s3_bucket_name = "html-db-ansible-bucket"
266
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "website_url" {
22
description = "Public URL of the nginx website via ALB"
3-
value = "http://${module.alb.dns_name}"
3+
value = module.web.website_url
44
}

html-db-website/aws-ec2/one-instance/terraform/s3.tf

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

html-db-website/aws-ec2/one-instance/terraform/security_group.tf

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

html-db-website/aws-ec2/one-instance/terraform/variables.tf

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

html-db-website/aws-ec2/two-instances/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ We choose to use a EC2 instance to showcase the utilization of Ansible along wit
2727
│   └── architecture.dot.png # Generated with https://github.com/patrickchugh/terravision.
2828
├── README.md
2929
└── terraform
30-
├── iam.tf # This is needed for AWS SSM.
31-
├── lb.tf # We are using ALB to expose our web page.
3230
├── main.tf
33-
├── network.tf # At least 2 publics subnets in differents AZ are required for ALB creation. We are using NAT gateway for AWS SSM (and for instance internet connectivity).
3431
├── outputs.tf
35-
├── provider.tf
36-
├── s3.tf # S3 bucket is mandatory for the utilization of Ansible along with AWS SSM.
37-
├── security_group.tf
38-
└── variables.tf
32+
└── provider.tf
3933
```
4034

4135
## Architecture diagram

0 commit comments

Comments
 (0)