hashicorp / terraform-provider-random

Utility provider that supports the use of randomness within Terraform configurations.
https://registry.terraform.io/providers/hashicorp/random/latest
Mozilla Public License 2.0
201 stars 115 forks source link

Calculating incorrect bytes on imported resource #435

Closed rmvangun closed 1 year ago

rmvangun commented 1 year ago

Terraform CLI and Provider Versions

Terraform v1.5.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v5.8.0
+ provider registry.terraform.io/hashicorp/local v2.4.0
+ provider registry.terraform.io/hashicorp/random v3.5.1

Terraform Configuration

resource "random_id" "postfix" {
  byte_length = 4
}

Expected Behavior

If I run terraform import random_id.postfix 9789af1d, then run terraform plan, I would expect to see no changes.

Actual Behavior

However, I'm getting this:

  # module.terraform_remote_state.random_id.postfix must be replaced
-/+ resource "random_id" "postfix" {
      ~ b64_std     = "9789af1d" -> (known after apply)
      ~ b64_url     = "9789af1d" -> (known after apply)
      ~ byte_length = 6 -> 4 # forces replacement
      ~ dec         = "272400741170525" -> (known after apply)
      ~ hex         = "f7bf3d69fd5d" -> (known after apply)
      ~ id          = "9789af1d" -> (known after apply)
      - keepers     = {} -> null
    }

This is obviously incorrect, as you can see that it believes the byte_length is 6, yet the existing b64_url is 4 bytes.

This is also pretty rough as it's causing all my resources with names based on this random ID to be recreated.

Steps to Reproduce

  1. Create a random_id resource with 4 bytes
  2. Run terraform import random_id.postfix 9789af1d
  3. Run terraform plan and observe the incorrectly calculated bytes

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

Code of Conduct

rmvangun commented 1 year ago

Nevermind, while the output is a little confusing as it places the hex value as the b64 encoded values, I realized that I needed to convert the hex to base64url to correctly import it. Good to go now.

github-actions[bot] commented 5 months ago

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.