terraform-provider-azurerm icon indicating copy to clipboard operation
terraform-provider-azurerm copied to clipboard

data `azurerm_resources` sometimes could not return all matched resources

Open amosricky opened this issue 4 years ago • 8 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

  • Terraform v0.14.7
  • provider registry.terraform.io/hashicorp/azurerm v2.45.1

Affected Resource(s)

  • azurerm_resources

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

  • #7035 (In this issue the similar bug seems be fixed in azurerm version = "~> 2.11.0". I use azurerm v2.45.1, however, it still not work)

amosricky avatar Feb 27 '21 04:02 amosricky

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

kfkawalec avatar Mar 31 '21 08:03 kfkawalec

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

Simonzhaohui avatar Jul 07 '21 05:07 Simonzhaohui

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

Xat59 avatar Jan 07 '22 16:01 Xat59

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.

bradhannah avatar Apr 26 '22 14:04 bradhannah

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..

harshavmb avatar Nov 03 '22 16:11 harshavmb

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.

djk avatar Mar 22 '23 14:03 djk

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/<sub_id>/resourceGroups/<RG_Name>/resources?api-version=2021-04-01

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

chr1sk1ng avatar Mar 31 '23 08:03 chr1sk1ng

no progress yet ?

shubham2110 avatar Aug 09 '23 11:08 shubham2110