Terraform variable interpolation with match operator

313 views
Skip to first unread message

Bubunia Patra

unread,
Apr 5, 2018, 2:03:49 AM4/5/18
to Terraform
Hi all,

I am exploring a way to check if we have a match operator in variable interpolation. For example:

I want to match the server name and do some action and send the result to the user data script.

abc1, def1, mno1 etc.

I want to check if the variable matches with any of the pattern as above then pass the value.

How can we achieve this using terraform? 

Regards
Pradeep

Lowe Schmidt

unread,
Apr 5, 2018, 4:57:54 AM4/5/18
to terrafo...@googlegroups.com

--
Lowe Schmidt | +46 723 867 157

--
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-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/9b2483df-eeb7-4957-8553-0fe90aed35de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bubunia Patra

unread,
Apr 5, 2018, 9:53:56 AM4/5/18
to Terraform
yes. could you please provide me a example. I tried this and it doesn't work.


locals {
  trusted_sources = [
   {
      cidr = "255.255.255.255/32"
      desc = "test office 2"
      type = "office"
    },
    {
       cidr = "255.255.255.254/32"
      desc = "test office 1"
      type = "office"
    },
    {
      cidr = "255.255.255.253/32"
      desc = "test vpn"
      type = "vpn"
    },
  ]
}

data "null_data_source" "test" {
  count = "${length(locals.trusted_sources)}"
  inputs = {
    type = "${ lookup(locals.trusted_sources[count.index], "type", "") }"
    cidr = "${ lookup(locals.trusted_sources[count.index], "cidr", "") }"
    desc = "${ lookup(locals.trusted_sources[count.index], "desc", "") }"
  }
}

output "offices" {
  value = "${ matchkeys(data.null_data_source.test.*.outputs, data.null_data_source.test.*.outputs.type, list("office"))}"
}


On Thursday, April 5, 2018 at 4:57:54 PM UTC+8, Lowe Schmidt wrote:

--
Lowe Schmidt | +46 723 867 157

On 5 April 2018 at 08:03, Bubunia Patra <bubunia...@gmail.com> wrote:
Hi all,

I am exploring a way to check if we have a match operator in variable interpolation. For example:

I want to match the server name and do some action and send the result to the user data script.

abc1, def1, mno1 etc.

I want to check if the variable matches with any of the pattern as above then pass the value.

How can we achieve this using terraform? 

Regards
Pradeep

--
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.
Reply all
Reply to author
Forward
0 new messages