2017-07-06 90 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