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

Can I import if I only know the hex value via conversion perhaps? #96

Open
codydiehl opened this issue Jan 12, 2020 · 2 comments
Open

Comments

@codydiehl
Copy link

codydiehl commented Jan 12, 2020

Hello,
I lost my state due to losing a lock apparently on my storage backend and so it never completed saving the state file. The resources were all created but i no longer have the state.
I would like to still manage these resources so i was hoping I could import the random ID as I use it on another resource that is always wanting to update.
In the meantime I an using lifecycle hooks to ignore it.

I use the "hex" attribute of the random_id resource to place within a disk name for a VM.
So all i have is the hex value for instance with using a 16 byte length this hex value:
1c2535161c6755ac151b4c6adf2242ca

Is there any possible way to convert this back to the base64url value that is needed to import?

Terraform Version

Terraform v0.12.18

  • provider.azurerm v1.38.0
  • provider.random v2.2.1

Affected Resource(s)

  • random_id

Terraform Configuration Files

resource "random_id" "os_disk_id" {
  keepers = {
    vm_name = var.vm_name
  }
  byte_length = 16
}

resource "azurerm_virtual_machine" "vm" {
#<snip>
  storage_os_disk {
    name              = "${var.vm_name}_OsDisk_1_${random_id.os_disk_id.hex}"
    #<snip>
  }
}

Expected Behavior

Be able to import with the known hex value perhaps, or a simple way to convert back to the other formats when knowing one of the formats.

Actual Behavior

Cannot import hex value as it sets this for all values and wants to replace the resource on plan. as it sets the b64_url value and will convert this to hex.

Steps to Reproduce

  1. terraform import resource.random_id.os_disk_id 1c2535161c6755ac151b4c6adf2242ca
  2. terraform plan

Important Factoids

only know the hex value created by the random_id provider. would like to convert this back to b64_url value if at all possible.

@emmaLP
Copy link

emmaLP commented Apr 17, 2020

As a work around I took the hex value and used a converter to get it into base 64

https://base64.guru/converter/encode/hex

@rafikurnia
Copy link

See whether it is working or not...

OUTPUT=`echo "1c2535161c6755ac151b4c6adf2242ca" | xxd -r -p | base64 | tr '/+' '_-' | tr -d '='`
terraform import resource.random_id.os_disk_id $OUTPUT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants