0
votes

I have an issue with my S3 module, When i put a default KMS arn in the variables at module level, it works.

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

module 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 (when i replace the null value field of kms_key_arn by the ARN key it works)

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"
}

I get the following error:

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.

I can't figure out what's going on.

Could you please help me ?

Regards.

1

1 Answers

1
votes

There is no variable named kms_master_key_id. That's a property you are trying to set inside the module, but the module's variable is named kms_key_arn.

It should be the following:

kms_key_arn = var.kms_key_arn