Hello,
I am trying to get list of used ips in an account with this 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/${var.azure_pipeline_iam_role} --role-session-name "RoleSession1" --output json)
export AWS_ACCESS_KEY_ID=$(echo $aws_credentials|jq '.Credentials.AccessKeyId'|tr -d '"')
export AWS_SECRET_ACCESS_KEY=$(echo $aws_credentials|jq '.Credentials.SecretAccessKey'|tr -d '"')
export AWS_SESSION_TOKEN=$(echo $aws_credentials|jq '.Credentials.SessionToken'|tr -d '"')
aws ec2 describe-network-interfaces --region eu-west-2 --filters "Name=subnet-id,Values=subnet-0ec649f72bb07cdf3" --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
}
However <<EOT- gets added to my file/local variable and looks something like this
"[\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 tried functions like trim, chomp, split to get a list but best I get is
<<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 to get a list [“172.18.0.247”,“172.18.0.253”,…] that I can use in other part of code.
I want to use contains function on this list to see if a new IP TF is trying to create is already taken or not,
Thanks !