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.46k stars 4.54k forks source link

data `azurerm_resources` sometimes could not return all matched resources #10756

Open amosricky opened 3 years ago

amosricky commented 3 years ago

Community Note

Terraform (and AzureRM Provider) Version

Affected Resource(s)

Terraform Configuration Files

data "azurerm_resource_group" "cluster_resource_rg" {
  name       = azurerm_kubernetes_cluster.this.node_resource_group
  depends_on = [azurerm_kubernetes_cluster.this]
}

data "azurerm_resources" "this" {
  resource_group_name = data.azurerm_resource_group.cluster_resource_rg.name
  type = "Microsoft.Compute/virtualMachineScaleSets"
  depends_on = [data.azurerm_resource_group.cluster_resource_rg]
}

resource "azurerm_kubernetes_cluster" "this" {
// have 3 nodepool
}

output "resource_list" {
  value = data.azurerm_resources.this.resources.*.name
}

Debug Output

Panic Output

Expected Behaviour

The output "resource_list" could show 3 vmss name something like: resource_list = tolist([ "aks-monitorpool-34450601-vmss", "aks-systempool-34450601-vmss", "aks-testpool-34450601-vmss" ])

Actual Behaviour

At the first time apply sometimes the output is empty: resource_list = tolist([])

Most of time the output only have one data resource_list = tolist([ "aks-monitorpool-34450601-vmss", ])

Steps to Reproduce

  1. terraform apply

Important Factoids

References

kfkawalec commented 3 years ago

I have the same problem for resources created by AKS. For example code below all nsg but without this related to aks.

data "azurerm_resources" "example" { type = "Microsoft.Network/networkSecurityGroups" }

Tested on version 2.53

Simonzhaohui commented 3 years ago

I got same problem for virtualmachine scale sets resources:

data "azurerm_resources" "scale_set" {
  resource_group_name = data.azurerm_kubernetes_cluster.aks_cluster.node_resource_group
  type                = "Microsoft.Compute/virtualMachineScaleSets"
}

The data.azurerm_resources.scale_set.resources.*.id can't get all matched resource ids. The azurerm version is 2.61

Xat59 commented 2 years ago

I have the same behavior with Microsoft.RecoveryServices resource type :

data "azurerm_resources" "rs" {
  type                = "Microsoft.RecoveryServices"
}

output "rs" {
  value = data.azurerm_resources.rs
}

Here is the output :

rs = {
  "id" = "resource-4761bd34-dfa7-4e37-b3a6-45a4127221cb"
  "resources" = []
  "type" = "Microsoft.RecoveryServices"
}

Note that I have an existing Azure SIte Recovery . Thanks

bradhannah commented 2 years ago

This problem persists - but may be acting as expected? It only returns resources from the current providers subscription. I was expecting it go gather all resources available to the current managed identity.

If this is the intended behaviour, then perhaps updating the docs (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resources) to indicate that would be helpful to folks like me.

On the other hand, being able to walk through all resources of a specific type, in a specified scope such as a Management Group would be amazingly helpful.

harshavmb commented 1 year ago

This problem persists - but may be acting as expected? It only returns resources from the current providers subscription. I was expecting it go gather all resources available to the current managed identity.

Not definitely as expected. The error is seen even on current provider subscription. It works sporadically that itself means there is an issue with this data provider. retry option could be useful..

djk commented 1 year ago

This is still an issue with provider 3.48.0 and is today and yesterday causing issues for us which up until now have not occurred. I don't know if a provider or Azure API change has made this more frequent and likely to happen but it seems like something has happened! We've had to stop using this data source, at least temporarily.

chr1sk1ng commented 1 year ago

Hi, following conversation with Microsoft on this, this works "real-time" atm for "resource group" scoped calls, see below. Based on this, would it be possible (or even make sense anyway) for the API call to be crafted this way for azurerm_resources data source calls where the resource group is specified ?

Powershell (WORKS) GET https://management.azure.com/subscriptions//resourceGroups//resources?api-version=2021-04-01

Terraform (where there is a huge delay in returning new resources) GET https://management.azure.com/subscriptions//resources?$filter=resourceGroup eq '&api-version=2021-04-01

shubham2110 commented 11 months ago

no progress yet ?