Azure / terraform-provider-azapi

Terraform provider for Azure Resource Manager Rest API
https://registry.terraform.io/providers/Azure/azapi/latest
Mozilla Public License 2.0
173 stars 47 forks source link

`azapi_resource_action` - resource_id validate error for Providers Register At Management Group Scope method #326

Open teowa opened 1 year ago

teowa commented 1 year ago

the POST method: Providers - Register At Management Group Scope config:

provider "azurerm" {
  features {}
}

data "azurerm_management_group" "example" {
  name = "00000000-0000-0000-0000-000000000000"
}
resource "null_resource" "register_rp_to_mg" {
  provisioner "local-exec" {
    command = <<CMD
         az provider register --namespace 'Microsoft.Network' -m ${data.azurerm_management_group.example.name}
    CMD
  }
}

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
}

resource "azapi_resource_action" "rp2mg" {
  type        = "Microsoft.Resources/providers@2021-04-01"
  resource_id = "${data.azurerm_management_group.example.id}/providers/Microsoft.Network"
  action      = "register"
  method      = "POST"
}

error:

╷
│ Error: invalid resource ID: /providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network
│ 
│   with azapi_resource_action.rp2mg,
│   on main.tf line 29, in resource "azapi_resource_action" "rp2mg":
│   29:   resource_id = "${data.azurerm_management_group.example.id}/providers/Microsoft.Network"
│ 
╵
ms-henglu commented 1 year ago

Hi @teowa ,

Thank you for taking time to report this issue!

It's caused by upstream-sdk that management group scoped provider ID couldn't be parsed correctly, I've created an issue to track it: https://github.com/Azure/azure-sdk-for-go/issues/21319

marvinbuss commented 1 month ago

I was just running into the same issue. It looks like the upstream issue was just closed without further action. Would be great to get this resolved to avoid falling back on Azure CLI or other client tools.