Friday, October 15, 2021

Creating Mysql RDS instance using Terraform

 I have been working on terraform for sometime now and find it very useful , We can create most of the cloud infrastructure using terraform including RDS-MYSQL instances. 

Today i will be posting a simple code to create a MYSQL RDS instance with basic configuration for a beginner.

Create a main.tf file and add the below values in your testing environment. Am assuming AWS access keys are already present in the laptop that is connecting to the AWS environment for access , otherwise terraform will be unable to communicate with AWS.

-------------------------------------------------------

terraform {

 required_providers {

 aws = {

       source = "hashicorp/aws"

      version = "~> 3.27"

       }}}

 provider "aws" {

  profile = "default"

 region = "specify region"

}

resource "aws_db_parameter_group" "default" {

 name = " testnew"

family = "mysql5.7"

}

resource "aws_db_instance" "default" {

identifier =  "testdb"

allocated_storage = 10

engine = "mysql"

engine_version = "5.7"

instance_class = "db.t3.micro"

name = "mydb"

username = "testuser"

password = "Specify password"

parameter_group_name = "newpggroup"

}  


once the above code is complete, run a terraform init, terraform plan to validate the plan and finally terraform apply..

Post this you should see an RDS instance created based on the inputs provided above

This is a very basic example for someone to start with terraform and we can provide many other parameters in the above code. Do refer to terraform documentation for the same 

No comments:

Post a Comment