|
|
@ -17,9 +17,9 @@
|
|
|
|
gcp_compute_firewall:
|
|
|
|
gcp_compute_firewall:
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
allowed:
|
|
|
|
allowed:
|
|
|
|
- ip_protocol: 'tcp'
|
|
|
|
- ip_protocol: tcp
|
|
|
|
ports:
|
|
|
|
ports:
|
|
|
|
- "22"
|
|
|
|
- '22'
|
|
|
|
target_tags:
|
|
|
|
target_tags:
|
|
|
|
- test-ssh-server
|
|
|
|
- test-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
@ -28,17 +28,15 @@
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
scopes:
|
|
|
|
|
|
|
|
- https://www.googleapis.com/auth/compute
|
|
|
|
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
|
#----------------------------------------------------------
|
|
|
|
#----------------------------------------------------------
|
|
|
|
- name: create a firewall
|
|
|
|
- name: create a firewall
|
|
|
|
gcp_compute_firewall:
|
|
|
|
gcp_compute_firewall:
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
allowed:
|
|
|
|
allowed:
|
|
|
|
- ip_protocol: 'tcp'
|
|
|
|
- ip_protocol: tcp
|
|
|
|
ports:
|
|
|
|
ports:
|
|
|
|
- "22"
|
|
|
|
- '22'
|
|
|
|
target_tags:
|
|
|
|
target_tags:
|
|
|
|
- test-ssh-server
|
|
|
|
- test-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
@ -47,8 +45,6 @@
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
scopes:
|
|
|
|
|
|
|
|
- https://www.googleapis.com/auth/compute
|
|
|
|
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
register: result
|
|
|
|
- name: assert changed is true
|
|
|
|
- name: assert changed is true
|
|
|
@ -57,21 +53,27 @@
|
|
|
|
- result.changed == true
|
|
|
|
- result.changed == true
|
|
|
|
- "result.kind == 'compute#firewall'"
|
|
|
|
- "result.kind == 'compute#firewall'"
|
|
|
|
- name: verify that firewall was created
|
|
|
|
- name: verify that firewall was created
|
|
|
|
shell: |
|
|
|
|
gcp_compute_firewall_facts:
|
|
|
|
gcloud compute firewall-rules describe --project="{{ gcp_project}}" "{{ resource_name }}"
|
|
|
|
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
|
|
|
|
register: results
|
|
|
|
- name: verify that command succeeded
|
|
|
|
- name: verify that command succeeded
|
|
|
|
assert:
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
that:
|
|
|
|
- results.rc == 0
|
|
|
|
- results['items'] | length == 1
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
- name: create a firewall that already exists
|
|
|
|
- name: create a firewall that already exists
|
|
|
|
gcp_compute_firewall:
|
|
|
|
gcp_compute_firewall:
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
allowed:
|
|
|
|
allowed:
|
|
|
|
- ip_protocol: 'tcp'
|
|
|
|
- ip_protocol: tcp
|
|
|
|
ports:
|
|
|
|
ports:
|
|
|
|
- "22"
|
|
|
|
- '22'
|
|
|
|
target_tags:
|
|
|
|
target_tags:
|
|
|
|
- test-ssh-server
|
|
|
|
- test-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
@ -80,8 +82,6 @@
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
scopes:
|
|
|
|
|
|
|
|
- https://www.googleapis.com/auth/compute
|
|
|
|
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
register: result
|
|
|
|
- name: assert changed is false
|
|
|
|
- name: assert changed is false
|
|
|
@ -94,9 +94,9 @@
|
|
|
|
gcp_compute_firewall:
|
|
|
|
gcp_compute_firewall:
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
allowed:
|
|
|
|
allowed:
|
|
|
|
- ip_protocol: 'tcp'
|
|
|
|
- ip_protocol: tcp
|
|
|
|
ports:
|
|
|
|
ports:
|
|
|
|
- "22"
|
|
|
|
- '22'
|
|
|
|
target_tags:
|
|
|
|
target_tags:
|
|
|
|
- test-ssh-server
|
|
|
|
- test-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
@ -105,8 +105,6 @@
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
scopes:
|
|
|
|
|
|
|
|
- https://www.googleapis.com/auth/compute
|
|
|
|
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
register: result
|
|
|
|
- name: assert changed is true
|
|
|
|
- name: assert changed is true
|
|
|
@ -115,23 +113,27 @@
|
|
|
|
- result.changed == true
|
|
|
|
- result.changed == true
|
|
|
|
- result.has_key('kind') == False
|
|
|
|
- result.has_key('kind') == False
|
|
|
|
- name: verify that firewall was deleted
|
|
|
|
- name: verify that firewall was deleted
|
|
|
|
shell: |
|
|
|
|
gcp_compute_firewall_facts:
|
|
|
|
gcloud compute firewall-rules describe --project="{{ gcp_project}}" "{{ resource_name }}"
|
|
|
|
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
|
|
|
|
register: results
|
|
|
|
failed_when: results.rc == 0
|
|
|
|
|
|
|
|
- name: verify that command succeeded
|
|
|
|
- name: verify that command succeeded
|
|
|
|
assert:
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
that:
|
|
|
|
- results.rc == 1
|
|
|
|
- results['items'] | length == 0
|
|
|
|
- "\"'projects/{{ gcp_project }}/global/firewalls/{{ resource_name }}' was not found\" in results.stderr"
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
- name: delete a firewall that does not exist
|
|
|
|
- name: delete a firewall that does not exist
|
|
|
|
gcp_compute_firewall:
|
|
|
|
gcp_compute_firewall:
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
name: "{{ resource_name }}"
|
|
|
|
allowed:
|
|
|
|
allowed:
|
|
|
|
- ip_protocol: 'tcp'
|
|
|
|
- ip_protocol: tcp
|
|
|
|
ports:
|
|
|
|
ports:
|
|
|
|
- "22"
|
|
|
|
- '22'
|
|
|
|
target_tags:
|
|
|
|
target_tags:
|
|
|
|
- test-ssh-server
|
|
|
|
- test-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
|
- staging-ssh-server
|
|
|
@ -140,8 +142,6 @@
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
project: "{{ gcp_project }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
service_account_file: "{{ gcp_cred_file }}"
|
|
|
|
scopes:
|
|
|
|
|
|
|
|
- https://www.googleapis.com/auth/compute
|
|
|
|
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
register: result
|
|
|
|
- name: assert changed is false
|
|
|
|
- name: assert changed is false
|
|
|
|