Absent
Once you don’t need a resource, you can completely delete it by using the state directive absent , which instructs Idem to remove an existing resource.
Let’s delete an existing Azure Resource Group, in order to do that, we craft the delete_my_resource_group_state.sls: file with the following contents:
<Your Azure Resource Group Name>:
azure.resource_management.resource_groups.absent:
- resource_group_name: <Your Azure Resource Group Name>
- parameters:
location: <Azure Region>
Then State SLS file can be executed with:
idem state <file_path>/delete_my_resource_group_state.sls
In this example:
idem state states/delete_my_resource_group_state.sls
After that you will see Idem removing the resource group to meet our new intentention and state.
--------
ID: moff-idem-01
Function: azure.resource_management.resource_groups.absent
Result: True
Comment: Accepted
Changes: old:
----------
id:
/subscriptions/23a8cee7-a1e4-4bb3-aff9-6898b4ee6fde/resourceGroups/moff-idem-01
name:
moff-idem-01
type:
Microsoft.Resources/resourceGroups
location:
eastus
tags:
----------
createdWith:
idem
properties:
----------
provisioningState:
Succeeded
You can further verify by the idem describe and filter by the resource group name.
idem describe azure.resource_management.resource_groups --filter="[?resource[?resource_group_name=='moff-idem-01']]"
State Absent - Delete: