Complete the code to create a managed database instance in AWS.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = "[1]" db_name = "mydatabase" username = "admin" password = "password123" parameter_group_name = "default.mysql5.7" }
The instance_class must specify a valid AWS RDS instance type like db.m5.large for managed databases.
Complete the code to enable automatic backups for the managed database.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = "db.m5.large" db_name = "mydatabase" username = "admin" password = "password123" backup_retention_period = [1] }
The backup_retention_period sets how many days backups are kept. Setting it to 7 enables automatic backups for one week.
Fix the error in the code to enable Multi-AZ deployment for high availability.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = "db.m5.large" db_name = "mydatabase" username = "admin" password = "password123" multi_az = [1] }
The multi_az attribute expects a boolean value true or false, not a string.
Fill both blanks to configure the database to be publicly accessible and set the storage type.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = "db.m5.large" publicly_accessible = [1] storage_type = "[2]" username = "admin" password = "password123" }
Setting publicly_accessible to true allows access from outside the VPC. The storage_type gp2 is a common SSD storage type for better performance.
Fill all three blanks to configure the database with encryption, backup window, and maintenance window.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = "db.m5.large" storage_encrypted = [1] backup_window = "[2]" maintenance_window = "[3]" username = "admin" password = "password123" }
Enabling storage_encrypted with true secures data at rest. The backup_window and maintenance_window specify times in UTC when backups and maintenance occur, respectively.