From 9908b2fbf65c5fc2f7d5b0841fc06b82b6effdff Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 3 Apr 2019 10:31:08 -0700 Subject: [PATCH] Bug fixes for GCP modules (#54765) --- lib/ansible/module_utils/gcp_utils.py | 9 +------- .../cloud/google/gcp_spanner_database.py | 11 +++++----- .../google/gcp_spanner_database_facts.py | 11 +++++----- .../modules/cloud/google/gcp_sql_database.py | 11 +++++----- .../cloud/google/gcp_sql_database_facts.py | 11 +++++----- .../modules/cloud/google/gcp_sql_user.py | 11 +++++----- .../cloud/google/gcp_sql_user_facts.py | 11 +++++----- .../cloud/google/gcp_storage_bucket.py | 22 ++++++++++--------- .../gcp_storage_bucket_access_control.py | 11 +++++----- 9 files changed, 55 insertions(+), 53 deletions(-) diff --git a/lib/ansible/module_utils/gcp_utils.py b/lib/ansible/module_utils/gcp_utils.py index ffa5b5c565b..ae4f88582b7 100644 --- a/lib/ansible/module_utils/gcp_utils.py +++ b/lib/ansible/module_utils/gcp_utils.py @@ -62,16 +62,9 @@ def replace_resource_dict(item, value): else: if not item: return item - if isinstance(item, dict): + else: return item.get(value) - # Item could be a string or a string representing a dictionary. - try: - new_item = ast.literal_eval(item) - return replace_resource_dict(new_item, value) - except ValueError: - return item - # Handles all authentication and HTTP sessions for GCP API calls. class GcpSession(object): diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database.py b/lib/ansible/modules/cloud/google/gcp_spanner_database.py index e9d852ed249..19306cdd6bb 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database.py @@ -63,9 +63,10 @@ options: description: - The instance to create the database on. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_spanner_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true extends_documentation_fragment: gcp notes: @@ -117,7 +118,7 @@ instance: description: - The instance to create the database on. returned: success - type: str + type: dict ''' ################################################################################ @@ -140,7 +141,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(required=True, type='str'), extra_statements=dict(type='list', elements='str'), - instance=dict(required=True), + instance=dict(required=True, type='dict'), ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py b/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py index 23d4f296bd8..e5d02ce5acc 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py @@ -44,9 +44,10 @@ options: description: - The instance to create the database on. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_spanner_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true extends_documentation_fragment: gcp ''' @@ -85,7 +86,7 @@ items: description: - The instance to create the database on. returned: success - type: str + type: dict ''' ################################################################################ @@ -100,7 +101,7 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True))) + module = GcpModule(argument_spec=dict(instance=dict(required=True, type='dict'))) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database.py b/lib/ansible/modules/cloud/google/gcp_sql_database.py index 94a65adf448..c13402a1ed8 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database.py @@ -64,9 +64,10 @@ options: 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. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_sql_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true extends_documentation_fragment: gcp ''' @@ -120,7 +121,7 @@ instance: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: str + type: dict ''' ################################################################################ @@ -145,7 +146,7 @@ def main(): charset=dict(type='str'), collation=dict(type='str'), name=dict(type='str'), - instance=dict(required=True), + instance=dict(required=True, type='dict'), ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py b/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py index df677e04694..215fef21881 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py @@ -44,9 +44,10 @@ options: 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. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_sql_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true extends_documentation_fragment: gcp ''' @@ -87,7 +88,7 @@ items: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: str + type: dict ''' ################################################################################ @@ -102,7 +103,7 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True))) + module = GcpModule(argument_spec=dict(instance=dict(required=True, type='dict'))) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user.py b/lib/ansible/modules/cloud/google/gcp_sql_user.py index 9699a4ea8c1..6428e7f3416 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user.py @@ -61,9 +61,10 @@ options: 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. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_sql_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true password: description: @@ -118,7 +119,7 @@ instance: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: str + type: dict password: description: - The password for the user. @@ -147,7 +148,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), host=dict(required=True, type='str'), name=dict(required=True, type='str'), - instance=dict(required=True), + instance=dict(required=True, type='dict'), password=dict(type='str'), ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py b/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py index 9511a872f10..3cfe6326594 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py @@ -44,9 +44,10 @@ options: 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. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_sql_instance task and then set this instance field to "{{ name-of-resource + }}"' required: true extends_documentation_fragment: gcp ''' @@ -83,7 +84,7 @@ items: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: str + type: dict password: description: - The password for the user. @@ -103,7 +104,7 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True))) + module = GcpModule(argument_spec=dict(instance=dict(required=True, type='dict'))) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py index 73b13f7363c..e33cbed2302 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py @@ -61,9 +61,10 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. First, you can place in the name of the resource here as a - string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value + of your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_storage_bucket task and then set this bucket field to "{{ name-of-resource + }}"' required: true entity: description: @@ -140,9 +141,10 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. First, you can place in the name of the resource here as a - string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value + of your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_storage_bucket task and then set this bucket field to "{{ name-of-resource + }}"' required: true entity: description: @@ -359,7 +361,7 @@ acl: description: - The name of the bucket. returned: success - type: str + type: dict domain: description: - The domain associated with the entity. @@ -453,7 +455,7 @@ defaultObjectAcl: description: - The name of the bucket. returned: success - type: str + type: dict domain: description: - The domain associated with the entity. @@ -740,7 +742,7 @@ def main(): type='list', elements='dict', options=dict( - bucket=dict(required=True), + bucket=dict(required=True, type='dict'), entity=dict(required=True, type='str'), entity_id=dict(type='str'), project_team=dict( @@ -763,7 +765,7 @@ def main(): type='list', elements='dict', options=dict( - bucket=dict(required=True), + bucket=dict(required=True, type='dict'), entity=dict(required=True, type='str'), object=dict(type='str'), role=dict(required=True, type='str', choices=['OWNER', 'READER']), diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py index 8e25f11418a..49c9dc76e79 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py @@ -60,9 +60,10 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. First, you can place in the name of the resource here as a string - Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''name'' and value of + your resource''s name Alternatively, you can add `register: name-of-resource` + to a gcp_storage_bucket task and then set this bucket field to "{{ name-of-resource + }}"' required: true entity: description: @@ -131,7 +132,7 @@ bucket: description: - The name of the bucket. returned: success - type: str + type: dict domain: description: - The domain associated with the entity. @@ -203,7 +204,7 @@ def main(): module = GcpModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), - bucket=dict(required=True), + bucket=dict(required=True, type='dict'), entity=dict(required=True, type='str'), entity_id=dict(type='str'), project_team=dict(type='dict', options=dict(project_number=dict(type='str'), team=dict(type='str', choices=['editors', 'owners', 'viewers']))),