---
|
- environment:
|
AZURE_CLIENT_ID: "{{azure_service_principal}}"
|
AZURE_TENANT: "{{azure_tenant}}"
|
AZURE_SECRET: "{{azure_password}}"
|
AZURE_SUBSCRIPTION_ID: "{{azure_subscription_id}}"
|
# AZURE_CONFIG_DIR: create a specific config dir for this stack to allow concurrent access for 'az' command
|
AZURE_CONFIG_DIR: "/tmp/.azure-{{project_tag}}"
|
block:
|
- name: Delete delegation for NS to the main DNSZone
|
when: az_dnszone_resource_group != 'none'
|
azure_rm_dnsrecordset:
|
resource_group: "{{az_dnszone_resource_group|default('dns')}}"
|
relative_name: "{{guid}}"
|
zone_name: "{{HostedZoneId}}"
|
record_type: NS
|
state: absent
|
|
- name: Destroy method resourceGroup (standalone ResourceGroup)
|
when: az_destroy_method|default('resource_group') == 'resource_group'
|
block:
|
- name: Delete the resource group
|
azure_rm_resourcegroup:
|
name: "{{az_resource_group}}"
|
state: absent
|
force: true
|
tags:
|
- destroying
|
- destroy_cloud_deployment
|
- destroy_azure_deployment
|
register: azure_result
|
until: azure_result is succeeded
|
retries: 6
|
delay: 10
|
ignore_errors: yes
|
when:
|
- cloud_provider == 'azure'
|
|
- name: report azure error
|
fail:
|
msg: "FAIL {{ az_resource_group }} Azure delete group"
|
when:
|
- azure_result is failed
|
- cloud_provider == 'azure'
|
tags:
|
- destroying
|
- destroy_cloud_deployment
|
- destroy_azure_deployment
|
|
- name: Method destroy deployment (shared ResourceGroup)
|
when: az_destroy_method|default('resource_group') == 'deployment'
|
block:
|
- set_fact:
|
t_dest: "{{output_dir}}/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template"
|
|
- name: Get all resources from the deployment
|
command: az group deployment show --name {{env_type}}.{{guid}} --resource-group {{az_resource_group}}
|
changed_when: false
|
register: az_dep
|
until: az_dep is succeeded
|
retries: 5
|
|
- debug:
|
var: az_dep
|
verbosity: 2
|
|
- name: Get all resources from tag
|
command: az resource list --tag 'Project={{project_tag}}'
|
register: az_tag
|
retries: 5
|
until: az_tag is succeeded
|
changed_when: false
|
|
- name: delete all resources
|
vars:
|
ids_tags: "{{ az_tag.stdout|from_json|json_query('[*].id')}}"
|
ids_deployment: "{{ az_dep.stdout|from_json|json_query('properties.additionalProperties.outputResources[*].id')}}"
|
ids: "{{ids_deployment|union(ids_tags)}}"
|
command: "az resource delete --ids {{ids|join(' ')}} --resource-group {{az_resource_group}}"
|
register: az_delete
|
until: az_delete is succeeded
|
retries: 5
|
when: ids|length > 0
|