Azure / Azure/terraform-provider-azapi

when using azapi_update_resource... wait for state change?

Open
#366 1 comment 2 reactions 0 assignees View on GitHub
enhancement upstream-api
Dominant language
Go
Stars
244
Forks
97
Avg merge
5d 9h
Merged PRs (30d)
9

Description

Hi,

Considering the following config:

```
data "azurerm_subscription" "current" {}

resource "azapi_update_resource" "EnableEncryptionAtHost" {
type = "Microsoft.Features/featureProviders/subscriptionFeatureRegistrations@2021-07-01"
resource_id = "/subscriptions/${data.azurerm_subscription.current.subscription_id}/providers/Microsoft.Features/featureProviders/Microsoft.Compute/subscriptionFeatureRegistrations/EncryptionAtHost"
body = jsonencode({
properties = {}
})
}
```

The problem is, the command runs but I can see that the resource is still in state "Registering"

`az feature show --namespace "Microsoft.Compute" --name "EncryptionAtHost"
{
"id": "/subscriptions/xxxxxxx/providers/Microsoft.Features/providers/Microsoft.Compute/features/EncryptionAtHost",
"name": "Microsoft.Compute/EncryptionAtHost",
"properties": {
"state": "Registering"
},
"type": "Microsoft.Features/providers/features"
}`

And the resource that depends on this feature to be enabled, throws an error saying the provider is not registered.

**The question is... Is there anyway to wait until the provider has been registered?**

Something like a null resource with a local-exec sleep command might do the trick:

```
resource "null_resource" "providers_registration_delay" {
provisioner "local-exec" {
command = "sleep 1500"
}
depends_on = [ azapi_update_resource.EnableEncryptionAtHostPreview,azapi_update_resource.EnableEncryptionAtHost ]
}

```

BUT, the problem is to include a 25 min delay (that's what it took!) that would then run on every execution...

... Maybe another API query that waits for state value or something? I've been checking the azapi provider documentation and I can't find a way to do something like this...

Any ideas?

Many thanks and best regards,

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the configuration with azapi_update_resource and checking the Azure CLI command `az feature show --namespace "Microsoft.Compute" --name "EncryptionAtHost"`. Investigate how the provider handles asynchronous Azure resource operations and determine where a state wait could belong; done means dependent resources apply successfully only after the feature reaches the registered state.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, terraform
Domain
cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.