hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.65k forks source link

Bad import state for identity block in azurerm_logic_app_workflow #27463

Open seblatre opened 1 month ago

seblatre commented 1 month ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.5

AzureRM Provider Version

3.116.0

Affected Resource(s)/Data Source(s)

azurerm_logic_app_workflow

Terraform Configuration Files

resource "azurerm_logic_app_workflow" "logic_app" {

  name                = "my-wonderful-logic-app"
  location            = "westeurope"
  resource_group_name = "DEVA42TEST

  identity {
    type = "SystemAssigned"
  }

  lifecycle {
    ignore_changes = [parameters, workflow_parameters, enabled]
  }
}

variable "group" {
  description = "The group to add members to"
  type = object({
    display_name = string
    id           = string
    object_id    = string
  })
}

resource "azuread_group_member" "member" {
  group_object_id  = var.group.object_id
  member_object_id = azurerm_logic_app_workflow.logic_app.identity[0].principal_id
}

Debug Output/Panic Output

Not useful for this use case

Expected Behaviour

Being able to Import an existing logic app without system managed identity yet

Actual Behaviour

Steps to Reproduce

  1. A logic app must be already existing on Azure with no Managed Identity with resource id /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/DEVA42TEST/providers/Microsoft.Logic/workflows/my-wonderful-logic-app
  2. Ask the logic app to be imported in the state through import block in a .tf file
    import {
    to = azurerm_logic_app_workflow.logic_app
    id = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/DEVA42TEST/providers/Microsoft.Logic/workflows/my-wonderful-logic-app"
    }
  3. Launch a plan terraform plan

Important Factoids

None

References

No response

ziyeqf commented 1 month ago

Hi @seblatre, thanks for opening the issue.

There might 2 issues involved, first is the provider does not produce the correct plan value. Second is the somehow azuread_group_member. member did not get the value of azurerm_logic_app_workflow.logic_app.identity[0].principal_id after the modification finished. I'm still working on it and will let you know once I made progress.

Thanks

seblatre commented 1 month ago

@ziyeqf, for what I could understand here is that the plan is not complete in the third case I presented. Looking at the plan, there is absolutely no mention of identity.principal_id (with a value or a not yet known value). Without that, I think that the engine is lost and not able to propose any value for this field (hence the no definition found error)

ziyeqf commented 1 month ago

Hi @seblatre,

I have reproduced this issue before but with the latest Terraform and provider, it works properly, it might because of this PR(https://github.com/hashicorp/terraform/pull/35644) on Terraform, do you mind try it again? my versions:

❯❯ tf version   
Terraform v1.9.7
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azurerm v4.5.0

my configuration:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "test-logic"
  location = "westus2"
}

resource "azurerm_logic_app_workflow" "test" {
  name                = "test-workflow"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name

  lifecycle {
    ignore_changes = [ tags, identity ]
  }
}

import {
  id = "/subscriptions/<sub_id>/resourceGroups/test-logic/providers/Microsoft.Logic/workflows/test-logic"
  to = azurerm_logic_app_workflow.test
}

output "identity_id" {
  value = azurerm_logic_app_workflow.test.identity[0].principal_id
}
seblatre commented 3 weeks ago

Hello @ziyeqf, I just saw you answer but I'm on vacation right now. I'll check that at my return. But that sounds good :)

seblatre commented 1 week ago

Hello @ziyeqf, I just tested the behavior on the following stack:

$ terraform version
Terraform v1.9.8
on windows_amd64
+ provider registry.terraform.io/hashicorp/azurerm v4.5.0
[...]

and just hit the exact same issue.

In your example, I think that the following block is missing in your logic app to reproduce the same issue.

  identity {
    type = "SystemAssigned"
  }

Also the logic app must not have any identity defined on it (set it to off). The use of azuread_group_member resource may be needed as well because I think the issue lies within the plan workflow and just outputting the value may not be sufficient to make the issue appear.

ziyeqf commented 1 week ago

Oh, I reproduced the issue, still looking into it