Skip to content

Instantly share code, notes, and snippets.

@acsrujan
Created July 31, 2019 11:57

Revisions

  1. acsrujan created this gist Jul 31, 2019.
    67 changes: 67 additions & 0 deletions mysql_rds.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    resource "aws_security_group" "mydatabase_sg" {
    name = "mydatabase_sg"
    description = "Allows services to talk to mydatabase 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 "dbmydatabase" {
    source = "terraform-aws-modules/rds/aws"
    version = "~> 2.0"

    identifier = "mydatabase"

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

    name = "mydatabase"
    username = "jesus"
    password = "some_strong_password"
    port = "3306"
    vpc_security_group_ids = ["${aws_security_group.maxmind.id}"]

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

    tags = {
    Team = "some_application_team"
    Environment = "production"
    }

    storage_encrypted = true
    multi_az = true

    # DB Subnet IDs
    subnet_ids = ["subnet-xxxx", "subnet-xxxx", "subnet-xxxx"]

    # Snapshot name upon DB deletion
    final_snapshot_identifier = "mydatabase"

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

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