cloudposse / cloudposse/terraform-aws-ec2-instance

instance_profile error with invalid count on first apply

Open
#194 4 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
HCL
Stars
169
Forks
216
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

Input instance_profile will throw the below error on apply
```
│ Error: Invalid count argument

│ on .terraform/modules/instance/main.tf line 85, in data "aws_iam_instance_profile" "given":
│ 85: count = local.enabled && var.instance_profile_enabled && var.instance_profile != "" ? 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.


│ Error: Invalid count argument

│ on .terraform/modules/instance/main.tf line 96, in resource "aws_iam_role" "default":
│ 96: count = var.instance_profile_enabled ? local.instance_profile_count : 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.
```

### Expected Behavior

Expected behavior is that the instance will use the precreated instance profile

### Steps to Reproduce

```
resource "aws_iam_role" "default" {
depends_on = [aws_iam_policy.default]
name = "test-role"
assume_role_policy = <

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.