Don't Do That! RDS Terraform Import sans Pain 📊
Importing the RDS
You start the import like any other resource. Define an import
block and then
match the properties of the resource 1-1 with the existing resource.
1 2 3 4 |
|
Then define the corresponding resource in the resource
block.
1 2 3 4 5 6 7 |
|
Testing the Process
Examine your plans. In particular make sure the resource is updated in place and not destroyed and recreated. In the case of destroy on an RDS you could lose all your data.
1 |
|
Gotchyas
If your database is encrypted be sure to include the:
1 |
|
argument as it defaults
to false
and will cause an encrypted RDS to be destroyed and recreated resulting in data loss.
If you are testing your process and you are using micro instances to save on costs, be aware that the smallest instance
size that supports encryption is db.t2.small
. If you are using a db.t2.micro
instance you may not see the
replacement issue since encryption is not available on the free tier RDSs.
Again always examine your plans.
Conclusion
Importing a database into terraform is a delicate process. Always be sure to examine your plans and be aware of the gotchyas that can cause data loss. Keep in mind the differences between testing resources and your production resources as differences in possible configuration can result in different outcomes.