Complete the code to create a security group that allows inbound HTTP traffic.
resource "aws_security_group" "web_sg" { name = "web_sg" description = "Allow HTTP inbound" ingress { from_port = 80 to_port = 80 protocol = "[1]" cidr_blocks = ["0.0.0.0/0"] } }
The protocol for HTTP traffic is TCP, so the ingress rule must specify "tcp".
Complete the code to allow SSH access only from a specific IP address.
resource "aws_security_group" "ssh_sg" { name = "ssh_sg" description = "Allow SSH inbound from office" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["[1]"] } }
To restrict SSH access to a single IP, use the IP with /32 mask, like "192.168.1.100/32".
Complete the code to create a security group that allows all inbound traffic.
resource "aws_security_group" "allow_all" { name = "allow_all" description = "Allow all inbound traffic" ingress { from_port = 0 to_port = 0 protocol = "[1]" cidr_blocks = ["0.0.0.0/0"] } }
Using protocol "-1" means all protocols, which is needed to allow all inbound traffic properly.
Fill both blanks to create a security group that allows HTTPS inbound and denies all other inbound traffic.
resource "aws_security_group" "https_only" { name = "https_only" description = "Allow HTTPS inbound only" ingress { from_port = [1] to_port = [2] protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } }
HTTPS uses port 443, so both from_port and to_port must be 443 to allow only HTTPS inbound.
Fill all three blanks to create a security group that allows inbound SSH from a specific IP, HTTP from anywhere, and denies all other inbound traffic.
resource "aws_security_group" "custom_sg" { name = "custom_sg" description = "Allow SSH from office and HTTP from anywhere" ingress { from_port = [1] to_port = [2] protocol = "tcp" cidr_blocks = ["[3]"] } ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } }
SSH uses port 22 for both from_port and to_port, and the CIDR block restricts access to the specific IP.