Moving the database to the RDS

To create the MySQL database, we can use a public module that is available in the official repository found here: https://registry.terraform.io/modules/terraform-aws-modules/rds/aws/1.21.0.

In the following code, I will simplify the original example slightly and add a security group as follows. Refer to the main.tf file:

resource "aws_security_group" "rds" {  name = "allow_from_my_vpc"  description = "Allow from my vpc"  vpc_id = "${var.my_default_vpcid}"  ingress {    from_port = 3306    to_port = 3306    protocol = "tcp"    cidr_blocks = ["172.31.0.0/16"]  }}module "db" {  source = "terraform-aws-modules/rds/aws"  identifier = "demodb"  engine = "mysql"  engine_version = "5.7.19"  instance_class = "db.t2.micro" allocated_storage ...

Get Effective DevOps with AWS - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.