Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Rely on resource group removal when performing destroy (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohit Kumar Sharma <mohit@flux7.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people authored Oct 29, 2020
1 parent b84a521 commit 18acf4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
location: "{{ lookup('env', 'AZURE_REGION') or 'westus' }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,12 @@
virtual_network_name: molecule_vnet
subnet_name: molecule_subnet
tasks:
- name: Destroy molecule instance(s)
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ item.name }}"
state: absent
remove_on_absent:
- all_autocreated
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0

- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: azure_jobs
until: azure_jobs.finished
retries: 300
with_items: "{{ server.results }}"
# avoid failure when resource_group is already missing, as we remove it later anyway
failed_when: false

- name: Destroy subnet
azure_rm_subnet:
resource_group: "{{ resource_group_name }}"
name: "{{ subnet_name }}"
virtual_network_name: "{{ virtual_network_name }}"
state: absent
# avoid failure when resource_group is already missing, as we remove it later anyway
failed_when: false

- name: Destroy virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_network_name }}"
state: absent
# avoid failure when resource_group is already missing, as we remove it later anyway
failed_when: false

- name: Destroy resource group
- name: Destroy resource group and all associated resources
azure_rm_resourcegroup:
name: "{{ resource_group_name }}"
state: absent
force_delete_nonempty: true
register: rg

# Mandatory configuration for Molecule to function.

Expand All @@ -65,5 +27,5 @@
copy:
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
when: rg.changed | bool
{%- endraw %}

0 comments on commit 18acf4d

Please sign in to comment.