[英]How to backup a RDS database in AWS using terraform but not destroying it after each apply
我想使用 terraform 在我的 RDS 數據庫中進行自動備份。我已經這樣做了:
`
resource "aws_db_instance" "main" {
snapshot_identifier = data.aws_db_snapshot.from[0].id
identifier = "${local.prefix}-db"
storage_type = "gp2"
instance_class = "db.t2.micro"
db_subnet_group_name = aws_db_subnet_group.main.name
backup_retention_period = 7
multi_az = false
skip_final_snapshot = true
vpc_security_group_ids = [aws_security_group.rds.id]
tags = merge(
local.common_tags,
tomap({ "Name" = "${local.prefix}-main" })
)
}
data "aws_db_snapshot" "from" {
count = length("test-dev-db") > 0 ? 1 : 0
most_recent = true
db_instance_identifier = "test-db"
}
`
問題在於,在我執行的每個應用程序中,數據庫都會被刪除並重新創建。 那么我怎樣才能避免這種情況呢?
謝謝
伙計們,我已經用這個解決了這個問題:
lifecycle {
ignore_changes = [snapshot_identifier]
}
使用此元參數對我有用。 我是從這里拿來的:https://www.terraform.io/language/meta-arguments/lifecycle
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.