使用Terraform添加存储虚拟网络规则

时间:2018-10-31 22:16:37

标签: azure-storage terraform terraform-provider-azure

是否可以像在Azure SQL中那样将虚拟网络规则添加到存储帐户中?有azurerm_sql_virtual_network_rule,但似乎没有存储帐户的等效项。

1 个答案:

答案 0 :(得分:1)

这里是Usage with Network Rules的示例,您可以参考它。

resource "azurerm_resource_group" "testrg" {
  name     = "resourceGroupName"
  location = "westus"
}

resource "azurerm_virtual_network" "test" {
    name = "virtnetname"
    address_space = ["10.0.0.0/16"]
    location = "${azurerm_resource_group.testrg.location}"
    resource_group_name = "${azurerm_resource_group.testrg.name}"
}

resource "azurerm_subnet" "test" {
    name                 = "subnetname"
    resource_group_name  = "${azurerm_resource_group.testrg.name}"
    virtual_network_name = "${azurerm_virtual_network.test.name}"
    address_prefix       = "10.0.2.0/24"
    service_endpoints    = ["Microsoft.Sql","Microsoft.Storage"]
  }

resource "azurerm_storage_account" "testsa" {
    name = "storageaccountname"
    resource_group_name = "${azurerm_resource_group.testrg.name}"

    location = "${azurerm_resource_group.testrg.location}"
    account_tier = "Standard"
    account_replication_type = "LRS"

    network_rules {
        ip_rules = ["127.0.0.1"]
        virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"]
    }

    tags {
        environment = "staging"
    }
}