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 vague error message on length=-1 for random_string resource #129

Closed
ghost opened this issue Nov 9, 2020 · 2 comments · Fixed by #234
Closed

Terraform vague error message on length=-1 for random_string resource #129

ghost opened this issue Nov 9, 2020 · 2 comments · Fixed by #234
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Nov 9, 2020

This issue was originally opened by @bogdanbarna as hashicorp/terraform#26849. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/random v3.0.0

Terraform Configuration Files

variable "name_prefix" {}

resource "random_string" "name_suffix" {
  length  = 30 - length(var.name_prefix)
  upper   = false
  special = false
}

resource "aws_instance" "web" {
  ami           = "ami-07dd19a7900a1f049"
  instance_type = "t3.micro"

  tags = {
    Name = "foo-${random_string.name_suffix.result}"
  }
}

Debug Output

Crash Output

https://gist.github.com/bogdanbarna/4181ddf0b5fe0082e6cdcf4aae8cf0e0

Expected Behavior

A specific error message appearing during plan and/or apply.

Actual Behavior

Receiving Error: rpc error: code = Unavailable desc = transport is closing on apply.

Steps to Reproduce

terraform init
terraform apply -var name_prefix=small # this works
terraform apply -var name_prefix=laaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarge # this crashes

Additional Context

The crash report isn't created when the random_string output is used for the aws_instance input.
So apply -target=random_string creates the crash report, but apply without target does not.

References

@pyToshka
Copy link

in this case length = -12

  # random_string.name_suffix will be created
  + resource "random_string" "name_suffix" {
      + id          = (known after apply)
      + length      = -12
      + lower       = true
      + min_lower   = 0
      + min_numeric = 0
      + min_special = 0
      + min_upper   = 0
      + number      = true
      + result      = (known after apply)
      + special     = false
      + upper       = false
    }

seems like need to add checking for negative length in string.go

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 May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants