Automating AWS RDS MySQL creation using Terraform
So far, we have created a MySQL database using the AWS console. In this section, we will learn how to automate the entire process using Terraform. The whole process is divided into four steps:
- We will start with the boilerplate syntax where we specify
aws
asprovider
, and the region where we want to create this database (for example,us-west-2
, which is in Oregon):provider "aws" { Â Â region = "us-west-2" }
- In the next step, you need to specify the database subnet group. This is the subnet group that MySQL uses to create the database instance:
-
name
: This is the name of the subnet group. For example, you could userds-db-subnet
. If you omit this, Terraform will randomly assign some unique name for you.-
subnet_ids
: Here you specify the list of subnet IDs (for example,subnet-07714eb09171b1f7e
andsubnet-0cca9fdeb1b95003c
– these are the subnet IDs fromprod-vpc
):resource "aws_db_subnet_group...