Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13.2: Error: Invalid count argument: terraform apply 'destroy' plan #26207

Closed
afallucc opened this issue Sep 10, 2020 · 1 comment · Fixed by #28017
Closed

0.13.2: Error: Invalid count argument: terraform apply 'destroy' plan #26207

afallucc opened this issue Sep 10, 2020 · 1 comment · Fixed by #28017
Labels
bug confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases

Comments

@afallucc
Copy link

Terraform Version

Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/local v1.4.0
+ provider registry.terraform.io/hashicorp/null v2.1.2

Terraform Configuration Files

#### Root directory
.
├── 01
│   └── main.tf
├── 02
│   └── main.tf
├── data.json
└── main.tf

2 directories, 4 files
cat main.tf
module "one" {
  source = "./01"
}

module "two" {
  source = "./02"
  items  = module.one.config
}

output two {
    value = module.two.sample
}

##Local file to be used by datasource
cat data.json
{"item":"c"}

cat 01/main.tf
data "local_file" "foo" {
  filename = "data.json"
}

output config {
   value = {foo = jsondecode(data.local_file.foo.content).item}

}

cat 02/main.tf
variable items {}

resource "null_resource" "sample"{

  count = var.items.foo == "c" ? 1 : 0
}

output sample {
  value = try(null_resource.sample[0], {})
}
...

Debug Output

Crash Output

Expected Behavior

Successful destroy

Actual Behavior

 ./terraform apply plan
module.two.null_resource.sample[0]: Destroying... [id=1227142402422233482]
module.two.null_resource.sample[0]: Destruction complete after 0s

Error: Invalid count argument

  on 02/main.tf line 5, in resource "null_resource" "sample":
   5:   count = var.items.foo == "c" ? 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.

Steps to Reproduce

terraform init
terraform apply -auto-approve
terraform plan -destroy -out=plan
terraform apply plan

Additional Context

References

@afallucc afallucc added bug new new issue not yet triaged labels Sep 10, 2020
@afallucc afallucc changed the title 0.13.2: Error: Invalid count argument: 0.13.2: Error: Invalid count argument: terraform apply 'destroy' plan Sep 10, 2020
@jbardin jbardin added confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases and removed new new issue not yet triaged labels Sep 16, 2020
@ghost
Copy link

ghost commented Apr 9, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants