terraform-provider-random
terraform-provider-random copied to clipboard
Can I import if I only know the hex value via conversion perhaps?
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
terraform import resource.random_id.os_disk_id 1c2535161c6755ac151b4c6adf2242caterraform 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.
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
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