Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Native Update Mask support (#176)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @rambleraptor
  • Loading branch information
modular-magician authored and rambleraptor committed Jan 30, 2019
1 parent 7081caa commit 54175cc
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_redis_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,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:
Expand All @@ -320,8 +320,25 @@ def create(module, link):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))


def update(module, link):
module.fail_json(msg="Instance cannot be edited")
def update(module, link, fetch):
auth = GcpSession(module, 'redis')
params = {'updateMask': updateMask(resource_to_request(module), response_to_hash(module, fetch))}
request = resource_to_request(module)
del request['name']
return wait_for_operation(module, auth.patch(link, request, params=params))


def updateMask(request, response):
update_mask = []
if request.get('displayName') != response.get('displayName'):
update_mask.append('displayName')
if request.get('labels') != response.get('labels'):
update_mask.append('labels')
if request.get('redisConfigs') != response.get('redisConfigs'):
update_mask.append('redisConfigs')
if request.get('memorySizeGb') != response.get('memorySizeGb'):
update_mask.append('memorySizeGb')
return ','.join(update_mask)


def delete(module, link):
Expand Down

0 comments on commit 54175cc

Please sign in to comment.