terraform 工作区
ディレクトリを切りなおさなくても、環境を切り替えることでそれぞれのstateファイルを管理するための機能
准备就绪
创建工作空间
terraform workspace new prod
terraform workspace new stg
显示工作区列表
terraform workspace list
工作区的指定
terraform workspace select prod
terraform文件
AzureResourceGroupを環境ごとに作成するだけのもの
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.46.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "resource_group" {
name = "${var.env}-resourcegroup"
location = "japaneast"
}
variable "env" {
type = string
}
env = "production"
env = "staging"
应用 Terraform
设立
terraform workspace select stg
terraform apply -var-file=terraform.tfvars.staging
生产
terraform workspace select prod
terraform apply -var-file=terraform.tfvars.production