2017-07-06 89 views
0

我试图创建Terraform.io资源组与此example.tf文件:Terraform国道

# 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文件中的其他地方,以便我得到一个状态路径?

回答

1

state path:为空,因为您没有在上面的配置中配置后端。在这种情况下terraform将保持称为terraform.tfstate状态文件在同一位置.tf文件

这就是说的休息,如果你想state path:有你terraform.tfstate文件的完整路径运行terraform apply之后再配置本地后端如下:

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

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

+0

谢谢!这是有道理的:) – zapatilla

0

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

+0

感谢fishi!如果我从你的链接中得到很好的理解,如果我有一个远程状态后端,我就不会有一个本地的terraform.tfstate文件。不过,我确实已将它放在当前文件夹中,而且我没有故意配置任何使用远程状态后端的东西。我很困惑: -/ – zapatilla