RDS MariaDB Database and Resource Tags

This is the continuation of a Terraform demo to create a VPC in AWS with an EC2 instance connected to MariaDB database running in RDS (Amazon Relational Database Service) using a single Terraform plan. Operating System and software configuration is done using Ansible after the infrastructure has been created.

Continue the demo, see:

Download de the code from IT Wonder Lab public GitHub repository.

Configuring a RDS MariaDB Database with Terraform

I am a big fan of AWS RDS databases as you can access a ready to use database that is backed by AWS experience and has administration tools that are easy to use.

IT Wonder Lab recommendation is to use Cloud services as much as possible and focus all your resources and energy in configuring and developing what is really disruptive and unique.

In my opinion the only reason not to use a RDS database is if you have requirements that are not available in RDS, but even then, Do you really need those requirement?  ar you so unique? or aren’t those requirements going to be included in standardized services once you are done developing?

The AWS RDS database is fully configured in the terraform.tfvars file.

Following IT Wonder Lab best practices the RDS elements will be named following a pattern:

  • Cloud: a prefix specifying the unique name of this cloud across all available clouds and providers. In this case the prefix will be: ditwl that stands for Demo ITWonder Lab in lowercase.
  • Resource: a short name identifying the resource, in this case:
    • rds-mariadb: for RDS MariaDB type of resource
    • sg-rds-mariadbfor RDS Security Group for MariaBD type of resource
    • sr-rds-mariadbfor RDS Security Rule for MariaBD type of resource
  • Environment: for resources that are not to be shared between environments, a 3 letter acronym for the environment:
    • pro: production
    • pre: preproduction
    • dev: development
  • Visibility: for resources that can be either public or private, a 3 letter acronym for the visibility:
    • pub: for public resources
    • pri: for private resources
  • Name/ID: optional a name or ID that describes the usage of the resource or the number of the resource instance, for example:
    • DB resource number: this will be the RDS MariaDB 01 for Public Zones and Pro Environment. We might have new RDS DB on the future, adding a number now will make it easier to grow the infrastructure later on.
    • DB security group number: this will be the RDS MariaDB security group 01 for Public Zones and Pro Environment. We might have new security groups on the future, adding a number now will make it easier to grow the infrastructure later on.
    • Description of the purpose of the rule: using a description like instances_to_db_port explains the intended usage of the rule. In this case it is a rule to allow access from the EC2 instances to the RDS Database port.

Be aware of the password in clear text in terraform.tfvars. It will also show in terraform.tftstate and terraform.tfstate.backup.  Currently the recommended action for passwords in Terraform files is to change them after resource creation using a different tool (AWS cli, AWS Console, Ansible, DB Client …) . A changed password in Terraform doesn’t trigger a resource property change.

aws_rds_pro_mariadb_01.tf is used to create the security group, assign the security rule and launch the database.

A work around is used to create a dependency between the RDS subnet group and the RDS database. See RDS subnet group creation in part II (VPC/RDS Sub Nets).

In order to launch the RDS database the subnet needs to exist, we provide the name of the RDS subnet using the output ID of the RDS subnet as source, this way Terraform is forced to create the RDS subnet first in order to evaluate the output ID.

Tagging AWS RDS Databases in Terraform

Tags can be used to identify resources, split cost between cost centers, and for further configuration and provisioning with dynamic inventories.

IT Wonder Lab recommends adding at least these tags to all resources.

  • Private Name: The private name for this element, it is used for DNS registration in private zone and should follow a standard and be unique. It can be used for monitoring and server naming.
  • Public Name: The public name for the element, it can be used in DNS registration in public zones and can be the same for many instances, as instances can be behind load balancers. In RDS it is the same as the private name.
  • App: The name of the main application that will be used in the resource.
  • App ID: A unique characteristic of the application or a number that can be used to differentiate multiple different instances of the same application, for example imagine you have to releases of the same application in the same environment, App ID could be the release number.
  • OS: The operating system of the instance, useful for applying basic configuration.
  • Environment: Used for environment identification, it is a 3 letter acronym for the environment:
  • Cost Center:  one or many cost centers that this resource should be assigned to. The cost center is used in billing to classify resources, for example if you provide resources for different customers, some resources are shared and other are costs associated to a specific customer.

Values should all be in lowercase without spaces.

Example:

terraform-aws-ec2-rds-basic-free - ITWL_AWS_Terraform_VPC_WP_RDS_tags.png

Continue the demo, see:


Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of