Reputation: 17
I have written a script for function app and it's storage account creation using terraform.
I was having shared access key enabled for storage account but on azure portal in security it shows that function app should access storage account via managed identity, not via shared access key.
So I made changes in my script:
storage_uses_managed_identity
in function appAzureWebJobsStorage__accountName
storage blob data contributor
role in
storage accountBut still it is unable to connect.
Can someone suggest what other changes can be made so that connectivity can be established. When I check in app insight there also it shows exception.
Upvotes: 1
Views: 1304
Reputation: 21
I hope this will help you. For me it works good.
resource "azurerm_windows_function_app" "this" {
.....................
storage_uses_managed_identity = true
storage_account_name = var.storage_account_name
identity {
type = "SystemAssigned"
}
app_settings = {
"WEBSITE_CONTENTSHARE" = var.storage_account_file_share_name
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = var.storage_account_connection_string
"FUNCTIONS_EXTENSION_VERSION" = var.functions_extension_version
"FUNCTIONS_WORKER_RUNTIME" = var.functions_worker_runtime
}
}
And don't forget to create the role assignment resource.
resource "azurerm_role_assignment" "this" {
scope = var.storage_account_id
role_definition_name = "Storage Blob Data Contributor"
principal_id = azurerm_windows_function_app.this.identity[0].principal_id
}
Upvotes: 2
Reputation: 8694
To connect Azure function App with Storage account using Managed Identity:
Storage Account=>Access Control(IAM)=>Add Role Assignment
:I have followed the above-mentioned steps and able to connect the Function App with Storage Account.
References:
Use managed identity instead of AzureWebJobsStorage to connect a function app to a storage account
Upvotes: 0