Bug fixes for gcp_compute_ssl_certificate (#42821)

pull/44018/merge
Alex Stephen 6 years ago committed by Ryan Brown
parent c38e1e5631
commit fbfea59d7d

@ -76,9 +76,8 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a ssl certificate - name: create a ssl certificate
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: testObject name: "test_object"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -103,11 +102,9 @@ EXAMPLES = '''
AwEHoUQDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ4mzkzTv0dXyB750f AwEHoUQDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ4mzkzTv0dXyB750f
OGN02HtkpBOZzzvUARTR10JQoSe2/5PIwQ== OGN02HtkpBOZzzvUARTR10JQoSe2/5PIwQ==
-----END EC PRIVATE KEY----- -----END EC PRIVATE KEY-----
project: testProject project: "test_project"
auth_kind: service_account auth_kind: "service_account"
service_account_file: /tmp/auth.pem service_account_file: "/tmp/auth.pem"
scopes:
- https://www.googleapis.com/auth/compute
state: present state: present
''' '''
@ -177,6 +174,9 @@ def main():
) )
) )
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state'] state = module.params['state']
kind = 'compute#sslCertificate' kind = 'compute#sslCertificate'
@ -186,10 +186,10 @@ def main():
if fetch: if fetch:
if state == 'present': if state == 'present':
if is_different(module, fetch): if is_different(module, fetch):
fetch = update(module, self_link(module), kind, fetch) fetch = update(module, self_link(module), kind)
changed = True changed = True
else: else:
delete(module, self_link(module), kind, fetch) delete(module, self_link(module), kind)
fetch = {} fetch = {}
changed = True changed = True
else: else:
@ -209,12 +209,12 @@ def create(module, link, kind):
return wait_for_operation(module, auth.post(link, resource_to_request(module))) return wait_for_operation(module, auth.post(link, resource_to_request(module)))
def update(module, link, kind, fetch): def update(module, link, kind):
auth = GcpSession(module, 'compute') auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.put(link, resource_to_request(module))) return wait_for_operation(module, auth.put(link, resource_to_request(module)))
def delete(module, link, kind, fetch): def delete(module, link, kind):
auth = GcpSession(module, 'compute') auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.delete(link)) return wait_for_operation(module, auth.delete(link))
@ -314,7 +314,7 @@ def async_op_url(module, extra_data=None):
def wait_for_operation(module, response): def wait_for_operation(module, response):
op_result = return_if_object(module, response, 'compute#operation') op_result = return_if_object(module, response, 'compute#operation')
if op_result is None: if op_result is None:
return None return {}
status = navigate_hash(op_result, ['status']) status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module) wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#sslCertificate') return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#sslCertificate')

@ -16,8 +16,7 @@
- name: delete a ssl certificate - name: delete a ssl certificate
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: "{{ resource_name }}" name: "{{ resource_name }}"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -45,15 +44,12 @@
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 ssl certificate - name: create a ssl certificate
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: "{{ resource_name }}" name: "{{ resource_name }}"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -81,8 +77,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
@ -91,19 +85,24 @@
- result.changed == true - result.changed == true
- "result.kind == 'compute#sslCertificate'" - "result.kind == 'compute#sslCertificate'"
- name: verify that ssl_certificate was created - name: verify that ssl_certificate was created
shell: | gcp_compute_ssl_certificate_facts:
gcloud compute ssl-certificates 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 ssl certificate that already exists - name: create a ssl certificate that already exists
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: "{{ resource_name }}" name: "{{ resource_name }}"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -131,8 +130,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
@ -144,8 +141,7 @@
- name: delete a ssl certificate - name: delete a ssl certificate
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: "{{ resource_name }}" name: "{{ resource_name }}"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -173,8 +169,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
@ -183,21 +177,24 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that ssl_certificate was deleted - name: verify that ssl_certificate was deleted
shell: | gcp_compute_ssl_certificate_facts:
gcloud compute ssl-certificates 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/sslCertificates/{{ resource_name }}' was not found\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a ssl certificate that does not exist - name: delete a ssl certificate that does not exist
gcp_compute_ssl_certificate: gcp_compute_ssl_certificate:
name: "{{ resource_name }}" name: "{{ resource_name }}"
description: | description: A certificate for testing. Do not use this certificate in production
"A certificate for testing. Do not use this certificate in production"
certificate: | certificate: |
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
@ -225,8 +222,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

Loading…
Cancel
Save