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

Commit 18acf4d

Browse files
mkshaMohit Kumar Sharmassbarnea
authored
Rely on resource group removal when performing destroy (#23)
Co-authored-by: Mohit Kumar Sharma <mohit@flux7.com> Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
1 parent b84a521 commit 18acf4d

File tree

2 files changed

+4
-41
lines changed
  • molecule_azure/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}

2 files changed

+4
-41
lines changed

molecule_azure/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/create.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
hosts: localhost
55
connection: local
66
gather_facts: false
7+
no_log: "{{ molecule_no_log }}"
78
vars:
89
resource_group_name: molecule
910
location: "{{ lookup('env', 'AZURE_REGION') or 'westus' }}"

molecule_azure/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/destroy.yml

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,12 @@
1010
virtual_network_name: molecule_vnet
1111
subnet_name: molecule_subnet
1212
tasks:
13-
- name: Destroy molecule instance(s)
14-
azure_rm_virtualmachine:
15-
resource_group: "{{ resource_group_name }}"
16-
name: "{{ item.name }}"
17-
state: absent
18-
remove_on_absent:
19-
- all_autocreated
20-
register: server
21-
with_items: "{{ molecule_yml.platforms }}"
22-
async: 7200
23-
poll: 0
24-
25-
- name: Wait for instance(s) deletion to complete
26-
async_status:
27-
jid: "{{ item.ansible_job_id }}"
28-
register: azure_jobs
29-
until: azure_jobs.finished
30-
retries: 300
31-
with_items: "{{ server.results }}"
32-
# avoid failure when resource_group is already missing, as we remove it later anyway
33-
failed_when: false
34-
35-
- name: Destroy subnet
36-
azure_rm_subnet:
37-
resource_group: "{{ resource_group_name }}"
38-
name: "{{ subnet_name }}"
39-
virtual_network_name: "{{ virtual_network_name }}"
40-
state: absent
41-
# avoid failure when resource_group is already missing, as we remove it later anyway
42-
failed_when: false
43-
44-
- name: Destroy virtual network
45-
azure_rm_virtualnetwork:
46-
resource_group: "{{ resource_group_name }}"
47-
name: "{{ virtual_network_name }}"
48-
state: absent
49-
# avoid failure when resource_group is already missing, as we remove it later anyway
50-
failed_when: false
51-
52-
- name: Destroy resource group
13+
- name: Destroy resource group and all associated resources
5314
azure_rm_resourcegroup:
5415
name: "{{ resource_group_name }}"
5516
state: absent
5617
force_delete_nonempty: true
18+
register: rg
5719

5820
# Mandatory configuration for Molecule to function.
5921

@@ -65,5 +27,5 @@
6527
copy:
6628
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
6729
dest: "{{ molecule_instance_config }}"
68-
when: server.changed | bool
30+
when: rg.changed | bool
6931
{%- endraw %}

0 commit comments

Comments
 (0)