Answers: <p>I ended up using the <code>cyrilgdn/postgresql</code> provider which allowed be to create/destroy db as needed</p>
  <pre><code>terraform {
    required_providers {
      hashiaws = {
        source  = &quot;hashicorp/aws&quot;
        version = &quot;~&gt; 3.4.0&quot;
      }
      postgresql = {
        source  = &quot;cyrilgdn/postgresql&quot;
        version = &quot;1.7.2&quot;
      }
    }
    required_version = &quot;&gt;= 0.13&quot;
  }
  
  provider &quot;postgresql&quot; {
    host             = local.db_url
    port             = local.db_port
    database         = local.db_name
    username         = local.db_usr
    password         = local.db_pwd
    sslmode          = &quot;disable&quot;
    connect_timeout  = 15
    expected_version = local.db_eng_ver
  }
  </code></pre>
  <p>The only downside to this solution is that the server you are running TF on will need to have access to the RDS manage instance</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-10-16T15:59:55.117Z
Answers: 2020-10-16T15:59:55.117Z
Answers: alexis
Answers: <p>For RDS, the simplest would probably be to have a template RDS snapshot that you create instances off of, just like you would an AMI.</p>
  <p>However if later updates to the database structure will be frequent/complex enough that the added complexity of a CD migration tool will be worthwhile, then you may be better off starting with that for the initial deployment as well. I don't know how mature they are in the postgres world, but <a href="https://dbmstools.com/categories/version-control-tools/postgresql" rel="nofollow noreferrer">https://dbmstools.com/categories/version-control-tools/postgresql</a> might be a good place to start.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-04T14:10:11.127Z
Answers: 2020-09-04T14:10:11.127Z
Answers: T.H.
Body: <p>I am using Terraform Cloud to build the infrastructure. One of the resources is a postgresql database.</p>
  <p>What is the best way to populate the database by creating tables, multiple schema etc after the database gets created.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-09-04T13:49:47.227Z
Comments: Are you using RDS for the postgresql database?
Comments: T.H.
Comments: CC BY-SA 4.0
Comments: 2020-09-04T13:54:16.870Z
Comments: yes i am using RDS Postgresql
Comments: alexis
Tags: <amazon-web-services><terraform><databases>
Title: Populate Database
UserDisplayName: alexis
ThreadText: # Populate Database
  
  (Asked by: username_0 on 2020-08-21)
  
  I am using Terraform Cloud to build the infrastructure. One of the resources is a postgresql database.
  
  What is the best way to populate the database by creating tables, multiple schema etc after the database gets created.
  
  **Tags:** amazon-web-services, terraform, databases
  
  > **Comments:**
  > **username_1**: Are you using RDS for the postgresql database?  
  > **username_0**: yes i am using RDS Postgresql  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-10-16. Score: 1 | Accepted answer
  
  I ended up using the `cyrilgdn/postgresql` provider which allowed be to create/destroy db as needed
  
  ```
  terraform {
    required_providers {
      hashiaws = {
        source  = "hashicorp/aws"
        version = "~> 3.4.0"
      }
      postgresql = {
        source  = "cyrilgdn/postgresql"
        version = "1.7.2"
      }
    }
    required_version = ">= 0.13"
  }
  
  provider "postgresql" {
    host             = local.db_url
    port             = local.db_port
    database         = local.db_name
    username         = local.db_usr
    password         = local.db_pwd
    sslmode          = "disable"
    connect_timeout  = 15
    expected_version = local.db_eng_ver
  }
  
  ```
  
  The only downside to this solution is that the server you are running TF on will need to have access to the RDS manage instance
  
  
  ---
  
  ### Answer by username_1 on 2020-09-04. Score: 1
  
  For RDS, the simplest would probably be to have a template RDS snapshot that you create instances off of, just like you would an AMI.
  
  However if later updates to the database structure will be frequent/complex enough that the added complexity of a CD migration tool will be worthwhile, then you may be better off starting with that for the initial deployment as well. I don't know how mature they are in the postgres world, but <https://dbmstools.com/categories/version-control-tools/postgresql> might be a good place to start.
  
  
  ---
  
  