title: RDS storage autoscaling support using terraform for live databases
body: <p>AWS has <a href="https://aws.amazon.com/about-aws/whats-new/2019/06/rds-storage-auto-scaling/" rel="nofollow noreferrer">recently</a> launched support for storage autoscaling of RDS instances. We have multiple RDS instances with over provisioned storage in our production environment. We want to utilise this new feature to reduce some costs. Since we cannot reduce the storage of a live RDS instance, we will have to first create a RDS instance with less storage with autoscaling support and then migrate the existing data to new instance and then delete the old instance.</p>
  
  <p>We use terraform with the terraform-aws-provider to create our infrastructure. Problem is that I am not able to achieve the above strategy using terraform. 
  Here is what i have tried :</p>
  
  <ol>
  <li>Modify the existing RDS creation script to create two more
  resources. </li>
  <li>One is of type <code>aws_db_snapshot</code> and other is
  <code>aws_db_instance</code> (using the snapshot). </li>
  <li>However I get the following
  error error modifying DB Instance (test-rds-snapshot):
  InvalidParameterCombination: Invalid storage size for engine name
  postgres and storage type gp2: 20.</li>
  </ol>
  
  <pre><code># Existing RDS instance with over provisioned storage
  resource "aws_db_instance" "test_rds"{
  .
  .
  .
  }
  
  # My changes below
  # The snapshot
  resource "aws_db_snapshot" "test_snapshot" {
    db_instance_identifier = "${aws_db_instance.test_rds.id}"
    db_snapshot_identifier = "poc-snapshot"
  }
  
  # New instance with autoscale support and reduced storage
  resource "aws_db_instance" "test_rds_snapshot" {
    identifier            = "test-rds-snapshot"
    allocated_storage     = 20
    max_allocated_storage = 50
    snapshot_identifier   = "${aws_db_snapshot.test_snapshot.id}"
  .
  .
  .
  }
  </code></pre>
  
  <p>I want to know if I am on the right track or not and will I be able to migrate production databases using this strategy. Let me know if you need more information. </p>