diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py index 93c64e46384..27b65d5c62f 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py @@ -84,7 +84,9 @@ options: choices: ['TCP', 'UDP', 'ESP', 'AH', 'SCTP', 'ICMP'] backend_service: description: - - A reference to BackendService resource. + - A reference to a BackendService to receive the matched traffic. + - This is used for internal load balancing. + - "(not used for external load balancing) ." required: false ip_version: description: @@ -105,14 +107,17 @@ options: description: - Name of the resource; provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must - be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? + be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` 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: true network: description: - - A reference to Network resource. + - For internal load balancing, this field identifies the network that the load balanced + IP should belong to for this Forwarding Rule. If this field is not specified, the + default network will be used. + - This field is not used for external load balancing. required: false port_range: description: @@ -138,7 +143,12 @@ options: required: false subnetwork: description: - - A reference to Subnetwork resource. + - A reference to a subnetwork. + - For internal load balancing, this field identifies the subnetwork that the load + balanced IP should belong to for this Forwarding Rule. + - If the network specified is in auto subnet mode, this field is optional. However, + if the network is in custom subnet mode, a subnetwork must be specified. + - This field is not used for external load balancing. required: false target: description: @@ -152,30 +162,26 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a global address gcp_compute_global_address: - name: 'globaladdress-globalforwardingrule' + name: "globaladdress-globalforwardingrule" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: present register: globaladdress - name: create a instance group gcp_compute_instance_group: - name: 'instancegroup-globalforwardingrule' - zone: 'us-central1-a' + name: "instancegroup-globalforwardingrule" + 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-globalforwardingrule' + name: "httphealthcheck-globalforwardingrule" healthy_threshold: 10 port: 8080 timeout_sec: 2 @@ -183,63 +189,53 @@ 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-globalforwardingrule' + name: "backendservice-globalforwardingrule" 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-globalforwardingrule' + name: "urlmap-globalforwardingrule" 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: 'targethttpproxy-globalforwardingrule' + name: "targethttpproxy-globalforwardingrule" url_map: "{{ urlmap }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: present register: httpproxy - name: create a global forwarding rule gcp_compute_global_forwarding_rule: - name: testObject + name: "test_object" ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' + ip_protocol: TCP + port_range: 80-80 target: "{{ httpproxy.selfLink }}" - 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 ''' @@ -290,7 +286,9 @@ RETURN = ''' type: str backend_service: description: - - A reference to BackendService resource. + - A reference to a BackendService to receive the matched traffic. + - This is used for internal load balancing. + - "(not used for external load balancing) ." returned: success type: dict ip_version: @@ -312,7 +310,7 @@ RETURN = ''' description: - Name of the resource; provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must - be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? + be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` 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. @@ -320,7 +318,10 @@ RETURN = ''' type: str network: description: - - A reference to Network resource. + - For internal load balancing, this field identifies the network that the load balanced + IP should belong to for this Forwarding Rule. If this field is not specified, the + default network will be used. + - This field is not used for external load balancing. returned: success type: dict port_range: @@ -349,12 +350,18 @@ RETURN = ''' type: list subnetwork: description: - - A reference to Subnetwork resource. + - A reference to a subnetwork. + - For internal load balancing, this field identifies the subnetwork that the load + balanced IP should belong to for this Forwarding Rule. + - If the network specified is in auto subnet mode, this field is optional. However, + if the network is in custom subnet mode, a subnetwork must be specified. + - This field is not used for external load balancing. returned: success type: dict region: description: - - A reference to Region resource. + - A reference to the region where the regional forwarding rule resides. + - This field is not applicable to global forwarding rules. returned: success type: str target: @@ -400,6 +407,9 @@ def main(): ) ) + if not module.params['scopes']: + module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] + state = module.params['state'] kind = 'compute#forwardingRule' @@ -554,7 +564,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#forwardingRule') diff --git a/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml b/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml index 1fbfe2472ed..aaaf8f35be0 100644 --- a/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml +++ b/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml @@ -15,28 +15,24 @@ # Pre-test setup - name: create a global address gcp_compute_global_address: - name: 'globaladdress-globalforwardingrule' + name: "globaladdress-globalforwardingrule" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: present register: globaladdress - name: create a instance group gcp_compute_instance_group: - name: 'instancegroup-globalforwardingrule' - zone: 'us-central1-a' + name: "instancegroup-globalforwardingrule" + 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-globalforwardingrule' + name: "httphealthcheck-globalforwardingrule" healthy_threshold: 10 port: 8080 timeout_sec: 2 @@ -44,73 +40,61 @@ 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-globalforwardingrule' + name: "backendservice-globalforwardingrule" 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-globalforwardingrule' + name: "urlmap-globalforwardingrule" 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: 'targethttpproxy-globalforwardingrule' + name: "targethttpproxy-globalforwardingrule" url_map: "{{ urlmap }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: present register: httpproxy - name: delete a global forwarding rule gcp_compute_global_forwarding_rule: name: "{{ resource_name }}" ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' + ip_protocol: TCP + port_range: 80-80 target: "{{ httpproxy.selfLink }}" 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 global forwarding rule gcp_compute_global_forwarding_rule: name: "{{ resource_name }}" ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' + ip_protocol: TCP + port_range: 80-80 target: "{{ httpproxy.selfLink }}" 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 @@ -118,19 +102,31 @@ that: - result.changed == true - "result.kind == 'compute#forwardingRule'" -# ---------------------------------------------------------------------------- -- name: create a global forwarding rule that already exists - gcp_compute_global_forwarding_rule: - name: "{{ resource_name }}" - ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' - target: "{{ httpproxy.selfLink }}" +- name: verify that global_forwarding_rule was created + gcp_compute_global_forwarding_rule_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 global forwarding rule that already exists + gcp_compute_global_forwarding_rule: + name: "{{ resource_name }}" + ip_address: "{{ globaladdress.address }}" + ip_protocol: TCP + port_range: 80-80 + target: "{{ httpproxy.selfLink }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" state: present register: result - name: assert changed is false @@ -143,14 +139,12 @@ gcp_compute_global_forwarding_rule: name: "{{ resource_name }}" ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' + ip_protocol: TCP + port_range: 80-80 target: "{{ httpproxy.selfLink }}" 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 @@ -158,19 +152,31 @@ that: - result.changed == true - result.has_key('kind') == False -# ---------------------------------------------------------------------------- -- name: delete a global forwarding rule that does not exist - gcp_compute_global_forwarding_rule: - name: "{{ resource_name }}" - ip_address: "{{ globaladdress.address }}" - ip_protocol: 'TCP' - port_range: '80-80' - target: "{{ httpproxy.selfLink }}" +- name: verify that global_forwarding_rule was deleted + gcp_compute_global_forwarding_rule_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 global forwarding rule that does not exist + gcp_compute_global_forwarding_rule: + name: "{{ resource_name }}" + ip_address: "{{ globaladdress.address }}" + ip_protocol: TCP + port_range: 80-80 + target: "{{ httpproxy.selfLink }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" state: absent register: result - name: assert changed is false @@ -182,44 +188,38 @@ # Post-test teardown - name: delete a target http proxy gcp_compute_target_http_proxy: - name: 'targethttpproxy-globalforwardingrule' + name: "targethttpproxy-globalforwardingrule" url_map: "{{ urlmap }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: absent register: httpproxy - name: delete a url map gcp_compute_url_map: - name: 'urlmap-globalforwardingrule' + name: "urlmap-globalforwardingrule" 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: absent register: urlmap - name: delete a backend service gcp_compute_backend_service: - name: 'backendservice-globalforwardingrule' + name: "backendservice-globalforwardingrule" 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: absent register: backendservice - name: delete a http health check gcp_compute_http_health_check: - name: 'httphealthcheck-globalforwardingrule' + name: "httphealthcheck-globalforwardingrule" healthy_threshold: 10 port: 8080 timeout_sec: 2 @@ -227,28 +227,22 @@ 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-globalforwardingrule' - zone: 'us-central1-a' + name: "instancegroup-globalforwardingrule" + 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 - name: delete a global address gcp_compute_global_address: - name: 'globaladdress-globalforwardingrule' + name: "globaladdress-globalforwardingrule" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" - scopes: - - https://www.googleapis.com/auth/compute state: absent register: globaladdress