Support compute reservation resize (#3308) (#181)

* support compute reservations resize

* remove if custom encoder

* review comments

Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
The Magician 2020-03-27 14:55:40 -07:00 committed by GitHub
parent 947007da82
commit 872d3daf12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -410,7 +410,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module))
update(module, self_link(module), fetch)
fetch = fetch_resource(module, self_link(module))
changed = True
else:
@ -434,9 +434,22 @@ def create(module, link):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
def update(module, link):
delete(module, self_link(module))
create(module, collection(module))
def update(module, link, fetch):
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module))
def update_fields(module, request, response):
if response.get('specificReservation') != request.get('specificReservation'):
specific_reservation_update(module, request, response)
def specific_reservation_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/zones/{zone}/reservations/{name}/resize"]).format(**module.params),
{u'specificReservation': ReservationSpecificreservation(module.params.get('specific_reservation', {}), module).to_request()},
)
def delete(module, link):
@ -582,7 +595,7 @@ class ReservationSpecificreservation(object):
return remove_nones_from_dict(
{
u'count': self.request.get(u'count'),
u'instanceProperties': ReservationInstanceproperties(self.request.get(u'instanceProperties', {}), self.module).from_response(),
u'instanceProperties': ReservationInstanceproperties(self.module.params.get('instance_properties', {}), self.module).to_request(),
}
)