azure – Splitting a comma separated string
azure – Splitting a comma separated string
You can use the split()
function to split a string into a list.
output output_tf_testap_outbound_ip_addresses {
value = [${split(,, azurerm_app_service.testap.outbound_ip_addresses)}]
}
After that you can then index it by using the element(list, index)
syntax:
output first_ip {
value = ${element(split(,, azurerm_app_service.testap.outbound_ip_addresses), 0}
}
You should also normally be able to use the list[index]
syntax like this:
output first_ip {
value = ${split(,, azurerm_app_service.testap.outbound_ip_addresses)[0]}
}
However there seems to be a bug in Terraform 0.11 that prevents slicing the result of the split
function, throwing the following error:
Error: Error loading /tmp/tf-split-test/main.tf: Error reading config
for output foo: parse error at 1:25: expected } but found [
You could use a local
to split the list and then slice that to get around this if youd prefer to use this syntax over the element
function.
locals {
outbound_ip_addresses_list = ${split(,, azurerm_app_service.testap.outbound_ip_addresses)}
}
output first_ip {
value = ${local.outbound_ip_addresses_list[0]}
}