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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.