Complete the code to enable encryption for the RDS instance.
resource "aws_db_instance" "example" { allocated_storage = 20 engine = "mysql" instance_class = "db.t3.micro" name = "mydb" username = "admin" password = "password" parameter_group_name = "default.mysql8.0" storage_encrypted = [1] }
Setting storage_encrypted to true enables encryption for the RDS instance storage.
Complete the code to allow inbound MySQL traffic on port 3306 in the security group.
resource "aws_security_group_rule" "mysql_inbound" { type = "ingress" from_port = 3306 to_port = 3306 protocol = "[1]" security_group_id = aws_security_group.db_sg.id cidr_blocks = ["0.0.0.0/0"] }
MySQL uses TCP protocol on port 3306, so the protocol must be set to tcp.
Fix the error in the security group rule to restrict access only from a specific IP.
resource "aws_security_group_rule" "restricted_access" { type = "ingress" from_port = 5432 to_port = 5432 protocol = "tcp" security_group_id = aws_security_group.db_sg.id cidr_blocks = ["[1]"] }
To restrict access to a single IP, use the IP address with a /32 mask, like 192.168.1.100/32.
Fill both blanks to create a security group rule that allows inbound HTTPS traffic only from a specific security group.
resource "aws_security_group_rule" "https_inbound" { type = "ingress" from_port = 443 to_port = 443 protocol = "tcp" security_group_id = aws_security_group.app_sg.id [1] = aws_security_group.web_sg.id [2] = [] }
To allow traffic from another security group, use source_security_group_id with the group's ID, and set cidr_blocks to an empty list to avoid conflicts.
Fill all three blanks to define an encrypted RDS instance with a security group allowing inbound traffic only from a trusted IP range.
resource "aws_db_instance" "secure_db" { allocated_storage = 50 engine = "postgres" instance_class = "db.t3.medium" name = "securedb" username = "admin" password = "securepass" storage_encrypted = [1] vpc_security_group_ids = [[2]] } resource "aws_security_group" "db_sg" { name = "db_sg" description = "Allow trusted IPs" vpc_id = "vpc-123456" } resource "aws_security_group_rule" "trusted_ip_rule" { type = "ingress" from_port = 5432 to_port = 5432 protocol = "tcp" security_group_id = aws_security_group.db_sg.id cidr_blocks = ["[3]"] }
Encryption is enabled by setting storage_encrypted to true. The RDS instance must reference the security group ID in vpc_security_group_ids. The security group rule restricts access to the trusted IP range 10.0.0.0/24.