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

Chained data sources fail during destroy #32023

Closed
Nuru opened this issue Oct 15, 2022 · 2 comments · Fixed by #32051
Closed

Chained data sources fail during destroy #32023

Nuru opened this issue Oct 15, 2022 · 2 comments · Fixed by #32051
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue

Comments

@Nuru
Copy link

Nuru commented Oct 15, 2022

Terraform Version

Terraform v1.3.2
on darwin_amd64
+ provider registry.terraform.io/hashicorp/null v3.1.1

Also reproduced on Terraform 1.1.0

Terraform Configuration Files

./modules/data/main.tf

data "null_data_source" "config" { }

locals {
  use_s3_backend = tonumber(data.null_data_source.config.random) == 1
}

output "use_s3_backend" {
  value = local.use_s3_backend
}

output "s3_output" {
  value = one(data.terraform_remote_state.s3[*].output)
}

data "terraform_remote_state" "s3" {
  count = local.use_s3_backend ? 1 : 0

  backend = "s3"
  config = {
    encrypt        = true
    bucket         = "example"
    key            = "terraform.tfstate"
    region         = "us-east-1"
  }
}

main.tf

terraform {
  required_providers {
    null = {
      source = "hashicorp/null"
      version = "3.1.1"
    }
  }
}

provider "null" { }

module "data" {
  source = "./modules/data"
}

output "use_s3_backend" {
  value = module.data.use_s3_backend
}

output "s3_output" {
  value = module.data.s3_output
}

Debug Output

terraform-debug.log

Expected Behavior

Destroy complete! Resources: 0 destroyed.

Actual Behavior

│ Error: Invalid count argument
│ 
│   on modules/data/main.tf line 17, in data "terraform_remote_state" "s3":
│   17:   count = local.use_s3_backend ? 1 : 0
│ 

Steps to Reproduce

  1. terraform init
  2. terraform plan -destroy -out=plan
  3. terraform apply plan

Additional Context

Although it may seem trivial that an error is generated when destroying a non-existent resource, it causes significant problems with automated workflows, such as cleaning up test environments.

References

@crw
Copy link
Contributor

crw commented Oct 18, 2022

Thanks for this report!

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants