SlideShare a Scribd company logo
Terraforming RDS
● What are RDS and Terraform?
● Why does managing RDS with
Terraform suck?
● Why do I highly recommend
managing RDS with
Terraform?
What is RDS?
What is RDS?
What is Terraform?
What is Terraform?
Abstraction
Abstraction
Terraform and RDS defaults
resource "aws_db_instance" "muffy-test" {
allocated_storage = 100
db_subnet_group_name = "db-subnetgrp"
engine = "postgres"
engine_version = "11.5"
identifier = "muffy-test"
instance_class = "db.m5.large"
password = "password"
skip_final_snapshot = true
storage_encrypted = true
username = "postgres"
}
# aws_db_instance.muffy-test will be created
+ resource "aws_db_instance" "muffy-test" {
+ address = (known after apply)
+ allocated_storage = 100
+ apply_immediately = (known after apply)
. . .
+ skip_final_snapshot = true
+ status = (known after apply)
+ storage_encrypted = true
storage_type = "gp2"
username = "postgres"
vpc_security_group_ids = [
"sg-81f064e5",
]
}
Terraform and RDS defaults
# aws_db_instance.muffy-test:
resource "aws_db_instance" "muffy-test" {
address = "muffy-test.....com"
allocated_storage = 100
arn = "arn:...:muffy-test"
auto_minor_version_upgrade = true
availability_zone = "us-east-1b"
backup_retention_period = 0
backup_window = "04:40-05:10"
ca_cert_identifier = "rds-ca-2019"
copy_tags_to_snapshot = false
db_subnet_group_name = "db-subnetgrp"
delete_automated_backups = true
deletion_protection = false
endpoint = "muffy-test...:5432"
engine = "postgres"
engine_version = "11.5"
hosted_zone_id = "Z2R2ITUGPM61AM"
iam_database_authentication_enabled = false
id = "muffy-test"
identifier = "muffy-test"
instance_class = "db.m5.large"
iops = 0
kms_key_id = "arn:...:key/..."
license_model = "postgresql-license"
maintenance_window = "sat:08:12-sat:08:42"
max_allocated_storage = 0
monitoring_interval = 0
multi_az = false
option_group_name = "default:postgres-11"
parameter_group_name = "default.postgres11"
password = (sensitive value)
performance_insights_enabled = false
performance_insights_retention_period = 0
port = 5432
publicly_accessible = false
replicas = []
resource_id = "db-EJHF7...W6VLWRE"
skip_final_snapshot = true
status = "available"
storage_encrypted = true
storage_type = "gp2"
username = "postgres"
vpc_security_group_ids = [
"sg-81f064e5",
]
}
Applying changes
resource "aws_db_instance" "muffy-test" {
allocated_storage = 16000
apply_immediately = false
[...]
}
# aws_db_instance.muffy-test will be updated
in-place
~ resource "aws_db_instance" "muffy-test" {
~ allocated_storage = 100 -> 16000
+ apply_immediately = false
}
. . .
aws_db_instance.muffy-test: Modifying...
[id=muffy-test]
...muffy-test: Modifications complete after 32s
[id=muffy-test]
Apply complete! Resources: 0 added, 1 changed, 0
destroyed.
Parameter groups
# aws_db_parameter_group.muffy-pg must be
replaced
-/+ resource "aws_db_parameter_group"
"muffy-pg" {
description = "Managed by Terraform"
~ family = "postgres9.6" ->
"postgres11" # forces replacement
}
aws_db_parameter_group.muffy-pg: Destroying...
[id=terraform-20200115031710299600000001]
. . .
[id=terraform-20200115031710299600000001, 2m50s
elapsed]
Error: Error deleting DB parameter group:
InvalidDBParameterGroupState: One or more
database instances are still members of this
parameter group
terraform-20200115031710299600000001, so the
group cannot be deleted
status code: 400, request id:
0e99a7be-4b2d-43d7-ac96-5b18af81c307
Parameter apply_method
resource "aws_db_parameter_group" "muffy-pg"
{
family = "postgres11"
parameter {
apply_method = "immediate"
name = "autovacuum_naptime"
value = "30"
}
parameter {
apply_method = "pending-reboot"
name = "autovacuum_max_workers"
value = "15"
}
}
# aws_db_parameter_group.muffy-pg will be
updated in-place
~ resource "aws_db_parameter_group" "muffy-pg" {
+ parameter {
+ apply_method = "immediate"
+ name = "autovacuum_naptime"
+ value = "30"
}
- parameter {
- apply_method = "immediate" -> null
- name = "autovacuum_naptime" -> null
- value = "15" -> null
}
}
Plans aside
# aws_db_parameter_group.muffy-pg will be updated
in-place
~ resource "aws_db_parameter_group" "muffy-pg" {
[...]
+ parameter {
+ apply_method = "immediate"
+ name = "autovacuum_naptime"
+ value = "30"
}
- parameter {
- apply_method = "immediate" -> null
- name = "autovacuum_naptime" -> null
- value = "15" -> null
}
parameter {
apply_method = "pending-reboot"
name = "autovacuum_max_workers"
value = "15"
}
}
A real pain
What’s the real value?
# PostgreSQL 9.6
postgres=> select name, setting, unit
from pg_settings where name =
'max_wal_size';
name | setting | unit
--------------+---------+------
max_wal_size | 128 | 16MB
(1 row)
postgres=> show max_wal_size;
max_wal_size
--------------
2GB
(1 row)
# PostgreSQL 10
postgres=> select name, setting, unit from
pg_settings where name =
'max_wal_size';
name | setting | unit
--------------+---------+------
max_wal_size | 128 | MB
(1 row)
postgres=> show max_wal_size;
max_wal_size
--------------
12MB
(1 row)
Modules: Good or evil?
Terraform and RDS: Do it!
Muffy Barkocy
muffybarkocy@gmail.com
twitter.com/muffyb

More Related Content

PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
PDF
Ground Control to Nomad Job Dispatch
PDF
HashiCorp Vault configuration as code via HashiCorp Terraform- stories from t...
PPTX
Dive into DevOps | March, Building with Terraform, Volodymyr Tsap
PPTX
Nomad + Flatcar: a harmonious marriage of lightweights
PPTX
Creating Reusable Puppet Profiles
PDF
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
PDF
Static Typing in Vault
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Ground Control to Nomad Job Dispatch
HashiCorp Vault configuration as code via HashiCorp Terraform- stories from t...
Dive into DevOps | March, Building with Terraform, Volodymyr Tsap
Nomad + Flatcar: a harmonious marriage of lightweights
Creating Reusable Puppet Profiles
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
Static Typing in Vault

What's hot (20)

PPTX
DataStax: An Introduction to DataStax Enterprise Search
PDF
Hive dirty/beautiful hacks in TD
PDF
Observability with Consul Connect
PPTX
Terraform day03
ODP
Meetup cassandra for_java_cql
ODP
Integrating icinga2 and the HashiCorp suite
PDF
Cassandra Community Webinar: Apache Cassandra Internals
PDF
MySQL under the siege
PDF
Deploying Docker Containers at Scale with Mesos and Marathon
PDF
Bulk Loading Data into Cassandra
PDF
Terraform Cosmos DB
PDF
Azure Large Scale Deployments - Tales from the Trenches
ODP
Meetup cassandra sfo_jdbc
PDF
Slow Database in your PHP stack? Don't blame the DBA!
PDF
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
PPTX
Building and Deploying Application to Apache Mesos
PDF
2013 05-openstack-israel-heat
PDF
Hazelcast
PDF
PHP and databases
PDF
Data Analytics Service Company and Its Ruby Usage
DataStax: An Introduction to DataStax Enterprise Search
Hive dirty/beautiful hacks in TD
Observability with Consul Connect
Terraform day03
Meetup cassandra for_java_cql
Integrating icinga2 and the HashiCorp suite
Cassandra Community Webinar: Apache Cassandra Internals
MySQL under the siege
Deploying Docker Containers at Scale with Mesos and Marathon
Bulk Loading Data into Cassandra
Terraform Cosmos DB
Azure Large Scale Deployments - Tales from the Trenches
Meetup cassandra sfo_jdbc
Slow Database in your PHP stack? Don't blame the DBA!
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
Building and Deploying Application to Apache Mesos
2013 05-openstack-israel-heat
Hazelcast
PHP and databases
Data Analytics Service Company and Its Ruby Usage
Ad

Similar to Terraforming RDS (20)

PDF
A Hands-on Introduction on Terraform Best Concepts and Best Practices
PPTX
Terraform infraestructura como código
PPTX
AWS Cost Control
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
PPTX
Amazon RDS for PostgreSQL - PGConf 2016
PDF
Workshop Infrastructure as Code - Suestra
PDF
Migrating and living on rds aurora
PPTX
Debasihish da final.ppt
PPTX
Iniciando com Terraform
PDF
Terraform -- Infrastructure as Code
PPTX
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
PDF
Refactoring Infrastructure Code
PDF
Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference...
PDF
Building infrastructure as code using Terraform - DevOps Krakow
PDF
Incrementalism: An Industrial Strategy For Adopting Modern Automation
PPTX
Terraform at Scale
PDF
Refactoring terraform
PDF
Declarative & workflow based infrastructure with Terraform
PPTX
Amazon RDS for PostgreSQL - Postgres Open 2016 - New Features and Lessons Lea...
PDF
Fullstack conf 2017 - Basic dev pipeline end-to-end
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Terraform infraestructura como código
AWS Cost Control
Infrastructure-as-code: bridging the gap between Devs and Ops
Amazon RDS for PostgreSQL - PGConf 2016
Workshop Infrastructure as Code - Suestra
Migrating and living on rds aurora
Debasihish da final.ppt
Iniciando com Terraform
Terraform -- Infrastructure as Code
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Refactoring Infrastructure Code
Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference...
Building infrastructure as code using Terraform - DevOps Krakow
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Terraform at Scale
Refactoring terraform
Declarative & workflow based infrastructure with Terraform
Amazon RDS for PostgreSQL - Postgres Open 2016 - New Features and Lessons Lea...
Fullstack conf 2017 - Basic dev pipeline end-to-end
Ad

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Well-logging-methods_new................
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
Structs to JSON How Go Powers REST APIs.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Arduino robotics embedded978-1-4302-3184-4.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Well-logging-methods_new................
Model Code of Practice - Construction Work - 21102022 .pdf
573137875-Attendance-Management-System-original
CYBER-CRIMES AND SECURITY A guide to understanding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech
Mechanical Engineering MATERIALS Selection
Strings in CPP - Strings in C++ are sequences of characters used to store and...
OOP with Java - Java Introduction (Basics)
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd

Terraforming RDS

  • 2. ● What are RDS and Terraform? ● Why does managing RDS with Terraform suck? ● Why do I highly recommend managing RDS with Terraform?
  • 9. Terraform and RDS defaults resource "aws_db_instance" "muffy-test" { allocated_storage = 100 db_subnet_group_name = "db-subnetgrp" engine = "postgres" engine_version = "11.5" identifier = "muffy-test" instance_class = "db.m5.large" password = "password" skip_final_snapshot = true storage_encrypted = true username = "postgres" } # aws_db_instance.muffy-test will be created + resource "aws_db_instance" "muffy-test" { + address = (known after apply) + allocated_storage = 100 + apply_immediately = (known after apply) . . . + skip_final_snapshot = true + status = (known after apply) + storage_encrypted = true storage_type = "gp2" username = "postgres" vpc_security_group_ids = [ "sg-81f064e5", ] }
  • 10. Terraform and RDS defaults # aws_db_instance.muffy-test: resource "aws_db_instance" "muffy-test" { address = "muffy-test.....com" allocated_storage = 100 arn = "arn:...:muffy-test" auto_minor_version_upgrade = true availability_zone = "us-east-1b" backup_retention_period = 0 backup_window = "04:40-05:10" ca_cert_identifier = "rds-ca-2019" copy_tags_to_snapshot = false db_subnet_group_name = "db-subnetgrp" delete_automated_backups = true deletion_protection = false endpoint = "muffy-test...:5432" engine = "postgres" engine_version = "11.5" hosted_zone_id = "Z2R2ITUGPM61AM" iam_database_authentication_enabled = false id = "muffy-test" identifier = "muffy-test" instance_class = "db.m5.large" iops = 0 kms_key_id = "arn:...:key/..." license_model = "postgresql-license" maintenance_window = "sat:08:12-sat:08:42" max_allocated_storage = 0 monitoring_interval = 0 multi_az = false option_group_name = "default:postgres-11" parameter_group_name = "default.postgres11" password = (sensitive value) performance_insights_enabled = false performance_insights_retention_period = 0 port = 5432 publicly_accessible = false replicas = [] resource_id = "db-EJHF7...W6VLWRE" skip_final_snapshot = true status = "available" storage_encrypted = true storage_type = "gp2" username = "postgres" vpc_security_group_ids = [ "sg-81f064e5", ] }
  • 11. Applying changes resource "aws_db_instance" "muffy-test" { allocated_storage = 16000 apply_immediately = false [...] } # aws_db_instance.muffy-test will be updated in-place ~ resource "aws_db_instance" "muffy-test" { ~ allocated_storage = 100 -> 16000 + apply_immediately = false } . . . aws_db_instance.muffy-test: Modifying... [id=muffy-test] ...muffy-test: Modifications complete after 32s [id=muffy-test] Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
  • 12. Parameter groups # aws_db_parameter_group.muffy-pg must be replaced -/+ resource "aws_db_parameter_group" "muffy-pg" { description = "Managed by Terraform" ~ family = "postgres9.6" -> "postgres11" # forces replacement } aws_db_parameter_group.muffy-pg: Destroying... [id=terraform-20200115031710299600000001] . . . [id=terraform-20200115031710299600000001, 2m50s elapsed] Error: Error deleting DB parameter group: InvalidDBParameterGroupState: One or more database instances are still members of this parameter group terraform-20200115031710299600000001, so the group cannot be deleted status code: 400, request id: 0e99a7be-4b2d-43d7-ac96-5b18af81c307
  • 13. Parameter apply_method resource "aws_db_parameter_group" "muffy-pg" { family = "postgres11" parameter { apply_method = "immediate" name = "autovacuum_naptime" value = "30" } parameter { apply_method = "pending-reboot" name = "autovacuum_max_workers" value = "15" } } # aws_db_parameter_group.muffy-pg will be updated in-place ~ resource "aws_db_parameter_group" "muffy-pg" { + parameter { + apply_method = "immediate" + name = "autovacuum_naptime" + value = "30" } - parameter { - apply_method = "immediate" -> null - name = "autovacuum_naptime" -> null - value = "15" -> null } }
  • 14. Plans aside # aws_db_parameter_group.muffy-pg will be updated in-place ~ resource "aws_db_parameter_group" "muffy-pg" { [...] + parameter { + apply_method = "immediate" + name = "autovacuum_naptime" + value = "30" } - parameter { - apply_method = "immediate" -> null - name = "autovacuum_naptime" -> null - value = "15" -> null } parameter { apply_method = "pending-reboot" name = "autovacuum_max_workers" value = "15" } }
  • 16. What’s the real value? # PostgreSQL 9.6 postgres=> select name, setting, unit from pg_settings where name = 'max_wal_size'; name | setting | unit --------------+---------+------ max_wal_size | 128 | 16MB (1 row) postgres=> show max_wal_size; max_wal_size -------------- 2GB (1 row) # PostgreSQL 10 postgres=> select name, setting, unit from pg_settings where name = 'max_wal_size'; name | setting | unit --------------+---------+------ max_wal_size | 128 | MB (1 row) postgres=> show max_wal_size; max_wal_size -------------- 12MB (1 row)