简体   繁体   中英

Terraform set variable with default value if empty

Hello i have problem with:

   on ../terraform-modules/terraform-employee/main.tf line 146, in module "ac-vm":
│  146:     token_user            = module.ac-gitlab[0].token
│     ├────────────────
│     │ module.ac-gitlab is empty tuple
│ 
│ The given key does not identify an element in this collection value: the collection has no elements.
  gitlab = {
   token_user            = module.ac-gitlab[0].token

  }

The problem is when it's empty. It is empty because it was not created for him on purpose.

it tries to do if null then some other default value.

I solved.

token_user = length(module.ac-gitlab) > 0 ? module.ac-gitlab[0].token : ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM