首页 > 解决方案 > ADF 和存储帐户的 Terraform 身份访问

问题描述

我想使用我知道怎么做的 terraform 创建 ADF 和存储帐户。在此之后,我想授予 ADF 身份访问存储帐户的权限。我可以使用 powershell 来做到这一点。但是当我使用 powershell 时会出现幂等性问题。是否可以在不使用 powershell 的情况下使用 terraform 本身实现访问?

标签: azureterraform-provider-azure

解决方案


您应该创建一个azurerm_role_assignment授予 ADF 访问 Azure 存储帐户的权限。

请检查下面的示例。此代码段将Storage Blob Data Reader角色分配给 ADF。

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_data_factory" "example" {
  name                = "example524657"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  identity {
    type = "SystemAssigned"
  }
}

resource "azurerm_storage_account" "example" {
  name                     = "examplestr524657"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "RAGRS"
}

resource "azurerm_role_assignment" "example" {
  scope                = azurerm_storage_account.example.id
  role_definition_name = "Storage Blob Data Reader"
  principal_id         = azurerm_data_factory.example.identity[0].principal_id
}

推荐阅读