0

I have some very simple code to do some testing with and I am running into some issues. My overall goal is to have config stored in a .yaml file which I then use templatefile to replace some variables and finally it will be jsonencoded.

main.tf

locals {
  test = yamldecode(templatefile("${path.module}/test.yaml",
    {
      admin_groups         = ["123456-7890"]
    }
  ))
}

output "test" {
  value = jsonencode(local.test)
}

test.yaml

GITLAB_OMNIBUS_CONFIG: |
  gitlab_rails['omniauth_providers'] = |
      admin_groups: ['${admin_groups}']

When terraform plan however I am getting the following error message:

│ Error: Error in function call
│ 
│   on main.tf line 2, in locals:
│    2:   test = yamldecode(templatefile("${path.module}/test.yaml",
│    3:     {
│    4:       admin_groups = ["123456-7890"]
│    5:     }
│    6:   ))
│     ├────────────────
│     │ path.module is "."
│ 
│ Call to function "templatefile" failed: ./test.yaml:3,25-37: Invalid template interpolation value; Cannot include the given value in a string template: string required..

Is there some way to interpolate this list of strings that I am not doing? Cheers for any help.

1
  • Try with double quotes. Commented Sep 21, 2022 at 16:46

1 Answer 1

1

For list in yaml, you should iterate the values like:

test.yaml

GITLAB_OMNIBUS_CONFIG: |
  gitlab_rails['omniauth_providers'] = |
      admin_groups: 
      %{ for g in admin_groups ~}
        - ${g}
      %{ endfor ~}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.