From 4959ab5004c77a45f05dd95d93a2c644954943b5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 7 Oct 2019 10:22:41 -0700 Subject: [PATCH] Bug fixes for GCP modules (#63153) --- .../cloud/google/gcp_bigquery_dataset.py | 53 +++++++++++++++++++ .../cloud/google/gcp_bigquery_dataset_info.py | 16 ++++++ 2 files changed, 69 insertions(+) diff --git a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset.py b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset.py index 875be8bff9d..db27ce2b421 100644 --- a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset.py +++ b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset.py @@ -200,6 +200,23 @@ options: required: false default: US type: str + default_encryption_configuration: + description: + - The default encryption key for all tables in the dataset. Once this property + is set, all newly-created partitioned tables in the dataset will have encryption + key set to this value, unless table creation request (or query) overrides the + key. + required: false + type: dict + version_added: '2.10' + suboptions: + kms_key_name: + description: + - Describes the Cloud KMS encryption key that will be used to protect destination + BigQuery table. The BigQuery Service Account associated with your project + requires access to this encryption key. + required: true + type: str project: description: - The Google Cloud Platform project to use. @@ -422,6 +439,22 @@ location: - Changing this forces a new resource to be created. returned: success type: str +defaultEncryptionConfiguration: + description: + - The default encryption key for all tables in the dataset. Once this property is + set, all newly-created partitioned tables in the dataset will have encryption + key set to this value, unless table creation request (or query) overrides the + key. + returned: success + type: complex + contains: + kmsKeyName: + description: + - Describes the Cloud KMS encryption key that will be used to protect destination + BigQuery table. The BigQuery Service Account associated with your project + requires access to this encryption key. + returned: success + type: str ''' ################################################################################ @@ -467,6 +500,7 @@ def main(): friendly_name=dict(type='str'), labels=dict(type='dict'), location=dict(default='US', type='str'), + default_encryption_configuration=dict(type='dict', options=dict(kms_key_name=dict(required=True, type='str'))), ) ) @@ -528,6 +562,9 @@ def resource_to_request(module): u'friendlyName': module.params.get('friendly_name'), u'labels': module.params.get('labels'), u'location': module.params.get('location'), + u'defaultEncryptionConfiguration': DatasetDefaultencryptionconfiguration( + module.params.get('default_encryption_configuration', {}), module + ).to_request(), } return_vals = {} for k, v in request.items(): @@ -606,6 +643,7 @@ def response_to_hash(module, response): u'labels': response.get(u'labels'), u'lastModifiedTime': response.get(u'lastModifiedTime'), u'location': response.get(u'location'), + u'defaultEncryptionConfiguration': DatasetDefaultencryptionconfiguration(response.get(u'defaultEncryptionConfiguration', {}), module).from_response(), } @@ -688,5 +726,20 @@ class DatasetDatasetreference(object): return remove_nones_from_dict({u'datasetId': self.request.get(u'datasetId'), u'projectId': self.request.get(u'projectId')}) +class DatasetDefaultencryptionconfiguration(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict({u'kmsKeyName': self.request.get('kms_key_name')}) + + def from_response(self): + return remove_nones_from_dict({u'kmsKeyName': self.request.get(u'kmsKeyName')}) + + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py index a149192ac1c..4007cf8e026 100644 --- a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py +++ b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py @@ -280,6 +280,22 @@ resources: - Changing this forces a new resource to be created. returned: success type: str + defaultEncryptionConfiguration: + description: + - The default encryption key for all tables in the dataset. Once this property + is set, all newly-created partitioned tables in the dataset will have encryption + key set to this value, unless table creation request (or query) overrides + the key. + returned: success + type: complex + contains: + kmsKeyName: + description: + - Describes the Cloud KMS encryption key that will be used to protect destination + BigQuery table. The BigQuery Service Account associated with your project + requires access to this encryption key. + returned: success + type: str ''' ################################################################################