Strange error during plan

Hello, I’m getting this error

 Error: Invalid count argument
│ 
│   on _modules/rbac/rbac-assign-roles-aadgroup/main.tf line 21, in module "rbac-assign-aadgroup-custom":
│   21:   count = var.aadgroup_displayname != "" && var.rbac_scope != "" ? length(var.rbac_role_ids) : 0 # Run Only if Parameters are known
│ 
│ 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.

But when looking for the work-arrount I can’t find much about it …

Any directions to put me on the right track again ?

Hi @HL-Sibelco,

In this case the final decision about the count value depends on the values of several variables:

  • var.aadgroup_displayname
  • var.rbac_scope
  • var.rbac_role_ids

This message means that at least one of those values is derived from something that Terraform won’t know until the apply step. Without more context I can’t say for certain which it is, but if you can share the configuration that is assigning values to those three variables (the calling module block) then I may be able to give some more concrete suggestions.

The general answer is that you should usually derive count only from values you’ve defined statically in your configuration, and not from values that are exported by providers after creating objects. For example, if var.rbac_scope is set to an attribute of some other resource and that attribute is not one you’ve set as an argument in the configuration then it’s possible that the provider doesn’t yet know that value and won’t determine it until the corresponding object has been created during the apply step.

1 Like