RDS with terraform

Engineering Jul 31, 2019

Meant for self reference.

This is a gist of launching an RDS mysql instance with terraform. It uses module from here: https://github.com/terraform-aws-modules/terraform-aws-rds

resource "aws_security_group" "sample-mysql" {
    name        = "sample-mysql"
    description = "Allows services to talk to sample mysql"
    vpc_id      = "vpc-xxxx"

    ingress {
      from_port = 3306
      to_port   = 3306
      protocol  = "TCP"
      self      = true
    }
    egress {
        from_port       = 0
        to_port         = 0
        protocol        = "-1"
        cidr_blocks     = ["0.0.0.0/0"]
    }
}

module "dbsample" {
  source = "terraform-aws-modules/rds/aws"
  version = "~> 2.0"

  identifier = "sample"

  engine            = "mysql"
  engine_version    = "5.7.25"
  instance_class    = "db.t2.small"
  allocated_storage = 10

  name     = "sample"
  username = "randomRootUserName"
  password = "Random#mysqlPassw0rd"
  port     = "3306"

  vpc_security_group_ids = ["${aws_security_group.sample-mysql.id}"]

  maintenance_window = "Mon:00:00-Mon:03:00"
  backup_window      = "03:00-06:00"

  tags = {
    Environment = "production"
  }

  storage_encrypted = true
  multi_az = true

  # DB Subnet IDs
  subnet_ids = ["subnet-xx", "subnet-yy", "subnet-zz"]

  # Snapshot name upon DB deletion
  final_snapshot_identifier = "sampleSnapshot"

  major_engine_version = "5.7"
  family = "mysql5.7"

  parameters = [
    {
      name  = "character_set_client"
      value = "utf8"
    },
    {
      name  = "character_set_server"
      value = "utf8"
    }
  ]
}

Srujan

You should go to about section on this site.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.