Bug fixes for gcp_compute_target_tcp_proxy (#42827)
This commit is contained in:
parent
97006cded2
commit
984cc10465
2 changed files with 80 additions and 76 deletions
|
@ -59,7 +59,7 @@ options:
|
||||||
which means the first character must be a lowercase letter, and all following characters
|
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
|
must be a dash, lowercase letter, or digit, except the last character, which cannot
|
||||||
be a dash.
|
be a dash.
|
||||||
required: false
|
required: true
|
||||||
proxy_header:
|
proxy_header:
|
||||||
description:
|
description:
|
||||||
- Specifies the type of proxy header to append before sending data to the backend,
|
- Specifies the type of proxy header to append before sending data to the backend,
|
||||||
|
@ -68,27 +68,28 @@ options:
|
||||||
choices: ['NONE', 'PROXY_V1']
|
choices: ['NONE', 'PROXY_V1']
|
||||||
service:
|
service:
|
||||||
description:
|
description:
|
||||||
- A reference to BackendService resource.
|
- A reference to the BackendService resource.
|
||||||
required: false
|
required: true
|
||||||
extends_documentation_fragment: gcp
|
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 = '''
|
EXAMPLES = '''
|
||||||
- name: create a instance group
|
- name: create a instance group
|
||||||
gcp_compute_instance_group:
|
gcp_compute_instance_group:
|
||||||
name: 'instancegroup-targettcpproxy'
|
name: "instancegroup-targettcpproxy"
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
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: instancegroup
|
register: instancegroup
|
||||||
|
|
||||||
- name: create a health check
|
- name: create a health check
|
||||||
gcp_compute_health_check:
|
gcp_compute_health_check:
|
||||||
name: 'healthcheck-targettcpproxy'
|
name: "healthcheck-targettcpproxy"
|
||||||
type: TCP
|
type: TCP
|
||||||
tcp_health_check:
|
tcp_health_check:
|
||||||
port_name: service-health
|
port_name: service-health
|
||||||
|
@ -100,37 +101,31 @@ EXAMPLES = '''
|
||||||
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: healthcheck
|
register: healthcheck
|
||||||
|
|
||||||
- name: create a backend service
|
- name: create a backend service
|
||||||
gcp_compute_backend_service:
|
gcp_compute_backend_service:
|
||||||
name: 'backendservice-targettcpproxy'
|
name: "backendservice-targettcpproxy"
|
||||||
backends:
|
backends:
|
||||||
- group: "{{ instancegroup }}"
|
- group: "{{ instancegroup }}"
|
||||||
health_checks:
|
health_checks:
|
||||||
- "{{ healthcheck.selfLink }}"
|
- "{{ healthcheck.selfLink }}"
|
||||||
protocol: 'TCP'
|
protocol: TCP
|
||||||
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: backendservice
|
register: backendservice
|
||||||
|
|
||||||
- name: create a target tcp proxy
|
- name: create a target tcp proxy
|
||||||
gcp_compute_target_tcp_proxy:
|
gcp_compute_target_tcp_proxy:
|
||||||
name: testObject
|
name: "test_object"
|
||||||
proxy_header: 'PROXY_V1'
|
proxy_header: PROXY_V1
|
||||||
service: "{{ backendservice }}"
|
service: "{{ backendservice }}"
|
||||||
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
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -168,7 +163,7 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
service:
|
service:
|
||||||
description:
|
description:
|
||||||
- A reference to BackendService resource.
|
- A reference to the BackendService resource.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
@ -193,12 +188,15 @@ def main():
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
description=dict(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']),
|
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']
|
state = module.params['state']
|
||||||
kind = 'compute#targetTcpProxy'
|
kind = 'compute#targetTcpProxy'
|
||||||
|
|
||||||
|
@ -316,9 +314,9 @@ def is_different(module, response):
|
||||||
def response_to_hash(module, response):
|
def response_to_hash(module, response):
|
||||||
return {
|
return {
|
||||||
u'creationTimestamp': response.get(u'creationTimestamp'),
|
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'id': response.get(u'id'),
|
||||||
u'name': response.get(u'name'),
|
u'name': module.params.get('name'),
|
||||||
u'proxyHeader': response.get(u'proxyHeader'),
|
u'proxyHeader': response.get(u'proxyHeader'),
|
||||||
u'service': response.get(u'service')
|
u'service': response.get(u'service')
|
||||||
}
|
}
|
||||||
|
@ -336,7 +334,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#targetTcpProxy')
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetTcpProxy')
|
||||||
|
|
|
@ -15,18 +15,16 @@
|
||||||
# Pre-test setup
|
# Pre-test setup
|
||||||
- name: create a instance group
|
- name: create a instance group
|
||||||
gcp_compute_instance_group:
|
gcp_compute_instance_group:
|
||||||
name: 'instancegroup-targettcpproxy'
|
name: "instancegroup-targettcpproxy"
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
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: instancegroup
|
register: instancegroup
|
||||||
- name: create a health check
|
- name: create a health check
|
||||||
gcp_compute_health_check:
|
gcp_compute_health_check:
|
||||||
name: 'healthcheck-targettcpproxy'
|
name: "healthcheck-targettcpproxy"
|
||||||
type: TCP
|
type: TCP
|
||||||
tcp_health_check:
|
tcp_health_check:
|
||||||
port_name: service-health
|
port_name: service-health
|
||||||
|
@ -38,47 +36,39 @@
|
||||||
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: healthcheck
|
register: healthcheck
|
||||||
- name: create a backend service
|
- name: create a backend service
|
||||||
gcp_compute_backend_service:
|
gcp_compute_backend_service:
|
||||||
name: 'backendservice-targettcpproxy'
|
name: "backendservice-targettcpproxy"
|
||||||
backends:
|
backends:
|
||||||
- group: "{{ instancegroup }}"
|
- group: "{{ instancegroup }}"
|
||||||
health_checks:
|
health_checks:
|
||||||
- "{{ healthcheck.selfLink }}"
|
- "{{ healthcheck.selfLink }}"
|
||||||
protocol: 'TCP'
|
protocol: TCP
|
||||||
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: backendservice
|
register: backendservice
|
||||||
- name: delete a target tcp proxy
|
- name: delete a target tcp proxy
|
||||||
gcp_compute_target_tcp_proxy:
|
gcp_compute_target_tcp_proxy:
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
proxy_header: 'PROXY_V1'
|
proxy_header: PROXY_V1
|
||||||
service: "{{ backendservice }}"
|
service: "{{ backendservice }}"
|
||||||
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 target tcp proxy
|
- name: create a target tcp proxy
|
||||||
gcp_compute_target_tcp_proxy:
|
gcp_compute_target_tcp_proxy:
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
proxy_header: 'PROXY_V1'
|
proxy_header: PROXY_V1
|
||||||
service: "{{ backendservice }}"
|
service: "{{ backendservice }}"
|
||||||
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
|
||||||
|
@ -86,17 +76,29 @@
|
||||||
that:
|
that:
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- "result.kind == 'compute#targetTcpProxy'"
|
- "result.kind == 'compute#targetTcpProxy'"
|
||||||
# ----------------------------------------------------------------------------
|
- name: verify that target_tcp_proxy was created
|
||||||
- name: create a target tcp proxy that already exists
|
gcp_compute_target_tcp_proxy_facts:
|
||||||
gcp_compute_target_tcp_proxy:
|
filters:
|
||||||
name: "{{ resource_name }}"
|
- name = {{ resource_name }}
|
||||||
proxy_header: 'PROXY_V1'
|
|
||||||
service: "{{ backendservice }}"
|
|
||||||
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:
|
scopes:
|
||||||
- https://www.googleapis.com/auth/compute
|
- 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
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -108,13 +110,11 @@
|
||||||
- name: delete a target tcp proxy
|
- name: delete a target tcp proxy
|
||||||
gcp_compute_target_tcp_proxy:
|
gcp_compute_target_tcp_proxy:
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
proxy_header: 'PROXY_V1'
|
proxy_header: PROXY_V1
|
||||||
service: "{{ backendservice }}"
|
service: "{{ backendservice }}"
|
||||||
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
|
||||||
|
@ -122,17 +122,29 @@
|
||||||
that:
|
that:
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- result.has_key('kind') == False
|
- result.has_key('kind') == False
|
||||||
# ----------------------------------------------------------------------------
|
- name: verify that target_tcp_proxy was deleted
|
||||||
- name: delete a target tcp proxy that does not exist
|
gcp_compute_target_tcp_proxy_facts:
|
||||||
gcp_compute_target_tcp_proxy:
|
filters:
|
||||||
name: "{{ resource_name }}"
|
- name = {{ resource_name }}
|
||||||
proxy_header: 'PROXY_V1'
|
|
||||||
service: "{{ backendservice }}"
|
|
||||||
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:
|
scopes:
|
||||||
- https://www.googleapis.com/auth/compute
|
- 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
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -144,22 +156,20 @@
|
||||||
# Post-test teardown
|
# Post-test teardown
|
||||||
- name: delete a backend service
|
- name: delete a backend service
|
||||||
gcp_compute_backend_service:
|
gcp_compute_backend_service:
|
||||||
name: 'backendservice-targettcpproxy'
|
name: "backendservice-targettcpproxy"
|
||||||
backends:
|
backends:
|
||||||
- group: "{{ instancegroup }}"
|
- group: "{{ instancegroup }}"
|
||||||
health_checks:
|
health_checks:
|
||||||
- "{{ healthcheck.selfLink }}"
|
- "{{ healthcheck.selfLink }}"
|
||||||
protocol: 'TCP'
|
protocol: TCP
|
||||||
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: backendservice
|
register: backendservice
|
||||||
- name: delete a health check
|
- name: delete a health check
|
||||||
gcp_compute_health_check:
|
gcp_compute_health_check:
|
||||||
name: 'healthcheck-targettcpproxy'
|
name: "healthcheck-targettcpproxy"
|
||||||
type: TCP
|
type: TCP
|
||||||
tcp_health_check:
|
tcp_health_check:
|
||||||
port_name: service-health
|
port_name: service-health
|
||||||
|
@ -171,18 +181,14 @@
|
||||||
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: healthcheck
|
register: healthcheck
|
||||||
- name: delete a instance group
|
- name: delete a instance group
|
||||||
gcp_compute_instance_group:
|
gcp_compute_instance_group:
|
||||||
name: 'instancegroup-targettcpproxy'
|
name: "instancegroup-targettcpproxy"
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
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: instancegroup
|
register: instancegroup
|
||||||
|
|
Loading…
Reference in a new issue