使用 Terraform 从不是最近的快照创建 RDS 实例

Creating RDS instances from not the recent snapshot using Terraform

在 Terraform 项目中,我正在从一个不是最近的快照(倒数第五个)创建一个 RDS 实例,我的脚本在这里:

data "aws_db_snapshot" "db_snapshot" {
  db_instance_identifier = "production-db-intern"
  db_snapshot_arn = "arn:aws:rds:eu-central-1:123114111478:snapshot:rds:production-db-intern-2019-05-09-16-10"
}

resource "aws_db_instance" "db_intern" {
  skip_final_snapshot = true
  identifier = "db-intern"
  auto_minor_version_upgrade = false
  instance_class = "db.m4.4xlarge"
  deletion_protection = false
  vpc_security_group_ids = ["${var.security_group_id}"]
  db_subnet_group_name = "${var.subnet_group_name}"

  timeouts {
    create = "3h"
    delete = "2h"
  }

  lifecycle {
    prevent_destroy = false
  }

  snapshot_identifier = "${data.aws_db_snapshot.db_snapshot.id}"
}

我做了一个 "terraform plan" 并且 我收到下一个错误:

Error: data.aws_db_snapshot.db_snapshot: "db_snapshot_arn": this field cannot be set

db_snapshot_arn 不是 aws_db_snapshot 数据资源的有效字段。您的意思是 db_snapshot_identifier

此外,您不能将 ARN 传递给此数据资源,您可以传递快照 ID,例如snap-1234567890abcdef0.

除此之外,数据资源只需要设置 db_instance_identifierdb_snapshot_identifier。有关具体细节的更多详细信息,请参阅 documentation on the snapshot CLI。 Terraform 利用 CLI 检索这些资源。