Terraform output in formatted way

356 views
Skip to first unread message

Sidh

unread,
Aug 31, 2019, 5:52:46 PM8/31/19
to Terraform
Need to get output in CIDR notation. 

data "dns_a_record_set" "google" {
  host = "www.google.com"
}

output "google" {
  value =  ["${join("/32,", data.dns_a_record_set.google.addrs)}"]}
}

trying to get output as :


instead getting output as [1.2.3.4/32, 5.6.7.8]

So , no quotes and /32 missing in last value. Any suggestions ?

Sidh

Giovanni Tirloni

unread,
Aug 31, 2019, 8:48:59 PM8/31/19
to terrafo...@googlegroups.com
https://www.terraform.io/docs/configuration/functions/formatlist.html

formatlist("%s/32", data.dns_a_record_set.google.addrs)
> --
> This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/terraform/issues
> IRC: #terraform-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups "Terraform" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/b5bbe6aa-fba3-4783-9854-a50e61a0c4b7%40googlegroups.com.

Sidh

unread,
Sep 1, 2019, 1:09:41 PM9/1/19
to Terraform
Thanks for the idea. It worked partially. Somehow I am not able to grab it in brackets. like ["1.2.3.4\32", "5.6.7.8\32"],
Output is : "1.2.3.4\32", "5.6.7.8\32" at the moment. i.e. without brackets.

Regards,
Sidh

On Sunday, September 1, 2019 at 2:48:59 AM UTC+2, Giovanni Tirloni wrote:
https://www.terraform.io/docs/configuration/functions/formatlist.html

formatlist("%s/32", data.dns_a_record_set.google.addrs)

On Sat, Aug 31, 2019 at 6:52 PM Sidh <sidhur...@gmail.com> wrote:
>
> Need to get output in CIDR notation.
>
> data "dns_a_record_set" "google" {
>   host = "www.google.com"
> }
>
> output "google" {
>   value =  ["${join("/32,", data.dns_a_record_set.google.addrs)}"]}
> }
>
> trying to get output as :
>
> ["1.2.3.4/32", "4.5.6.7/32"]
>
> instead getting output as [1.2.3.4/32, 5.6.7.8]
>
> So , no quotes and /32 missing in last value. Any suggestions ?
>
> Sidh
>
> --
> This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/terraform/issues
> IRC: #terraform-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups "Terraform" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to terrafo...@googlegroups.com.

Sidh

unread,
Sep 2, 2019, 4:56:11 PM9/2/19
to Terraform
Was able to grab output in formatted way with [] but terraform security group is complaining that it's not valid CIDR.

aws_security_group.dynamic-egress-sg-https: "egress.0.cidr_blocks.0" must contain a valid CIDR, got error parsing: invalid CIDR address: ["216.58.207.164/32"]
Reply all
Reply to author
Forward
0 new messages