Review the Infrastructure code for web app deployment

0

Hi AWS, I have to deploy a web application that supports the following design:

1.The end-users only contact the load balancers and the underlying instance are accessed for management purposes, design a security group scheme which supports the minimal set of ports required for communication. 2. The AWS generated load balancer hostname with be used for request to the public facing web application.

I have to write the terraform code for the same. I wrote the code for Security Group but I am not sure if it is sufficing the requirements asked or not. Here is the code snippet:

resource "aws_security_group" "client_alb" {
  name_prefix = "${var.default_tags.project_name}-alb"
  description = "security group for web application load balancer"
  vpc_id      = aws_vpc.main.id
  tags = {
    Name = "${var.default_tags.project_name}-sg"
  }
}

resource "aws_security_group_rule" "client_alb_allow_80" {
  security_group_id = aws_security_group.client_alb.id
  type              = "ingress"
  protocol          = "tcp"
  from_port         = 80
  to_port           = 80
  cidr_blocks       = ["0.0.0.0/0"]
  ipv6_cidr_blocks  = ["::/0"]
  description       = "Allow HTTP traffic."
}

resource "aws_security_group_rule" "client_alb_allow_443" {
  security_group_id = aws_security_group.client_alb.id
  type              = "ingress"
  protocol          = "tcp"
  from_port         = 443
  to_port           = 443
  cidr_blocks       = ["0.0.0.0/0"]
  ipv6_cidr_blocks  = ["::/0"]
  description       = "Allow HTTP traffic."
}

resource "aws_security_group_rule" "client_alb_allow_outbound" {
  security_group_id = aws_security_group.client_alb.id
  type              = "egress"
  protocol          = "-1"
  from_port         = 0
  to_port           = 0
  cidr_blocks       = ["0.0.0.0/0"]
  ipv6_cidr_blocks  = ["::/0"]
  description       = "Allow any outbound traffic."
}

Could someone please review and help me with point 2 as well?

2 Answers
0

You have shown the TF for the sg but you have shown us the code for the alb or EC2’s.

However the TF looks good if these are only used on the alb.

The alb resource will return the DNS name as an output along with the dns zone id.

profile picture
EXPERT
answered 2 months ago
  • I wrote the code for EC2 Security Groups. This is the complete requirement:

    1. The end-users only contact the load balancers and the underlying instance are accessed for management purposes, design a security group scheme which supports the minimal set of ports required for communication.
    2. The AWS generated load balancer hostname with be used for request to the public facing web application.
    3. An autoscaling group should be created which utilizes the latest AWS AMI
    4. The instance in the ASG Must contain both a root volume to store the application / services and must contain a secondary volume meant to store any log data bound from / var/log Must include a web server of your choice.
    5. Configure web application using Ansible, all requirements in this task of configuring the operating system should be defined in the launch configuration and/or the user data script
    6. Create self signed certificate for test.example.com and used this hostname with Load balancer, this dns should be resolve internally within VPC network with route 53 private hosted zone.
  • Hi @Gary, I have listed down the requirements that I have been given. Can you please review and help me in figuring things out?

0

Hello, Arjun

Regarding 2nd could explain me a little bit more?

Thanks

answered 2 months ago
  • The alb needs an outbound rule to connect to the resources in question. Ie ec2

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions