Skip to content

"Invalid count argument" when trying to use a terraform managed ssm parmater #4631

Open
@paul-civitas

Description

@paul-civitas

We tried to pass a ssm parameter resource into the module like this:

ami = {
  id_ssm_parameter_arn = aws_ssm_parameter.runner_ami.arn
}

We get the error:

│ Error: Invalid count argument

│ on .terraform/modules/runners/modules/runners/main.tf line 96, in resource "aws_ssm_parameter" "runner_ami_id":
│ 96: count = local.ami_id_ssm_module_managed ? 1 : 0

│ The "count" value depends on resource attributes that cannot be determined until apply, so OpenTofu cannot predict how many instances will be created.

As a workaround we had to change it to use a data source instead for the ssm parameter.

Suggested fix: allow people to pass in ami_id_ssm_module_managed themselves to say explicitly that it's managed or not managed. Fall back on the current detection method if that variable is not passed in.

This would preserve backwards compatibility while allowing people who are having this issue to resolve their issue.

Tofu version:

OpenTofu v1.10.0-rc1
on darwin_arm64
+ provider registry.opentofu.org/hashicorp/aws v5.100.0
+ provider registry.opentofu.org/hashicorp/null v3.2.4
+ provider registry.opentofu.org/hashicorp/random v3.7.2

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