[Infrastructure as Code (IaC)] Manage PostgreSQL database with Terraform PostgreSQL Provider
Terraform PostgreSQL Database Examples
Examples about using Terraform PostgreSQL Provider to manage databases and roles(users).
Github: https://github.com/CloudoLife/terraform-postgresql-examples
Prerequsites
Your must have a PostgreSQL database admin account and password, and Terraform CLI have been installed.
PostgreSQL Database Admin Account and Password
Account and password may be postgres/postgres by default.
Terrraform and Terrafrom PostgreSQL Provider
-
Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service
-
Provider: PostgreSQL - Terraform by HashiCorp
The PostgreSQL provider gives the ability to deploy and configure resources in a PostgreSQL server.
Configuration
PostgreSQL Provider Variables
First, Specify values for PostgreSQL Provider variables within terraform.tfvars.
1 | host = "localhost" |
Role(User)
Config PostgreSQL roles(users) within ./roles
1 | # PostgreSQL: postgresql_role - Terraform by HashiCorp |
Database
Config PostgreSQL databases within ./databases
1 | # PostgreSQL: postgresql_database - Terraform by HashiCorp |
Run
Terraform Init
1 | terraform init |
It will download the Terraform PostgreSQL Provider binary.
Terraform apply
1 | terraform apply |
It will dispaly the execute plan and wait for your make yes or no.
Then yes to create PostgreSQL roles(users) and databases.