Terraspace documentation regarding terraspace "env variable"?

Hi @tung ,

Is it possible to detail the Terraspace documentation regarding these variables (I don’t know how we should call them)

:PROJECT
:TYPE_DIR
:APP
:ROLE
:MOD_NAME
:ENV
:EXTRA
:LOCATION
...

Can you have a list with all these special variables used by Terraspace please?
There is one a bit confused. :LOCATION and :REGION, it’s the same thing?
on config/app.rb, it’s :REGION and on the terraform backend (for azurrerm for example), it’s :LOCATION

I understand that we can set TS_APP env var for defining :APP from export command (same for :ENV with TS_ENV)
But overall, I am a bit lost with these special (but very useful) variables… can you clarify these special variables please?
Like can we do
export TS_MY_VARIABLE='boltops' && terraspace build demo
then I can use :MY_VARIABLE/ in app.rb or my azure backend tfstate key expansion??

Hope my request is clear. Thanks!

Believe this is what you’re looking for

https://terraspace.cloud/docs/config/backend/variables/

1 Like

Yes thanks… I was going to reply myself that I found it on that link too.
So we stick to that list… we cannot add dynamically (multiple) new ones or can only use the :EXTRA one for the whole project? I guess it will be troublesome to handle that

Thanks anyway

Related PRs:

RE: we cannot add dynamically (multiple) new ones or can only use the :EXTRA one for the whole project?

Believe a boot hook can help with that. Take a look at Boot Hooks - Terraspace

With the boot hook, you can run any arbitrary logic you need early on. This includes setting one more multiple environment variables. You can key off of one env var, and based off of that set additional variables dynamically if you wish.

Also, other users have done some interesting things with the boot hook

Thanks, I will have a look on it.

By the way, I guess a mistypo (or bad copy-paste :slight_smile: ) in the backend variable doc
(weird, it seems that the upload image feature is broken, I can upload the it doesn’t display my screenshot)
image

Azure Specific Variables

VARIABLE EXAMPLE DESCRIPTION
APP_HASH wxyz Short consistent hash based on TS_APP value.
LOCATION eastus Azure Location. Can be set with ARM_LOCATION. Also can be set by az configure --defaults location=westus
LOCATION_HASH wxyz Short consistent hash based on Azure location.
SUSCRIPTION EXAMPLE88-c44e-4677-bf0eEXAMPLE Azure subscription id. Can be set by ARM_SUBSCRIPTION_ID.
SUSCRIPTION_HASH wxyz Short consistent hash based on subscription id.

Sorry another question regarding these variables

No issue to use them in ./config/terraform/provider.tf ?
Example: I would like to have my subscription id to be set from env var / parameter:
subscription_id can be set via ENV or expansion() ?
I tried each way, it seems to work but I would like to be sure that it’s safe (like no impact for terraspace/terraform process (now and future))? Sounds weird to ask but since you mentioned these variables in the backend config variable docuementation only (:SUBSCRIPTION) and not for the rest of the “./config” folder I prefer to ask
Thanks

provider "azurerm" {
  features {
    key_vault {
      purge_soft_delete_on_destroy = true
    }
  } # required
  tenant_id       = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  #subscription_id = "<%= expansion(':SUBSCRIPTION') %>"
  subscription_id = "<%= ENV['ARM_SUBSCRIPTION_ID'] %>"
  #subscription_id = "xxxxxxxxxxxxxxx"
}

Don’t see ENV['ARM_SUBSCRIPTION_ID'] and expansion(':SUBSCRIPTION') behavior changing. If it does, will try to bump major version.

1 Like