Bug fixes for gcp_compute_target_http_proxy (#42823)

This commit is contained in:
Alex Stephen 2018-08-14 06:53:29 -07:00
parent 8dc9526c16
commit a173d75cea
2 changed files with 56 additions and 76 deletions

View file

@ -62,27 +62,28 @@ options:
required: true
url_map:
description:
- A reference to UrlMap resource.
- A reference to the UrlMap resource that defines the mapping from URL to the BackendService.
required: true
extends_documentation_fragment: gcp
notes:
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/targetHttpProxies)"
- "Official Documentation: U(https://cloud.google.com/compute/docs/load-balancing/http/target-proxies)"
'''
EXAMPLES = '''
- name: create a instance group
gcp_compute_instance_group:
name: 'instancegroup-targethttpproxy'
zone: 'us-central1-a'
name: "instancegroup-targethttpproxy"
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 http health check
gcp_compute_http_health_check:
name: 'httphealthcheck-targethttpproxy'
name: "httphealthcheck-targethttpproxy"
healthy_threshold: 10
port: 8080
timeout_sec: 2
@ -90,48 +91,40 @@ 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-targethttpproxy'
name: "backendservice-targethttpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
- "{{ healthcheck.selfLink }}"
enable_cdn: true
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 url map
gcp_compute_url_map:
name: 'urlmap-targethttpproxy'
name: "urlmap-targethttpproxy"
default_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: urlmap
- name: create a target http proxy
gcp_compute_target_http_proxy:
name: testObject
name: "test_object"
url_map: "{{ urlmap }}"
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
'''
@ -163,7 +156,7 @@ RETURN = '''
type: str
url_map:
description:
- A reference to UrlMap resource.
- A reference to the UrlMap resource that defines the mapping from URL to the BackendService.
returned: success
type: dict
'''
@ -193,6 +186,9 @@ def main():
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state']
kind = 'compute#targetHttpProxy'
@ -202,10 +198,10 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind, fetch)
fetch = update(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind, fetch)
delete(module, self_link(module), kind)
fetch = {}
changed = True
else:
@ -225,12 +221,12 @@ def create(module, link, kind):
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')
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')
return wait_for_operation(module, auth.delete(link))
@ -328,7 +324,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#targetHttpProxy')