Azure 地形状态路径

Azure 地形状态路径,azure,terraform,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

我正在尝试使用以下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:

所以“阶段路径”是空的,看起来很重要。是否有一个参数我应该传递给“terraform apply”或放在tf文件的其他地方,以便获得状态路径?

很可能您已经用一个文件初始化了您的项目。在这种情况下,tf不会将您的状态存储在本地路径上,这会导致在末尾出现空状态路径消息。

状态路径:
为空,因为您没有在上面的配置中配置后端。在这种情况下,terraform将把名为
terraform.tfstate
的状态文件与
.tf
文件的其余部分保持在相同的位置

也就是说,如果您希望
状态路径:
在运行
terraform apply
后具有指向terraform.tfstate文件的完整路径,请按如下所示配置本地后端:

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

谢谢菲什!如果我能从你的链接中很好地理解,如果我有一个远程状态后端,我就不会有本地terraform.tfstate文件。但是,我确实在我当前的文件夹中有它,而且我还没有特意将任何东西配置为使用远程状态后端。我很困惑:-/谢谢!这是有道理的:)