Skip to content

Plan fails if KMS key is being created at the same time as the module #1278

Open
@brinnjoyce

Description

@brinnjoyce

Describe the bug

If the KMS key is being created at the same time as the module, i.e. as a separate aws_kms_key resource or by setting enable_managed_kms_key the plan fails with this error:

╷
│ Error: Invalid count argument
│
│   on .terraform/modules/gitlab-runner/modules/terminate-agent-hook/iam.tf line 53, in data "aws_iam_policy_document" "kms_key":
│   53:   count = var.kms_key_id != "" ? 1 : 0
│
│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this,
│ use the -target argument to first apply only the resources that the count depends on.

To Reproduce

Steps to reproduce the behavior:
Try to use the module like this:

module "gitlab-runner" {
  source  = "cattle-ops/gitlab-runner/aws"
  version = "9.2.0"

  environment = "prod"
  runner_gitlab = {
    url                                           = var.gitlab_url
    preregistered_runner_token_ssm_parameter_name = var.token_ssm_parameter_name
  }

  enable_managed_kms_key = true

  subnet_id = var.subnet
  vpc_id    = var.vpc
}

Expected behavior

Terraform plan should not fail

Additional context

Caused by #1258

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions