Hello I have following code
resource "null_resource" "used_ips_list" {
provisioner "local-exec" {
command = <<-EOT
aws_credentials=$(aws sts assume-role --role-arn arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/<rolename>
aws ec2 describe-network-interfaces --region eu-west-2 --filters "Name=subnet-id,Values=subnet-0ec649f72bb07c" --query 'NetworkInterfaces[*].PrivateIpAddress' > ${data.template_file.subnet_a.rendered}
EOT
}
}
data "template_file" "subnet_a" {
template = "${path.module}/subnet_a"
}
data "local_file" "create-endpoint" {
filename = data.template_file.subnet_a.rendered
depends_on = ["null_resource.used_ips_list"]
}
locals {
subnet_ip_list = data.local_file.create-endpoint.content
}
I am trying to get a list of used ips in aws account but I get heredoc charcters in the file/local variable. This is the format I get output in
"[\n \"172.18.0.247\",\n \"172.18.0.253\",\n \"172.18.0.219\",\n \"172.18.0.222\",\n \"172.18.0.254\",\n \"172.18.0.244\",\n \"172.18.0.227\",\n \"172.18.0.224\",\n \"172.18.0.211\",\n \"172.18.0.197\",\n \"172.18.0.246\",\n \"172.18.0.208\",\n \"172.18.0.237\",\n \"172.18.0.238\",\n \"172.18.0.243\",\n \"172.18.0.217\",\n \"172.18.0.248\",\n \"172.18.0.226\",\n \"172.18.0.207\"\n]\n"
I have tried function like trim and split but I get this
subnet_a_ip_list = tolist([
"[",
" \"172.18.0.247\",",
" \"172.18.0.253\",",
" \"172.18.0.219\",",
" \"172.18.0.222\",",
" \"172.18.0.254\",",
" \"172.18.0.244\",",
" \"172.18.0.227\",",
" \"172.18.0.224\",",
" \"172.18.0.211\",",
" \"172.18.0.197\",",
" \"172.18.0.246\",",
" \"172.18.0.208\",",
" \"172.18.0.237\",",
" \"172.18.0.238\",",
" \"172.18.0.243\",",
" \"172.18.0.217\",",
" \"172.18.0.248\",",
" \"172.18.0.226\",",
" \"172.18.0.207\"",
"]",
"",
])
or this
subnet_a_ip_list = <<EOT
[
"172.18.0.247",
"172.18.0.253",
"172.18.0.219",
"172.18.0.222",
"172.18.0.254",
"172.18.0.244",
"172.18.0.227",
"172.18.0.224",
"172.18.0.211",
"172.18.0.197",
"172.18.0.246",
"172.18.0.208",
"172.18.0.237",
"172.18.0.238",
"172.18.0.243",
"172.18.0.217",
"172.18.0.248",
"172.18.0.226",
"172.18.0.207"
]
EOT
How can I get a list of ips ?
any help will be much appreciated