Create new map from an existing list
hi, please , I migrate some terraform variables from terraform file [1.] to vault [2.], and for this reason,
right now I have variables reached from vault in different format [2.].
1.)
variable “vm_configuration” {
description = “Default vm configuration”
type = map
default = {
“192.168.1.10” = {
hostname = “vm01”
ip = “192.168.1.10”
vcpu = “2”
vram = “4294967296”
},
“192.168.1.11” = {
hostname = “vm02”
ip = “192.168.1.11”
vcpu = “2”
vram = “4294967296”
}
}
}
2.) vault secrets :
vm1_hostname = “vm01”
vm1_ip = “192.168.1.10”
vm1_vcpu = “2”
vm1_vram = “4294967296”
vm2_hostname = “vm02”
vm2_ip = “192.168.1.11”
vm2_vcpu = “2”
vm2_vram = “4294967296”
I try to convert reached variable from vault [2.], by using vault_generic_secret [3.], to the required format [1.], by extracting keys and values to separate lists [4.],
and then I try to use zipmap, but this way did not work.
Or I missed something.
3.)
data “vault_generic_secret” “vm_configs” {
path = “some/path/vm”
}
4.)
vms_keys = }
for key, value in “${data.vault_generic_secret.vm_configs.data}” : substr(key,0,3) => key…
}vms_values = {
for key, value in “${data.vault_generic_secret.vm_configs.data}” : substr(key,0,3) => value…
}
Another problem is, that right now i have string “vm1” and “vm2” as key and not ip address “192.168.1.10” and “192.168.1.11”.
Thank you