Terraform workspace

  • terraform workspace new <ENTORNO>
  • terraform workspace list
  • terraform workspace select <ENTORNO>
  • terraform workspace delete <ENTORNO>
  • terraform workspace show
  • se pueden crear tantos entornos como sean necesarios (new)
  • se puede personalizar cada uno de ellos usando objetos
variable "location" {
  type    = "string"
  default = "West Europe"
}
 
variable "wks_rg_name" {
  type = object({
    pre     = string,
    int     = string,
    default = string
  })
}
 
wks_rg_name = {
  pre     = "prepre",
  int     = "intint",
  default = ""
}
 
resource "azurerm_resource_group" "rg" {
  name     = "rg1-rg-${var.wks_rg_name[terraform.workspace]}"
  location = "${var.location}"
 
  tags = {
    status  = "testing"
    empresa = "synectic"
  }
}
 
resource "azurerm_virtual_network" "vnet" {
  name                = "rg1-vnet-${terraform.workspace}"
  location            = "${var.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  address_space       = ["1.0.0.0/22"]
}
 
resource "azurerm_subnet" "subnet" {
  name                 = "rg1-subnet-${terraform.workspace}"
  resource_group_name  = "${azurerm_resource_group.rg.name}"
  virtual_network_name = "${azurerm_virtual_network.vnet.name}"
  address_prefix       = "1.0.1.0/24"
}
  • tech/terraform/poc/workspaces.txt
  • Darrera modificació: 06/04/2020 06:03
  • per mate