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

random_string doesn't create correct length #609

Closed
1 task done
LeBaronDeCharlus opened this issue Sep 26, 2024 · 1 comment
Closed
1 task done

random_string doesn't create correct length #609

LeBaronDeCharlus opened this issue Sep 26, 2024 · 1 comment
Labels

Comments

@LeBaronDeCharlus
Copy link

Terraform CLI and Provider Versions

./terraform -v && ./terraform init --upgrade
Terraform v1.9.6
on linux_amd64
+ provider registry.terraform.io/hashicorp/random v3.6.3
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Using previously-installed hashicorp/random v3.6.3

Terraform has been successfully initialized!

Terraform Configuration

resource "random_string" "random" {
  length  = 32
  special = false
}

output "random_string" {
  value = random_string.random.result
}

Expected Behavior

Length should be the exact amount of characters defined in length arg.

Actual Behavior

While asking for a specific number, it creates an unwanted additional one.
If we ask for 30, we get 31 (29 => 30, 28 => 29 etc)

Steps to Reproduce

  1. terraform init
  2. terraform apply | tail -1 | cut -d '"' -f 2| wc

How much impact is this issue causing?

High

Logs

https://gist.github.com/LeBaronDeCharlus/147648c236408cf6c526522af4a5fe2f

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@austinvalle
Copy link
Member

austinvalle commented Sep 30, 2024

Hey there @LeBaronDeCharlus 👋🏻,

I believe since you're directly processing the human-readable CLI output, it's also receiving a newline character. (wc has a count for the newline character)

You could trim that with something like tr: terraform apply | tail -1 | cut -d '"' -f 2 | tr -d '\n' | wc

We typically recommend using one the machine-readable JSON output for external processes, which I think may be an easier path, for example:

$ terraform output -json

{
  "random_string": {
    "sensitive": false,
    "type": "string",
    "value": "<your random string here>"
  }
}

@austinvalle austinvalle closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants