Terraform状态路径

时间:2017-07-06 11:53:49

标签: azure terraform

我尝试使用此example.tf文件创建一个包含Terraform.io的资源组:

# Configure Azure provider
provider "azurerm" {
  subscription_id = "${var.azure_subscription_id}"
  client_id       = "${var.azure_client_id}"
  client_secret   = "${var.azure_client_secret}"
  tenant_id       = "${var.azure_tenant_id}"
}

# Create a resource group
resource "azurerm_resource_group" "terraform-rg" {
  name     = "terraform-rg"
  location = "ukwest"
}

看起来一切顺利,但最后我对此消息略感担忧:

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:

所以"舞台路径"是空的,看起来很重要。我应该传递给#34; terraform apply"或者把它放在tf文件中的其他地方以便我得到状态路径?

2 个答案:

答案 0 :(得分:1)

state path:为空,因为您未在上面的配置中配置后端。在这种情况下,terraform会将名为terraform.tfstate的状态文件保留在与.tf文件的其余部分相同的位置

也就是说,如果您希望state path:在运行terraform apply后拥有terraform.tfstate文件的完整路径,请按如下方式配置本地后端:

terraform {
  backend "local" {
    path = "/path_to_statefile_location/terraform.tfstate"
  }
}

https://www.terraform.io/docs/backends/types/local.html

答案 1 :(得分:0)

您很可能已使用remote state backend初始化项目。在这种情况下,tf不会将您的状态存储在本地路径上,这会在结尾处产生一个空的状态路径消息。