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.53k stars 4.6k forks source link

Chaos Studio Context Deadline Exceeded #27452

Open theangrytech-git opened 2 days ago

theangrytech-git commented 2 days ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.5

AzureRM Provider Version

4.0.1

Affected Resource(s)/Data Source(s)

azurerm_chaos_studio_capability, azurerm_chaos_studio_target

Terraform Configuration Files

/*******************************************************************************
********************************************************************************
                          CHAOS STUDIO SECTION
/*******************************************************************************
*******************************************************************************/

/*******************************************************************************
                      REGISTER AZURE CHAOS PROVIDER
*******************************************************************************/

resource "null_resource" "register_chaos_provider" {
  provisioner "local-exec" {
    command = "az provider register --namespace Microsoft.Chaos"
  }

  # Ensure this runs only once by using a trigger
    triggers = {
    always_run = "${timestamp()}"
  }
}

/********************************************************************************
                            CREATE SERVICE PRINCIPAL
********************************************************************************/
resource "azuread_application" "cs_app" {
  display_name = "chaos-studio-sp"
}

resource "azuread_service_principal" "cs_sp" {
  client_id = azuread_application.cs_app.client_id
  use_existing = true
}

resource "azuread_service_principal_password" "cs_sp_pw" {
  service_principal_id = azuread_service_principal.cs_sp.id
  end_date             = local.expiration_date
}

output "client_id" {
  value = azuread_service_principal.cs_sp.client_id
}
output "client_secret" {
  value = azuread_service_principal_password.cs_sp_pw.value
  sensitive = true
}

/********************************************************************************
                           SERVICE PRINCIPAL ROLES
********************************************************************************/
resource "azurerm_role_assignment" "chaos_contributor_sp" {
  principal_id   = azuread_service_principal.cs_sp.id
  role_definition_name = "Chaos Contributor"
  scope = azurerm_resource_group.uks.id
  #scope          = data.azurerm_subscription.primary.id
}

# resource "azurerm_role_assignment" "vm_reader" {
#   principal_id   = azuread_service_principal.example.id
#   role_definition_name = "Reader"
#   scope          = azurerm_windows_virtual_machine.uks-vmsa[0].id  # Replace with your VM's ID
# }

/********************************************************************************
                 ADD AGENT-BASED TARGETS TO CHAOS STUDIO
********************************************************************************/
resource "azurerm_chaos_studio_target" "tgt-uks_vmsa" {
  count               = var.servercounta
  location            = azurerm_resource_group.uks.location
  target_resource_id  = azurerm_windows_virtual_machine.uks-vmsa[count.index].id
  target_type         = "Microsoft-Agent"
}

# resource "azurerm_chaos_studio_target" "tgt-uks_vmsa_1" {
#   location            = azurerm_resource_group.uks.location
#   target_resource_id  = azurerm_windows_virtual_machine.uks-vmsa[1].id
#   target_type         = "Microsoft-Agent"
# }

# resource "azurerm_chaos_studio_target" "tgt-uks_vmsa_2" {
#   location            = azurerm_resource_group.uks.location
#   target_resource_id  = azurerm_windows_virtual_machine.uks-vmsa[2].id
#   target_type         = "Microsoft-Agent"
# }

/********************************************************************************
                 ADD SERVICE-BASED TARGETS TO CHAOS STUDIO
********************************************************************************/
resource "azurerm_chaos_studio_target" "tgt-key_vault_target" {
  location            = azurerm_resource_group.uks.location
  target_resource_id  = azurerm_key_vault.kv1.id
  target_type         = "Microsoft-Service"
}

resource "azurerm_chaos_studio_target" "tgt-app_service_target" {
  location            = azurerm_resource_group.uks.location
  target_resource_id  = azurerm_service_plan.uks-asp.id
  target_type         = "Microsoft-Service"
}

/********************************************************************************
                     ADD CHAOS STUDIO CAPABILITIES
********************************************************************************/

resource "azurerm_chaos_studio_capability" "cap_net_disconnect" {
  count                  = var.servercounta
  capability_type        = "NetworkDisconnect-1.1"
  chaos_studio_target_id = azurerm_chaos_studio_target.tgt-uks_vmsa[count.index].id
}

resource "azurerm_chaos_studio_capability" "cap_cpupressure" {
  count                  = var.servercounta
  capability_type        = "CPUPressure-1.0"
  chaos_studio_target_id = azurerm_chaos_studio_target.tgt-uks_vmsa[count.index].id
}

Debug Output/Panic Output

Error: retrieving list of chaos target types: loading results: Get "": context deadline exceeded

with azurerm_chaos_studio_target.tgt-uks_vmsa[0],
on main.tf line 1453, in resource "azurerm_chaos_studio_target" "tgt-uks_vmsa":
1453: resource "azurerm_chaos_studio_target" "tgt-uks_vmsa" {

retrieving list of chaos target types: loading results: Get "": context deadline exceeded

Error: retrieving list of chaos target types: loading results: Get "": context deadline exceeded

with azurerm_chaos_studio_target.tgt-key_vault_target,
on main.tf line 1475, in resource "azurerm_chaos_studio_target" "tgt-key_vault_target":
1475: resource "azurerm_chaos_studio_target" "tgt-key_vault_target" {

retrieving list of chaos target types: loading results: Get "": context deadline exceeded

Error: retrieving list of chaos target types: loading results: Get "": context deadline exceeded

with azurerm_chaos_studio_target.tgt-app_service_target,
on main.tf line 1481, in resource "azurerm_chaos_studio_target" "tgt-app_service_target":
1481: resource "azurerm_chaos_studio_target" "tgt-app_service_target" {

retrieving list of chaos target types: loading results: Get "": context deadline exceeded

Expected Behaviour

The Chaos Studio target and capability azurerm resources should be created, as the Microsoft.Chaos resource provider is registered in the target subscription.

Actual Behaviour

Terraform apply timeouts after 30 minutes, citing the context deadline has exceeded. This occurs regardless how long you set the deadline for, and the target and capability azurerm resources are not created.

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

neil-yechenwei commented 7 hours ago

Thanks for raising this issue. Seems the List API to retrieve target types would time out. The issue https://github.com/Azure/azure-rest-api-specs/issues/30673 is filed for tracking.