Terraform with Azure-如何创建存储帐户?
在和Terraform战斗了一天之后,我在这里呼救Terraform with Azure-如何创建存储帐户?,azure,terraform,terraform-provider-azure,azure-storage-account,Azure,Terraform,Terraform Provider Azure,Azure Storage Account,在和Terraform战斗了一天之后,我在这里呼救 Terraform v0.11.11 + provider.azurerm v1.20.0 我正在尝试从头创建一个新的资源组和一个存储帐户。看起来可以在没有存储帐户的情况下创建资源组: resource "azurerm_resource_group" "rg1" { name = "myResourceGroup" location = "West Europe" } 资源组已创建,目前不存在存储帐户。所以现在我很高兴。我
Terraform v0.11.11
+ provider.azurerm v1.20.0
我正在尝试从头创建一个新的资源组和一个存储帐户。看起来可以在没有存储帐户的情况下创建资源组:
resource "azurerm_resource_group" "rg1" {
name = "myResourceGroup"
location = "West Europe"
}
资源组已创建,目前不存在存储帐户。所以现在我很高兴。我执行销毁并重新从头开始
现在,在代码中,在创建资源组之后,我想创建一个存储帐户,因为以后其他资源将需要引用它。azurerm_storage_帐户需要的唯一引用是对资源组的引用
关于azurerm\u存储\u帐户的信息
代码如下所示:
resource "azurerm_resource_group" "rg1" {
name = "myResourceGroup"
location = "West Europe"
}
data "azurerm_storage_account" "stacc1" {
name = "mystorageaccount"
resource_group_name = "${azurerm_resource_group.rg1.name}"
}
我运行plan命令并获得以下输出:
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
<= read (data resources)
Terraform will perform the following actions:
<= data.azurerm_storage_account.stacc1
id: <computed>
access_tier: <computed>
account_encryption_source: <computed>
account_kind: <computed>
account_replication_type: <computed>
account_tier: <computed>
custom_domain.#: <computed>
enable_blob_encryption: <computed>
enable_file_encryption: <computed>
enable_https_traffic_only: <computed>
location: <computed>
name: "mystorageaccount"
primary_access_key: <computed>
primary_blob_connection_string: <computed>
primary_blob_endpoint: <computed>
primary_connection_string: <computed>
primary_file_endpoint: <computed>
primary_location: <computed>
primary_queue_endpoint: <computed>
primary_table_endpoint: <computed>
resource_group_name: "myResourceGroup"
secondary_access_key: <computed>
secondary_blob_connection_string: <computed>
secondary_blob_endpoint: <computed>
secondary_connection_string: <computed>
secondary_location: <computed>
secondary_queue_endpoint: <computed>
secondary_table_endpoint: <computed>
tags.%: <computed>
+ azurerm_resource_group.rg1
id: <computed>
location: "westeurope"
name: "myResourceGroup"
tags.%: <computed>
Plan: 1 to add, 0 to change, 0 to destroy.
$terraform平面图
正在计划之前刷新内存中的地形状态。。。
刷新状态将用于计算此计划,但不会更改
持久化到本地或远程状态存储。
------------------------------------------------------------------------
已生成执行计划,如下所示。
资源操作用以下符号表示:
+创造
您需要使用资源,而不是数据实体。所有资源都是如此。数据实体是获取资源数据,而不是创建它们
resource "azurerm_resource_group" "testrg" {
name = "resourceGroupName"
location = "westus"
}
resource "azurerm_storage_account" "testsa" {
name = "storageaccountname"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "westus"
account_tier = "Standard"
account_replication_type = "GRS"
tags {
environment = "staging"
}
}
您需要使用资源,而不是数据实体。所有资源都是如此。数据实体是获取资源数据,而不是创建它们
resource "azurerm_resource_group" "testrg" {
name = "resourceGroupName"
location = "westus"
}
resource "azurerm_storage_account" "testsa" {
name = "storageaccountname"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "westus"
account_tier = "Standard"
account_replication_type = "GRS"
tags {
environment = "staging"
}
}
谢谢!你当然是对的!我想我在某个时候从keyvault定义复制了它,并没有注意到它是数据而不是资源。谢谢!你当然是对的!我想我在某个时候从keyvault定义复制了它,但没有注意到它是数据而不是资源。