skip to Main Content

Lets suppose I have dev, uat and prod environment. I wan’t to have some modules to be deployed in the dev environment but not in other environment.

I want to put a condition based on the workspace I have but can’t figure it out how. Any recommendation would be appreciated.

I tried to use $(terraform.workspace) to select ‘dev’ enviroment but wasn’t working.

count = $(terraform.workspace) == "dev" ? 1 : 0 and it says 

which resulted in:

This character is not used within the language.

2

Answers


  1. You don’t need to use $ sign.

    count  = terraform.workspace == "dev" ? 1 : 0
    
    Login or Signup to reply.
  2. There are two different styles and two different logics to write this condition.

    Different Styles

    • If terraform.workspace is equal to "dev" then create one instance else zero instance.
    count = "${terraform.workspace}" == "dev" ? 1 : 0
    count = terraform.workspace == "dev" ? 1 : 0
    

    Another logic

    • If terraform.workspace is not equal to "dev" then create zero instance else one instance.
    count = "${terraform.workspace}" != "dev" ? 0 : 1
    count = terraform.workspace != "dev" ? 0 : 1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search