How can i pass a value to local variable in terraform based on a flag. The challenge is there are multiple flags

Viewed 17

can i get some help on this please? i want to assign the local variable based on the flags. The challenge is there are multiple flags and based on the flag set to true i should have my local variable set ...

example i have the following flags

docker_enabled = true
maven_enabled = false
nugget_enabled = flase

in my local i should have a condition to set the package_type as "docker" if docker_enabled flag is true and similiarly package_type should be maven if maven_enabled is true

something like this ..

  `package_type = local.docker_enabled ? local.docker_package : null || local.generic_enabled ? local.generic_package : null || local.maven_enabled ? local.maven_package : null

  dev_repo  = formatlist("%s-dev-%s-local", local.tla, local.package_type )
  uat_repo  = formatlist("%s-uat-%s-local", local.tla, local.package_type)
  prod_repo = formatlist("%s-prod-%s-local", local.tla, local.package_type)
  virtual_repo    = formatlist("%s-%s-virtual", local.tla, local.package_type)
  premission_repos = concat(local.dev_repo, local.uat_repo, local.prod_repo)`

The issue am facing is when i make "false" all the 3 (docker,maven and nugget) it complains package_type cant be null

any help much appreciated here.. thank you

0 Answers
Related