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.64k forks source link

azurerm_container_app_environment throws error when log analytics workspace located in different subscription #25514

Open Chasermistrz opened 7 months ago

Chasermistrz commented 7 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.7.5

AzureRM Provider Version

3.97.1

Affected Resource(s)/Data Source(s)

azurerm_container_app_environment

Terraform Configuration Files

data "azurerm_container_app_environment" "app_env" {
  name                = "my-aca-env"
  resource_group_name = "aca-rg"
}

Debug Output/Panic Output

│ Error: retrieving Log Analytics Workspace: no matching workspace found
│ 
│   with data.azurerm_container_app_environment.app_env,
│   on data.tf line 44, in data "azurerm_container_app_environment" "app_env":
│   44: data "azurerm_container_app_environment" "app_env" {
│ 
│ retrieving Log Analytics Workspace: no matching workspace found

Expected Behaviour

Data source should be propagated successfully without error.

Actual Behaviour

azurerm_container_app_environment data source throws error when log analytics workspace assigned to Azure Container Apps environment (Monitoring -> Logging options -> Logs Destination -> Azure Log Analytics) is located in different subscription. The last working version of provider is 3.73.0, bug was introduced in https://github.com/hashicorp/terraform-provider-azurerm/pull/23298, 3.74.0 and newer versions are affected.

Steps to Reproduce

  1. Create Azure Container Apps environment with assigned log analytics workspace from different subscription than environment (same tenant)
  2. Attach its name and resource group name to azurerm_container_app_environment data source
  3. terraform plan

Important Factoids

No response

References

https://github.com/hashicorp/terraform-provider-azurerm/pull/23298

MatthewJNixon commented 6 months ago

Hi guys,

We've encountered the exact same thing with the following setup with azurerm_container_app and azurerm_container_app_environment:

Terraform Version 1.7.5

AzureRM Provider Version 3.98.0

Dev Subscription: Container App Environment

We can create the Container App Environment under TF using azurerm linking to the Management Subscription log analytics workspace. Once we then began deploying Container Apps we encountered the exactly same Error: retrieving Log Analytics Workspace: no matching workspace found . We circumvented this by linking the child container app/job to the LAW via ID, e.g.

resource "azurerm_container_app" "some_container_app" {
  name = "some-container-app"
  container_app_environment_id = "/subscriptions/*****/resourceGroups/some-resource-group/providers/Microsoft.App/managedEnvironments/some-container-app-environment"
  resource_group_name          = "some-child-resource-group
# The rest of the azurerm_container_app definition

rather than using a data "azurerm_container_app_environment" block

Hope this helps others!

mapperCoderZ commented 5 months ago

Hello, I have this bug appearing when I try to create a azurerm_container_app_environment_custom_domain to an existing container app environment linked to a LAW in another subscription too. It's anoying because the previous workaround does not seem to work for me.

│ Error: retrieving Log Analytics Workspace: no matching workspace found
│ 
│   with module.container_apps.azurerm_container_app_environment_custom_domain.container_app_environment_domain,
│   on ../../../../**********/modules/azure/containerapps/container_app_environment.tf line 31, in resource "azurerm_container_app_environment_custom_domain" "container_app_environment_domain":
│   31: resource "azurerm_container_app_environment_custom_domain" "container_app_environment_domain" {
│ 
│ retrieving Log Analytics Workspace: no matching workspace found
sohocine commented 3 months ago

This bug is still occuring as of azurerm 3.115.0 Any planned resolution?

pmatthews05 commented 5 days ago

Any new on this issue? Any idea of a fix?