具有kms数据资源的Terraform代码的无效arn错误

时间:2020-11-07 04:40:17

标签: amazon-web-services terraform terraform-provider-aws

具有以下代码:

data "aws_kms_key" "rds_key" {
  key_id = "alias/rds_cluster_enryption_key"
}

我想用这个密钥来加密rds实例

resource "aws_rds_cluster" "tf-aws-rds-1" {
  cluster_identifier      = "aurora-cluster-1"
  engine                  = "aurora-mysql"
  engine_version          = "5.7.mysql_aurora.2.03.2"
  availability_zones      = ["us-east-1a", "us-east-1b", "us-east-1c"]
  database_name           = "cupday"
  master_username         = "administrator"
  master_password         = var.password
  backup_retention_period = 5
  preferred_backup_window = "07:00-09:00"
  storage_encrypted       = true
  kms_key_id              = "data.aws_kms_key.rds_key.arn"
}

但是,出现如下错误:

Error: "kms_key_id" (data.aws_kms_key.rds_key.id) is an invalid ARN: arn: invalid prefix

  on main.tf line 42, in resource "aws_rds_cluster" "tf-aws-rds-1":
  42:   kms_key_id              = "data.aws_kms_key.rds_key.id"

Error: "kms_key_id" (data.aws_kms_key.rds_key.arn) is an invalid ARN: arn: invalid prefix

  on main.tf line 42, in resource "aws_rds_cluster" "tf-aws-rds-1":
  42:   kms_key_id              = "data.aws_kms_key.rds_key.arn"

到底该如何推荐他们?

我不想在 kms_key_id

中披露我的帐户ID

1 个答案:

答案 0 :(得分:1)

您对的使用:

fun equal(view: View) {
    secondnum = editText.text.toString()
    decpressed = 0
    var sum = 0.0
    when (op) {
        "+" -> {
            sum = (firstnum.toDouble() + secondnum.toDouble())
        }
        "-" -> {
            sum = (firstnum.toDouble() - secondnum.toDouble())
        }
        "*" -> {
            sum = (firstnum.toDouble() * secondnum.toDouble())
        }
        "/" -> {
            if (secondnum == "0") {
                Toast.makeText(this, "Can not divide by 0!", Toast.LENGTH_LONG).show()
                editText.setText("0")
                textView.text = ""
            } else {
                sum = (firstnum.toDouble() / secondnum.toDouble())
            }
        }
    }
    val out = DecimalFormat("#.##########")
    out.roundingMode = RoundingMode.HALF_EVEN
    editText.setText(out.format(sum))
    textView.text = "$firstnum $op $secondnum ="
    zero = true
}

将导致kms_key_id = "data.aws_kms_key.rds_key.arn" 实际上是字符串“ data.aws_kms_key.rds_key.arn”。

它应该是(tf 0.12 +):

kms_key_id

或tf 0.11:

kms_key_id              = data.aws_kms_key.rds_key.arn