Ryan Brown 2018-10-18 10:55:42 -04:00 committed by Alex Stephen
parent 84f0e2c5b2
commit 5c97cc1da0
78 changed files with 2531 additions and 1137 deletions

View file

@ -62,6 +62,11 @@ options:
instance:
description:
- The name of the Cloud SQL instance. This does not include the project ID.
- 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_sql_instance task
and then set this instance field to "{{ name-of-resource }}" Alternatively, you
can set this instance to a dictionary with the name key where the value is the name
of your Instance.'
required: true
extends_documentation_fragment: gcp
'''
@ -89,7 +94,7 @@ EXAMPLES = '''
charset: utf8
instance: "{{ instance }}"
project: "test_project"
auth_kind: "service_account"
auth_kind: "serviceaccount"
service_account_file: "/tmp/auth.pem"
state: present
'''
@ -156,7 +161,8 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
update(module, self_link(module), kind)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind)
@ -204,9 +210,9 @@ def resource_to_request(module):
return return_vals
def fetch_resource(module, link, kind):
def fetch_resource(module, link, kind, allow_not_found=True):
auth = GcpSession(module, 'sql')
return return_if_object(module, auth.get(link), kind)
return return_if_object(module, auth.get(link), kind, allow_not_found)
def self_link(module):
@ -226,7 +232,7 @@ def collection(module):
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**res)
def return_if_object(module, response, kind):
def return_if_object(module, response, kind, allow_not_found=False):
# If not found, return nothing.
if response.status_code == 404:
return None