I have a terraform script that builds a MSK cluster, I have outputted the zookeeper & broker information and I would like to add this data to a AWS secret's manager secret.
The problem is they are comma separated.
This is the output in the pipeline
~ zookeeper_connect_string = "z-1.example-loadtesting.qukw3u.c2.kafka.eu-west-1.amazonaws.com:2181,z-2.example-loadtesting.qukw3u.c2.kafka.eu-west-1.amazonaws.com:2181,z-3.example-loadtesting.qukw3u.c2.kafka.eu-west-1.amazonaws.com:2181
This is the terrafrom for the secrets manager.
resource "aws_secretsmanager_secret_version" "connection" {
secret_id = aws_secretsmanager_secret.kafka.id
secret_string = jsonencode({
"bootstrap_brokers_tls_1": aws_msk_cluster.example.bootstrap_brokers_tls,
"bootstrap_brokers_tls_2": aws_msk_cluster.example.bootstrap_brokers_tls,
"zookeeper_connect_string_1": aws_msk_cluster.example.zookeeper_connect_string,
"zookeeper_connect_string_2":aws_msk_cluster.example.zookeeper_connect_string,
})
}
Is there a way to use terraform indexes or some other method to use this data?
Thanks
Output
output "zookeeper_connect_string_0" {
value = element(split(",", aws_msk_cluster.example.zookeeper_connect_string),0)
}
output "zookeeper_connect_string1_1" {
value = element(split(",", aws_msk_cluster.example.zookeeper_connect_string),1)
}