Terraform 11 升级至 12。错误:不支持的属性

Terraform 11 升级至 12。错误:不支持的属性

我最近使用Terraform 0.12升级命令,现在我运行Terraform 验证

$ ~/terraform/us-west-2/app/production/db/rds $  terraform validate

Error: Unsupported attribute

  on main.tf line 111, in resource "aws_rds_cluster" "app_db_production":
 111:   master_password                 = data.aws_kms_secret.app_db_production.master_password

This object has no argument, nested block, or exported attribute named
"master_password".

$ ~/terraform/us-west-2/app/production/db/rds $

有问题的配置:

data "aws_kms_secret" "app_db_production" {
  secret {
    name    = "master_password"
    payload = "2430db63c4f1479f122fb219d179afb1"
  }
}

resource "aws_rds_cluster" "app_db_production" {
  cluster_identifier              = "app-db-production"
  engine                          = "aurora-mysql"
  database_name                   = "app"
  port                            = 3306
  master_username                 = "root"
  master_password                 = data.aws_kms_secret.app_db_production.master_password
  backup_retention_period         = 7
  preferred_backup_window         = "02:00-03:00"
  preferred_maintenance_window    = "sat:03:00-sat:04:00"
  storage_encrypted               = true
  apply_immediately               = false
  final_snapshot_identifier       = "app-db-production-final-snapshot"
  db_cluster_parameter_group_name = "app-db-production"
  db_subnet_group_name            = "app-db-production"
  vpc_security_group_ids = [data.terraform_remote_state.app_production_db_sg.outputs.app_db_production]
  lifecycle {
    create_before_destroy = true
  }
  tags = {
    Application = "db"
    Environment = "production"
    Platform    = "app"
  }
}

这在 Terraform 11 中运行良好。有人可以给我指明正确的方向吗?

答案1

这是由 AWS 提供商的变化而不是 Terraform CLI 的变化引起的。

具体来说,数据aws_kms_secret源已弃用并且仅在 Terraform 0.11 中可用(带有弃用警告)。

要继续,您必须迁移到较新的aws_kms_secrets数据源。上面的链接是有关该迁移的完整文档,但对于这个问题而言,相关部分是,此新数据源的输出位于名为的对象属性中plaintext,目的是您可以在需要时将整个映射用作单个值,除了像以前一样提取单个值之外。

master_password = data.aws_kms_secrets.app_db_production.plaintext["master_password"]

相关内容