Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

Assign an Azure Logic Apps Managed Identity a role with terraform via ARM Deployment?

In azure: while trying to assign a logic apps system assigned managed identity a role for starting/stopping a virtual machine I get the following error message:

Error: authorization.RoleAssignmentsClient#Create: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="PrincipalNotFound" Message="Principal xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exist in the directory xxxxx-x-x-x-xxxx."

My assumption is, that I do not get the right id when the templates output

"[reference(resourceId('Microsoft.Logic/workflows/', 'scheduledvmdown'), '2019-05-01', 'Full').Identity.tenantId]"  

A terraform template deployments output should be used as input for a role assignments principal_id.

I use terraform to deploy the logic app template like this:

    resource "azurerm_template_deployment" "myterraformscheduledvmdown" {
  name                = "scheduledvmdown"
  resource_group_name = "j14t23resources"

  template_body = <<DEPLOY

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
...
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2019-05-01",
            "name": "scheduledvmdown",
            "location": "westus2",
            "identity": {
                "type": "SystemAssigned"
            },
            "properties": 
...

    ],
    "outputs": {
        "appid": {
            "type": "string",
            "value": "[reference(resourceId('Microsoft.Logic/workflows/', 'scheduledvmdown'), '2019-05-01', 'Full').Identity.tenantId]"
...
DEPLOY

  parameters = {
  }

  deployment_mode = "Incremental"
}

output "appid" {
  value = "${lookup(azurerm_template_deployment.myterraformscheduledvmdown.outputs, "appid")}"
}

resource "azurerm_role_assignment" "scheduletovmdown" {
  scope                = azurerm_linux_virtual_machine.myterraformvm.id
  role_definition_name = "Virtual Machine Contributor"
  principal_id         = azurerm_template_deployment.myterraformscheduledvmdown.outputs["appid"]
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Right, it should be principalId, not tenantId:

"[reference(resourceId('Microsoft.Logic/workflows/', 'scheduledvmdown'), '2019-05-01', 'Full').Identity.principalId]"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...