1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Bug fixes for gcp_compute_target_tcp_proxy (#42827)

This commit is contained in:
Alex Stephen 2018-08-14 06:53:46 -07:00 committed by Ryan Brown
parent 97006cded2
commit 984cc10465
2 changed files with 80 additions and 76 deletions

View file

@ -59,7 +59,7 @@ options:
which means the first character must be a lowercase letter, and all following characters
must be a dash, lowercase letter, or digit, except the last character, which cannot
be a dash.
required: false
required: true
proxy_header:
description:
- Specifies the type of proxy header to append before sending data to the backend,
@ -68,27 +68,28 @@ options:
choices: ['NONE', 'PROXY_V1']
service:
description:
- A reference to BackendService resource.
required: false
- A reference to the BackendService resource.
required: true
extends_documentation_fragment: gcp
notes:
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/targetTcpProxies)"
- "Setting Up TCP proxy for Google Cloud Load Balancing: U(https://cloud.google.com/compute/docs/load-balancing/tcp-ssl/tcp-proxy)"
'''
EXAMPLES = '''
- name: create a instance group
gcp_compute_instance_group:
name: 'instancegroup-targettcpproxy'
zone: 'us-central1-a'
name: "instancegroup-targettcpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: instancegroup
- name: create a health check
gcp_compute_health_check:
name: 'healthcheck-targettcpproxy'
name: "healthcheck-targettcpproxy"
type: TCP
tcp_health_check:
port_name: service-health
@ -100,37 +101,31 @@ EXAMPLES = '''
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: healthcheck
- name: create a backend service
gcp_compute_backend_service:
name: 'backendservice-targettcpproxy'
name: "backendservice-targettcpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
protocol: 'TCP'
- "{{ healthcheck.selfLink }}"
protocol: TCP
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: backendservice
- name: create a target tcp proxy
gcp_compute_target_tcp_proxy:
name: testObject
proxy_header: 'PROXY_V1'
name: "test_object"
proxy_header: PROXY_V1
service: "{{ backendservice }}"
project: testProject
auth_kind: service_account
service_account_file: /tmp/auth.pem
scopes:
- https://www.googleapis.com/auth/compute
project: "test_project"
auth_kind: "service_account"
service_account_file: "/tmp/auth.pem"
state: present
'''
@ -168,7 +163,7 @@ RETURN = '''
type: str
service:
description:
- A reference to BackendService resource.
- A reference to the BackendService resource.
returned: success
type: dict
'''
@ -193,12 +188,15 @@ def main():
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
description=dict(type='str'),
name=dict(type='str'),
name=dict(required=True, type='str'),
proxy_header=dict(type='str', choices=['NONE', 'PROXY_V1']),
service=dict(type='dict')
service=dict(required=True, type='dict')
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state']
kind = 'compute#targetTcpProxy'
@ -316,9 +314,9 @@ def is_different(module, response):
def response_to_hash(module, response):
return {
u'creationTimestamp': response.get(u'creationTimestamp'),
u'description': response.get(u'description'),
u'description': module.params.get('description'),
u'id': response.get(u'id'),
u'name': response.get(u'name'),
u'name': module.params.get('name'),
u'proxyHeader': response.get(u'proxyHeader'),
u'service': response.get(u'service')
}
@ -336,7 +334,7 @@ def async_op_url(module, extra_data=None):
def wait_for_operation(module, response):
op_result = return_if_object(module, response, 'compute#operation')
if op_result is None:
return None
return {}
status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetTcpProxy')

View file

@ -15,18 +15,16 @@
# Pre-test setup
- name: create a instance group
gcp_compute_instance_group:
name: 'instancegroup-targettcpproxy'
zone: 'us-central1-a'
name: "instancegroup-targettcpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: instancegroup
- name: create a health check
gcp_compute_health_check:
name: 'healthcheck-targettcpproxy'
name: "healthcheck-targettcpproxy"
type: TCP
tcp_health_check:
port_name: service-health
@ -38,47 +36,39 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: healthcheck
- name: create a backend service
gcp_compute_backend_service:
name: 'backendservice-targettcpproxy'
name: "backendservice-targettcpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
protocol: 'TCP'
- "{{ healthcheck.selfLink }}"
protocol: TCP
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: backendservice
- name: delete a target tcp proxy
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: 'PROXY_V1'
proxy_header: PROXY_V1
service: "{{ backendservice }}"
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 target tcp proxy
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: 'PROXY_V1'
proxy_header: PROXY_V1
service: "{{ backendservice }}"
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
@ -86,17 +76,29 @@
that:
- result.changed == true
- "result.kind == 'compute#targetTcpProxy'"
# ----------------------------------------------------------------------------
- name: create a target tcp proxy that already exists
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: 'PROXY_V1'
service: "{{ backendservice }}"
- name: verify that target_tcp_proxy was created
gcp_compute_target_tcp_proxy_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 target tcp proxy that already exists
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: PROXY_V1
service: "{{ backendservice }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: result
- name: assert changed is false
@ -108,13 +110,11 @@
- name: delete a target tcp proxy
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: 'PROXY_V1'
proxy_header: PROXY_V1
service: "{{ backendservice }}"
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
@ -122,17 +122,29 @@
that:
- result.changed == true
- result.has_key('kind') == False
# ----------------------------------------------------------------------------
- name: delete a target tcp proxy that does not exist
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: 'PROXY_V1'
service: "{{ backendservice }}"
- name: verify that target_tcp_proxy was deleted
gcp_compute_target_tcp_proxy_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 target tcp proxy that does not exist
gcp_compute_target_tcp_proxy:
name: "{{ resource_name }}"
proxy_header: PROXY_V1
service: "{{ backendservice }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: absent
register: result
- name: assert changed is false
@ -144,22 +156,20 @@
# Post-test teardown
- name: delete a backend service
gcp_compute_backend_service:
name: 'backendservice-targettcpproxy'
name: "backendservice-targettcpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
protocol: 'TCP'
- "{{ healthcheck.selfLink }}"
protocol: TCP
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: backendservice
- name: delete a health check
gcp_compute_health_check:
name: 'healthcheck-targettcpproxy'
name: "healthcheck-targettcpproxy"
type: TCP
tcp_health_check:
port_name: service-health
@ -171,18 +181,14 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: healthcheck
- name: delete a instance group
gcp_compute_instance_group:
name: 'instancegroup-targettcpproxy'
zone: 'us-central1-a'
name: "instancegroup-targettcpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: instancegroup