How can I set a Variable so it can be used across different Spaces

Hello,

We have a business case where we would like to set Variables across multiple Spaces (set up a variable in one place and that this one can be referenced in multiple spaces). Is this possible or variables are just project scope?

Thanks!

Hi @nicolas.spencer,
You can use Library Variable Sets to reference variables across multiple projects within a space, but Spaces are different in that they are hard-walls and as such sharing isn’t possible across different Spaces without some workarounds or extra legwork.

You could look into a project like Space Cloner to copy designated variables across your different spaces (with the exception of sensitive variables). Another option might be utilizing our Terraform Provider and using it to create standards for your variables.

I hope this helps!

Happy deployments,
Mark

Hi @mark.reeder thank you very much for your answer. I think we will go for the Terraform option. I did a test and it works ok when setting up just one Space. When using multiple Spaces, the Octopus Deploy Provider Documentation says that to do that you should use multiple instances of the provider with aliases. This is what I’m doing:

terraform {
  required_providers {
    octopusdeploy = {
      source = "OctopusDeployLabs/octopusdeploy"
    }
  }
}

provider "octopusdeploy" "unscoped" {
  name    = var.serverURL
  api_key = var.apiKey
}

data "octopusdeploy_space" "devops" {
  provider = octopusdeploy.unscoped
  name     = "DevOps"
}

provider "octopusdeploy" {
  alias    = "space_devops"
  address  = var.serverURL
  api_key  = var.apiKey
  space_id = data.octopusdeploy_space.devops.id
}

data "octopusdeploy_space" "dataplatform" {
  provider = octopusdeploy.unscoped
  name     = "DataPlatform"
}

provider "octopusdeploy" {
  alias    = "space_dataplatform"
  address  = var.serverURL
  api_key  = var.apiKey
  space_id = data.octopusdeploy_space.dataplatform.id
}

and I get this error from Terraform:

╷
│ Error: Extraneous label for provider
│
│ On providers.tf line 9: Only 1 labels (name) are expected for provider blocks.

So I’m stuck at this point.

Also, I’m using the octopusdeploy_library_variable_set resource following the documentation from the Terraform Registry. I can create a template in there but I can’t find a way to create variables inside the variable set.

# resource "octopusdeploy_library_variable_set" "newvariableset" {
#   description = var.description
#   name        = var.variableSetName
#   space_id    = var.space_id

#   template {
#     name          = "Variable_1"
#     default_value = "Value_1"
#   }

# }

How can I add variables to the variable set as I would do it in the console?

Thank you very much!
Cheers,
Nicolas