How can we restore a snapshot to an RDS instance that is managed by terraform? There is a way to restore the snapshot to a new RDS instance, but when we do a terraform apply later, this instance is destroyed.
This is how we do it now:
We’ve written a TF code to restore the RDS from a snapshot using the parameter snapshot_identifier.
The variable has null as the default value. So, by default, this parameter is ignored and a fresh RDS instance is created. When we pass the snapshot identifier to this variable, the RDS is created using that snapshot. But, when we do a terraform apply again with the default null snapshot identifier, the RDS gets recreated again and hence we lose all the data that was restored earlier. From terraform plan:
yes, this quite hot topic. Actually for now search solution also.
I think need to create manually rds from snapshot and then import to your resource, in my case it is module so for me need to verify first how it would work.
I our case at the company we had the same issue and after create the RDS resource from a snapshot and test the plan, it was keeping trying to destroy/create the resource because a drift on the resource name, so we just added it to the lifecycle like this:
lifecycle {
ignore_changes = [ publicly_accessible, snapshot_identifier, name ]
}
It took as a long time to realize the field that was forcing the replacement when applying the terraform even with lifecycle - ignore_changes - snapshot_identifier.
In our case, when running terraform plan, the command ended like this:
so we added username to the ignore_changes and it stopped trying to replace. Now we’re working on why are we replacing the username and how to replace the user without replacing the RDS.