Recently I was playing around with Azure Chaos studio and as a DevOps engineer I wanted to automate the experiment creation through terraform. Although it might seem straightforward it is not and through the process you may find out that some information are needed.
First things first you can go through the documentation and use the azurerm_chaos_studio_experiment terraform resource. This resource needs some properties to be defined as selectors which would be the resources that the experiment will affect.
selectors {
name = "Selector1"
chaos_studio_target_ids = [azurerm_chaos_studio_target.example.id]
}
As shown from the code we will then need a azurerm_chaos_studio_target terraform resource which is identical to the below:
resource "azurerm_chaos_studio_target" "example" {
location = "West Europe"
target_resource_id = data.azurerm_windows_web_app.example.id
target_type = "Microsoft-AppService"
}
The first thing that I. was searching is the target_types. Those can be located in the below page and for my example I wanted to use a WebApp that’s why I selected Microsoft-AppService
https://learn.microsoft.com/en-us/azure/chaos-studio/chaos-studio-fault-providers
Afterwards you will need a capability. The capability block can be located inside the steps of the experiment as shown in the example of terraform docs (link attached to the bottom of the article). The capability has a unique name depending on the action that you need to perform and resource. You can find them in the below link.
https://learn.microsoft.com/en-us/azure/chaos-studio/chaos-studio-fault-library#stop-app-service
resource "azurerm_chaos_studio_capability" "example" {
chaos_studio_target_id = azurerm_chaos_studio_target.example.id
capability_type = "Stop-1.0"
}
In my case I wanted to stop a WebApp so I selected the appropriate. As an example if you need to shutdown a virtual machine you will have to use another capability which is Shutdown-1.0 instead of Stop-1.0.
Bonus:
When running terraform to create your azure chaos resources you may encounter the below error:
retrieving list of chaos target types: loading results: Get "": unsupported protocol scheme ""
For this issue there is an open bug under terraform repository and it is under investigation.
https://github.com/hashicorp/pandora/issues/4535
Links:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/chaos_studio_experiment