Reputation: 131
I've upgraded AWS rds aurora postgress cluster from serverless v1 to serverless v2 using terraform.
The steps that I followed:
Below is my terraform config:
resource "aws_rds_cluster" "aurora_rds_serverless_v2" {
cluster_identifier = "aurora-v2-serverless-cluster-new-197789"
engine = local.env_config.rds_engine
}
resource "aws_db_cluster_snapshot" "aurora_rds_db_snapshot" {
db_cluster_identifier = aws_rds_cluster.aurora.id
db_cluster_snapshot_identifier = "aurora-rds-db-cluster-snapshot"
}
resource "aws_rds_cluster" "aurora_rds_provisioned_db_v2" {
cluster_identifier = "aurora-cluster-new-provisioned-v29071"
engine = local.env_config.rds_engine
engine_version = local.env_config.rds_engine_version
engine_mode = "provisioned"
depends_on = [aws_db_cluster_snapshot.aurora_rds_db_snapshot]
}
resource "aws_rds_cluster_instance" "aurora_provisioned_instance" {
cluster_identifier = aws_rds_cluster.aurora_rds_provisioned_db_v2.id
instance_class = "db.serverless"
}
My problem is I cannot simply comment out the old cluster code because snapshot resource is dependent on it. Is there a terraform resource that I can use to delete the old cluster? Or do I need to make the snapshot resource independent after first TF apply?
Upvotes: 0
Views: 128
Reputation: 553
< 1.7.0
You could follow steps similar to this:
terraform state rm
command to delete the snapshot from the terraform statedepends_on
Since you've removed the snapshot from the state, and from the code, before running plan/apply Terraform's will not detect that as a change, and will not attempt to delete the snapshot.
>= 1.7.0
In the same commit, do:
removed
block for the snapshot resourcedepends_on
.
Then, run a plan/apply cycle. Terraform will figure out by itself that it does not need to delete the snapshot because of the removed
block.Here's the updated version of your snippet that works as described:
resource "aws_rds_cluster" "aurora_rds_serverless_v2" {
cluster_identifier = "aurora-v2-serverless-cluster-new-197789"
engine = local.env_config.rds_engine
}
resource "aws_db_cluster_snapshot" "aurora_rds_db_snapshot" {
db_cluster_identifier = aws_rds_cluster.aurora.id
db_cluster_snapshot_identifier = "aurora-rds-db-cluster-snapshot"
}
resource "aws_rds_cluster" "aurora_rds_provisioned_db_v2" {
cluster_identifier = "aurora-cluster-new-provisioned-v29071"
engine = local.env_config.rds_engine
engine_version = local.env_config.rds_engine_version
engine_mode = "provisioned"
# removed the depends_on
}
resource "aws_rds_cluster_instance" "aurora_provisioned_instance" {
cluster_identifier = aws_rds_cluster.aurora_rds_provisioned_db_v2.id
instance_class = "db.serverless"
}
removed {
from = aws_db_cluster_snapshot.aurora_rds_db_snapshot
lifecycle {
destroy = false # so that the snapshot is not removed from AWS
}
}
Terraform state rm
– https://developer.hashicorp.com/terraform/cli/commands/state/rmremoved
block – https://developer.hashicorp.com/terraform/language/resources/syntax#removing-resources.Upvotes: 0