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

Terraform crash during import with check defined #33572

Closed
tristanmorgan opened this issue Jul 25, 2023 · 2 comments · Fixed by #33578
Closed

Terraform crash during import with check defined #33572

tristanmorgan opened this issue Jul 25, 2023 · 2 comments · Fixed by #33578
Assignees
Labels
bug cli confirmed a Terraform Core team member has reproduced this issue core explained a Terraform Core team member has described the root cause of this issue in code

Comments

@tristanmorgan
Copy link
Member

tristanmorgan commented Jul 25, 2023

Terraform Version

Terraform v1.5.3
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.9.0

Terraform Configuration Files

# the specific provider does not make a difference, this is just an AWS example
provider "aws" {
  endpoints {
    s3 = "http://minio.service.home.consul"
  }
  region                      = "ap-southeast-2"
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  s3_use_path_style           = true
}

resource "aws_s3_bucket" "bucket" {
  bucket = "distribution"
}

check "consul_health" {
  data "aws_s3_bucket" "distribution" {
    bucket = "distribution"
  }

  assert {
    condition     = data.aws_s3_bucket.distribution.arn == "arn:aws:s3:::distribution"
    error_message = "bucket arn does not equal \"arn:aws:s3:::distribution\""
  }
}

Debug Output

Crash log from running

TF_LOG=debug terraform import aws_s3_bucket.bucket "distribution"

Expected Behavior

Successful import of resource

Actual Behavior

Terraform crashed.

Steps to Reproduce

Using the sample code

  1. terraform init
  2. terraform import aws_s3_bucket.bucket "distribution"
    results in a crash

Additional Context

The issue seems to occur when any check block with a data source is defined while importing a resource. in this example I used a data source matching the imported resource but it could be any data source.

I initially caused the crash using the nomad provider and it does not seem to be provider specific.

References

No response

@tristanmorgan tristanmorgan added bug new new issue not yet triaged labels Jul 25, 2023
@tristanmorgan tristanmorgan changed the title Terraform crash during import Terraform crash during import with check defined Jul 25, 2023
@jbardin jbardin added core cli and removed new new issue not yet triaged labels Jul 25, 2023
@liamcervante liamcervante self-assigned this Jul 25, 2023
@liamcervante liamcervante added the confirmed a Terraform Core team member has reproduced this issue label Jul 25, 2023
@liamcervante
Copy link
Member

Hi @tristanmorgan, thanks for filing this issue! I can confirm I am able to replicate. Just a slight clarification for clarity: It's the nested data block that is causing the crash rather than the check block itself. Still a good find, and something I will looking into fixing.

A quick explanation. The nested data blocks are missing the logic telling them to skip evaluation during an import operation. This logic has been applied to the other elements of the check block. This is then crashing when the scoped data block attempts to report it's checkable status and the system isn't expecting any checkable statuses.

Thanks again for finding this!

Copy link

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 Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli confirmed a Terraform Core team member has reproduced this issue core explained a Terraform Core team member has described the root cause of this issue in code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants