Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: importing resources @ 2015-11-01 #4148

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

tombuildsstuff
Copy link
Contributor

This is a curious choice so it's worth some context.

The Key Vaults List endpoint appears to have a series of caching issues, where the cache is only appended to/removed from, rather than being updated/invalidated upon changes happening. This means that it's possible for the cache to become outdated and contain a limited subset of Resources - as in our case this is currently returning only 2 of 10 provisioned Key Vaults.

Whilst that's arguably worth a bug report to the API, checking the Azure CLI's implementation, the command az keyvault list performs two queries:

  1. /subscriptions/XXX/resources?$filter=resourceType%20eq%20%27Microsoft.KeyVault%2Fvaults%27&api-version=2015-11-01
  2. /subscriptions/XXX/providers/Microsoft.KeyVault/managedHSMs?api-version=2023-07-01

This means that the Azure CLI itself isn't using the Key Vault List endpoint and for the life of me I can't find an explanation as to the why - so in lieu of any other options, we're going to use same older API version as the Azure CLI and populate the cache in the AzureRM Provider using both the List on the Resource Type endpoint and a List on the Resources endpoint.

I'd rather not use an API version this old when a newer one is available - but the Azure CLI has opted to do so, so there must be a reason for it - I would assume there's no cache on this API Version, but I can't (easily) confirm that. So this'll have to do.

This is a curious choice so it's worth some context.

The Key Vaults List endpoint appears to have a series of caching issues, where the cache is only appended to/removed from, rather
than being updated/invalidated upon changes happening. This means that it's possible for the cache to become outdated and contain
a limited subset of Resources - as in our case this is currently returning only 2 of 10 provisioned Key Vaults.

Whilst that's arguably worth a bug report to the API, checking the Azure CLI's implementation, the command `az keyvault list` performs
two queries:

1. `/subscriptions/XXX/resources?$filter=resourceType%20eq%20%27Microsoft.KeyVault%2Fvaults%27&api-version=2015-11-01`
2. `/subscriptions/XXX/providers/Microsoft.KeyVault/managedHSMs?api-version=2023-07-01`

This means that the Azure CLI itself isn't using the Key Vault List endpoint and for the life of me I can't find an explanation as
to the why - so in lieu of any other options, we're going to use same older API version as the Azure CLI and populate the cache
in the AzureRM Provider using both the List on the Resource Type endpoint and a List on the Resources endpoint.

I'd rather not use an API version this old when a newer one is available - but the Azure CLI has opted to do so, so there must be
a reason for it - I would assume there's no cache on this API Version, but I can't (easily) confirm that. So this'll have to do.
@tombuildsstuff tombuildsstuff requested a review from a team May 21, 2024 10:26
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@tombuildsstuff tombuildsstuff merged commit 2c09c9e into main May 21, 2024
3 checks passed
@tombuildsstuff tombuildsstuff deleted the f/resources-2015-11-01 branch May 21, 2024 11:07
tombuildsstuff added a commit to hashicorp/terraform-provider-azurerm that referenced this pull request May 23, 2024
…t and the Resources Endpoint

This commit:

1. Registers a client for Resources@2015-11-01 and KeyVault@2023-07-01
2. Updates the caching to retrieve the list of Key Vaults using both the List API for the ResourceType and using the
   Resources API directly - meaning we have a more up-to-date set of data.

Notably we're using the older Resources API that the Azure CLI uses, more details can be found in hashicorp/pandora#4148
however by loading both we're hoping to alleviate the caching issues we've seen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants