terraform S3 模块,无法调用 KMS 密钥 arn 调用模块

terraform S3 module, can't call the KMS key arn calling module

我的 S3 模块有问题, 当我在模块级别的变量中放置一个默认的 KMS arn 时,它起作用了。

|- main.tf
|- variable.tf
|- /S3
    - main.tf
    - variable.tf

模块 s3 main.tf:

resource "aws_s3_bucket" "default" {
  bucket = var.name
  tags   = var.tags
  acl    = "private"

  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        enabled = true
        kms_master_key_id = var.kms_key_arn
        sse_algorithm     = "aws:kms"
      }
    }
  }
}

module s3 variable.tf(当我用它工作的 ARN 键替换 kms_key_arn 的空值字段时)

variable "tags" {
  type = map
  description = "Specifies the S3 tags here."
}

variable "name" {
  type        = string
  description = "Specifies the S3 path were spark stores it jobs log."
}

variable "kms_key_arn" {
  type        = string
  description = "Specifies the kms key used for this project."
  default     = null
}

root main.tf:

module "s3_python_scripts" {
  source  = "./s3"
  name  = "s3://my_S3_path/"
  tags = var.tags
  kms_master_key_id = var.kms_key_arn
}

root variable.tf:

...

variable "kms_key_arn" {
  type        = string
  description = "Specifies the kms key used for this project."
  default     = "arn:aws:kms:xxxxxxxxxxxxxxx:xxxxxxxxxxxxxxx:key/xxxxxxxxxxxxxxx"
}

我收到以下错误:

Error: Unsupported argument on maint.tf line 24, in module "s3_python_scripts": 24: kms_master_key_id = var.kms_key_arn An argument named "kms_master_key_id" is not expected here.

我搞不懂这是怎么回事。

你能帮帮我吗?

此致。

没有名为 kms_master_key_id 的变量。那是你试图在模块内部设置的 属性,但模块的变量名为 kms_key_arn.

应该是:

kms_key_arn = var.kms_key_arn