Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema update support to spanner db 2082 #291

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions plugins/modules/gcp_spanner_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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 @@ -235,13 +235,26 @@ def create(module, link):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))


def update(module, link):
def update(module, link, fetch):
module.fail_json(msg="Spanner objects can't be updated to ensure data safety")


def update_fields(module, request, response):
if response.get('extraStatements') != request.get('extraStatements'):
extra_statements_update(module, request, response)


def extra_statements_update(module, request, response):
auth = GcpSession(module, 'spanner')
auth.patch(
''.join(["https://spanner.googleapis.com/v1/", "projects/{project}/instances/{instance}/databases/{name}/ddl"]).format(**module.params),
{u'extraStatements': module.params.get('extra_statements')},
)


def delete(module, link):
auth = GcpSession(module, 'spanner')
return return_if_object(module, auth.delete(link))
return wait_for_operation(module, auth.delete(link))


def resource_to_request(module):
Expand Down Expand Up @@ -315,7 +328,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {u'name': module.params.get('name'), u'extraStatements': module.params.get('extra_statements')}
return {u'name': module.params.get('name'), u'extraStatements': response.get(u'extraStatements')}


def async_op_url(module, extra_data=None):
Expand Down