Closed earldata closed 1 year ago
Hi! Thanks for raising. This was fixed in 3.4, please update to the latest (3.4.1)
Hi! Thanks for raising. This was fixed in 3.4, please update to the latest (3.4.1)
Strangely with the latest 3.4.1 we are facing this issue.
However, when running it locally it works fine as the module creates all the resources as expected on the first run and this happens only on the runners (self-hosted agent - GitHub).
Initially we thought just the azapi_action is causing the issue but there are few other azapi_action calls which are working fine.
We fixed with the below workaround which is creating the subscription first and then registering the providers finally using the vending module.
locals {
providerList = "Microsoft.Compute, Microsoft.Network"
}
resource "null_resource" "es_register_provider_and_wait_for_state" {
triggers = {
providerList = sha1(local.providerList)
}
provisioner "local-exec" {
command = <<-EOT
az login --service-principal --username $env:ARM_CLIENT_ID --password $env:ARM_CLIENT_SECRET --tenant $env:ARM_TENANT_ID --output none
az account set -s "${azurerm_subscription.workload.subscription_id}"
$providersToRegister = '${local.providerList}' -split ',' | ForEach-Object { $_.Trim() }
foreach ($provider in $providersToRegister) {
$registrationState = (az provider show --namespace $provider | ConvertFrom-Json).registrationState
if ($registrationState -eq "Registered") {
Write-Host "##[section] ($provider) already registered..." -ForegroundColor Green
}
else {
az provider register --namespace $provider
Write-Host "##[section] ($provider) registering..." -ForegroundColor Green
$found = "Registering.."
$breakafterMultipleRetry = 1
while ("Registered" -ne $found) {
Write-Host "##[section] Waiting for the ($provider) registration to complete"
Start-Sleep 30
$found = (az provider show --namespace $provider | ConvertFrom-Json).registrationState
if ($breakafterMultipleRetry -eq 10) {
Write-Host "##[error] Unable to register provider ($provider) with the newly vended subscription"
break
}
$breakafterMultipleRetry++
}
Write-Host "##[section] ($provider) $found" -ForegroundColor Green
}
}
EOT
interpreter = ["pwsh", "-Command"]
}
depends_on = [azurerm_subscription.workload
]
}
Below are the plugins and their versions.
Downloading registry.terraform.io/Azure/lz-vending/azurerm 3.4.1 for lz_vending...
- lz_vending in .terraform/modules/lz_vending
- lz_vending.resourcegroup in .terraform/modules/lz_vending/modules/resourcegroup
- lz_vending.resourcegroup_networkwatcherrg in .terraform/modules/lz_vending/modules/resourcegroup
- lz_vending.resourceproviders in .terraform/modules/lz_vending/modules/resourceprovider
- lz_vending.roleassignment in .terraform/modules/lz_vending/modules/roleassignment
- lz_vending.roleassignment_umi in .terraform/modules/lz_vending/modules/roleassignment
- lz_vending.subscription in .terraform/modules/lz_vending/modules/subscription
- lz_vending.usermanagedidentity in .terraform/modules/lz_vending/modules/usermanagedidentity
- lz_vending.virtualnetwork in .terraform/modules/lz_vending/modules/virtualnetwork
Initializing provider plugins...
- Finding hashicorp/null versions matching ">= 3.0.0"...
- Finding hashicorp/azurerm versions matching ">= 3.7.0, >= 3.62.0"...
- Finding hashicorp/time versions matching ">= 0.9.0"...
- Finding azure/azapi versions matching ">= 1.3.0, >= 1.4.0, >= 1.8.0"...
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.79.0...
- Installed hashicorp/azurerm v3.79.0 (signed by HashiCorp)
- Installing hashicorp/time v0.9.1...
- Installed hashicorp/time v0.9.1 (signed by HashiCorp)
- Installing azure/azapi v1.10.0...
- Installed azure/azapi v1.10.0 (signed by a HashiCorp partner, key ID *****)
Any insights would be helpful.
Community Note
Versions
Please paste the output of
terraform version
command from within the initialized directory:Please enter the module version that you are using:
Description
When creating a subscription with virtual network enabled it fails on the first run with:
I believe this is because the Microsoft.Network provider has not been registered yet. This can be seen in the terraform output:
As above you can see that the vnet is created before the provider is registered.
Steps to Reproduce
The following config was used:
Screenshots
Additional context