amazon-web-servicesif-statementconditional-statementsterraformaws-lake-formation

Conditional statement for select correct environment permissions terraform


So I have the following within my locals.tf. This is assigning lf-tags for each group depending on what the name of the group is.

group_lf_dev = length(regexall("data-engineers", var.group)) > 0 ? ["raw", "processed", "published"] :
         length(regexall("data-analyst", var.group)) > 0 ? ["published"] :
         length(regexall("account-admin", var.group)) > 0 ? ["raw", "processed", "published"] :
        length(regexall("data-scientist", var.group)) > 0 ? ["published"] : ["No_user"]

Ideally I want to be able to have a conditional statement which will look at what the environment is and based on that assign the relevant lf tags. So if it is dev enrivonment it will assign the above permission and if it is live it will assign a different set of tags.

There is an environment variable in my tfvars which is the following :

environment = "live"
environment = "dev"

I want to make use of this but a little unsure of the approach to take.


Solution

  • Just create another local variable:

    lf_tags = var.environment == "live" ? local.group_lf_live : local.group_lf_dev