diff --git a/lib/ansible/modules/cloud/google/gcp_compute_network.py b/lib/ansible/modules/cloud/google/gcp_compute_network.py index 7ab0f985d83792..d3a4e1343e2c89 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_network.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_network.py @@ -216,7 +216,7 @@ def main(): ipv4_range=dict(type='str'), name=dict(required=True, type='str'), auto_create_subnetworks=dict(type='bool'), - routing_config=dict(type='list', elements='dict', options=dict( + routing_config=dict(type='dict', options=dict( routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL']) )) ) @@ -275,7 +275,7 @@ def resource_to_request(module): u'IPv4Range': module.params.get('ipv4_range'), u'name': module.params.get('name'), u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'), - u'routingConfig': NetworkRoutingconfigArray(module.params.get('routing_config', []), module).to_request() + u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request() } return_vals = {} for k, v in request.items(): @@ -349,7 +349,7 @@ def response_to_hash(module, response): u'subnetworks': response.get(u'subnetworks'), u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'), u'creationTimestamp': response.get(u'creationTimestamp'), - u'routingConfig': NetworkRoutingconfigArray(response.get(u'routingConfig', []), module).from_response() + u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response() } @@ -388,34 +388,22 @@ def raise_if_errors(response, err_path, module): module.fail_json(msg=errors) -class NetworkRoutingconfigArray(object): +class NetworkRoutingconfig(object): def __init__(self, request, module): self.module = module if request: self.request = request else: - self.request = [] + self.request = {} def to_request(self): - items = [] - for item in self.request: - items.append(self._request_for_item(item)) - return items - - def from_response(self): - items = [] - for item in self.request: - items.append(self._response_from_item(item)) - return items - - def _request_for_item(self, item): return remove_nones_from_dict({ - u'routingMode': item.get('routing_mode') + u'routingMode': self.request.get('routing_mode') }) - def _response_from_item(self, item): + def from_response(self): return remove_nones_from_dict({ - u'routingMode': item.get(u'routingMode') + u'routingMode': self.request.get(u'routingMode') })