Bug fixes for gcp_compute_firewall (#42807)

This commit is contained in:
Alex Stephen 2018-08-13 11:55:10 -07:00 committed by Ryan Brown
commit f405857f50
2 changed files with 88 additions and 89 deletions

View file

@ -17,38 +17,34 @@
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: 'tcp'
ports:
- "22"
- ip_protocol: tcp
ports:
- '22'
target_tags:
- test-ssh-server
- staging-ssh-server
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
- test-ssh-clients
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
#----------------------------------------------------------
- name: create a firewall
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: 'tcp'
ports:
- "22"
- ip_protocol: tcp
ports:
- '22'
target_tags:
- test-ssh-server
- staging-ssh-server
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
- test-ssh-clients
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: result
- name: assert changed is true
@ -57,31 +53,35 @@
- result.changed == true
- "result.kind == 'compute#firewall'"
- name: verify that firewall was created
shell: |
gcloud compute firewall-rules describe --project="{{ gcp_project}}" "{{ resource_name }}"
register: results
- name: verify that command succeeded
assert:
that:
- results.rc == 0
# ----------------------------------------------------------------------------
- name: create a firewall that already exists
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: 'tcp'
ports:
- "22"
target_tags:
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
gcp_compute_firewall_facts:
filters:
- name = {{ resource_name }}
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: results
- name: verify that command succeeded
assert:
that:
- results['items'] | length == 1
# ----------------------------------------------------------------------------
- name: create a firewall that already exists
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: tcp
ports:
- '22'
target_tags:
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: result
- name: assert changed is false
@ -94,19 +94,17 @@
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: 'tcp'
ports:
- "22"
- ip_protocol: tcp
ports:
- '22'
target_tags:
- test-ssh-server
- staging-ssh-server
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
- test-ssh-clients
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: result
- name: assert changed is true
@ -115,33 +113,35 @@
- result.changed == true
- result.has_key('kind') == False
- name: verify that firewall was deleted
shell: |
gcloud compute firewall-rules describe --project="{{ gcp_project}}" "{{ resource_name }}"
register: results
failed_when: results.rc == 0
- name: verify that command succeeded
assert:
that:
- results.rc == 1
- "\"'projects/{{ gcp_project }}/global/firewalls/{{ resource_name }}' was not found\" in results.stderr"
# ----------------------------------------------------------------------------
- name: delete a firewall that does not exist
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: 'tcp'
ports:
- "22"
target_tags:
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
gcp_compute_firewall_facts:
filters:
- name = {{ resource_name }}
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: results
- name: verify that command succeeded
assert:
that:
- results['items'] | length == 0
# ----------------------------------------------------------------------------
- name: delete a firewall that does not exist
gcp_compute_firewall:
name: "{{ resource_name }}"
allowed:
- ip_protocol: tcp
ports:
- '22'
target_tags:
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: absent
register: result
- name: assert changed is false