From 36fd9d1b6a51461489ff8c67d0ae84f47534cda2 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 16 Jan 2019 11:15:35 -0800 Subject: [PATCH] Bug fixes for GCP modules (as of 2019-01-09T15:35:45-08:00) (#50783) --- .../cloud/google/gcp_compute_address.py | 11 ++- .../cloud/google/gcp_compute_address_facts.py | 2 +- .../google/gcp_compute_backend_service.py | 12 +-- .../gcp_compute_backend_service_facts.py | 2 +- .../modules/cloud/google/gcp_compute_disk.py | 11 ++- .../cloud/google/gcp_compute_disk_facts.py | 2 +- .../cloud/google/gcp_compute_firewall.py | 11 ++- .../google/gcp_compute_firewall_facts.py | 2 +- .../google/gcp_compute_forwarding_rule.py | 45 ++++++----- .../gcp_compute_forwarding_rule_facts.py | 8 +- .../google/gcp_compute_global_address.py | 7 ++ .../gcp_compute_global_forwarding_rule.py | 34 ++++----- ...cp_compute_global_forwarding_rule_facts.py | 6 +- .../modules/cloud/google/gcp_compute_image.py | 74 +++++++++++++++---- .../gcp_compute_backend_bucket/tasks/main.yml | 2 + .../tasks/main.yml | 3 + .../tasks/main.yml | 3 + .../tasks/main.yml | 7 ++ .../targets/gcp_compute_image/tasks/main.yml | 2 + 19 files changed, 152 insertions(+), 92 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_compute_address.py b/lib/ansible/modules/cloud/google/gcp_compute_address.py index d4295108465..f93c8d450a3 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_address.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_address.py @@ -102,10 +102,9 @@ options: - This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes. - 'This field represents a link to a Subnetwork resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork - task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively, - you can set this subnetwork to a dictionary with the selfLink key where the - value is the selfLink of your Subnetwork' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_subnetwork + task and then set this subnetwork field to "{{ name-of-resource }}"' required: false version_added: 2.7 region: @@ -183,7 +182,7 @@ subnetwork: - This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes. returned: success - type: dict + type: str users: description: - The URLs of the resources that are using this address. @@ -221,7 +220,7 @@ def main(): description=dict(type='str'), name=dict(required=True, type='str'), network_tier=dict(type='str', choices=['PREMIUM', 'STANDARD']), - subnetwork=dict(type='dict'), + subnetwork=dict(), region=dict(required=True, type='str') ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_compute_address_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_address_facts.py index ba06eb409c6..d5b5140fe18 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_address_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_address_facts.py @@ -122,7 +122,7 @@ items: - This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes. returned: success - type: dict + type: str users: description: - The URLs of the resources that are using this address. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py index 4716e96fcea..d2e23376c61 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py @@ -97,10 +97,10 @@ options: - When the BackendService has load balancing scheme INTERNAL, the instance group must be in a zone within the same region as the BackendService. - 'This field represents a link to a InstanceGroup resource in GCP. It can - be specified in two ways. You can add `register: name-of-resource` to a - gcp_compute_instance_group task and then set this group field to "{{ name-of-resource - }}" Alternatively, you can set this group to a dictionary with the selfLink - key where the value is the selfLink of your InstanceGroup' + be specified in two ways. First, you can place in the selfLink of the resource + here as a string Alternatively, you can add `register: name-of-resource` + to a gcp_compute_instance_group task and then set this group field to "{{ + name-of-resource }}"' required: false max_connections: description: @@ -387,7 +387,7 @@ backends: - When the BackendService has load balancing scheme INTERNAL, the instance group must be in a zone within the same region as the BackendService. returned: success - type: dict + type: str maxConnections: description: - The max number of simultaneous connections for the group. Can be used with @@ -626,7 +626,7 @@ def main(): balancing_mode=dict(type='str', choices=['UTILIZATION', 'RATE', 'CONNECTION']), capacity_scaler=dict(type='str'), description=dict(type='str'), - group=dict(type='dict'), + group=dict(), max_connections=dict(type='int'), max_connections_per_instance=dict(type='int'), max_rate=dict(type='int'), diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py index e6d7feaa914..d714c80005e 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py @@ -115,7 +115,7 @@ items: - When the BackendService has load balancing scheme INTERNAL, the instance group must be in a zone within the same region as the BackendService. returned: success - type: dict + type: str maxConnections: description: - The max number of simultaneous connections for the group. Can be used diff --git a/lib/ansible/modules/cloud/google/gcp_compute_disk.py b/lib/ansible/modules/cloud/google/gcp_compute_disk.py index 327313991a7..7d9990d4b87 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_disk.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_disk.py @@ -157,10 +157,9 @@ options: - The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. - 'This field represents a link to a Snapshot resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_snapshot - task and then set this source_snapshot field to "{{ name-of-resource }}" Alternatively, - you can set this source_snapshot to a dictionary with the selfLink key where - the value is the selfLink of your Snapshot' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_snapshot + task and then set this source_snapshot field to "{{ name-of-resource }}"' required: false source_snapshot_encryption_key: description: @@ -351,7 +350,7 @@ sourceSnapshot: - The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. returned: success - type: dict + type: str sourceSnapshotEncryptionKey: description: - The customer-supplied encryption key of the source snapshot. Required if the source @@ -418,7 +417,7 @@ def main(): raw_key=dict(type='str'), sha256=dict(type='str') )), - source_snapshot=dict(type='dict'), + source_snapshot=dict(), source_snapshot_encryption_key=dict(type='dict', options=dict( raw_key=dict(type='str'), sha256=dict(type='str') diff --git a/lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py index bf5af4150cc..cbf483fcd90 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py @@ -224,7 +224,7 @@ items: - The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. returned: success - type: dict + type: str sourceSnapshotEncryptionKey: description: - The customer-supplied encryption key of the source snapshot. Required if the diff --git a/lib/ansible/modules/cloud/google/gcp_compute_firewall.py b/lib/ansible/modules/cloud/google/gcp_compute_firewall.py index 0a91375152f..75e9118ab3d 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_firewall.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_firewall.py @@ -147,10 +147,9 @@ options: networks/my-network projects/myproject/global/networks/my-network global/networks/default .' - 'This field represents a link to a Network resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_network - task and then set this network field to "{{ name-of-resource }}" Alternatively, - you can set this network to a dictionary with the selfLink key where the value - is the selfLink of your Network' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network + task and then set this network field to "{{ name-of-resource }}"' required: false default: selfLink: global/networks/default @@ -343,7 +342,7 @@ network: networks/my-network projects/myproject/global/networks/my-network global/networks/default .' returned: success - type: dict + type: str priority: description: - Priority for this rule. This is an integer between 0 and 65535, both inclusive. @@ -441,7 +440,7 @@ def main(): direction=dict(type='str', choices=['INGRESS', 'EGRESS']), disabled=dict(type='bool'), name=dict(required=True, type='str'), - network=dict(default={'selfLink': 'global/networks/default'}, type='dict'), + network=dict(default={'selfLink': 'global/networks/default'}), priority=dict(default=1000, type='int'), source_ranges=dict(type='list', elements='str'), source_service_accounts=dict(type='list', elements='str'), diff --git a/lib/ansible/modules/cloud/google/gcp_compute_firewall_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_firewall_facts.py index 1cc69b5d682..ae21847fd6a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_firewall_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_firewall_facts.py @@ -170,7 +170,7 @@ items: networks/my-network projects/myproject/global/networks/my-network global/networks/default .' returned: success - type: dict + type: str priority: description: - Priority for this rule. This is an integer between 0 and 65535, both inclusive. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py index 192c73160b4..0c844e7ef09 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py @@ -96,10 +96,10 @@ options: - This is used for internal load balancing. - "(not used for external load balancing) ." - 'This field represents a link to a BackendService resource in GCP. It can be - specified in two ways. You can add `register: name-of-resource` to a gcp_compute_backend_service - task and then set this backend_service field to "{{ name-of-resource }}" Alternatively, - you can set this backend_service to a dictionary with the selfLink key where - the value is the selfLink of your BackendService' + specified in two ways. First, you can place in the selfLink of the resource + here as a string Alternatively, you can add `register: name-of-resource` to + a gcp_compute_backend_service task and then set this backend_service field to + "{{ name-of-resource }}"' required: false ip_version: description: @@ -136,10 +136,9 @@ options: specified, the default network will be used. - This field is not used for external load balancing. - 'This field represents a link to a Network resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_network - task and then set this network field to "{{ name-of-resource }}" Alternatively, - you can set this network to a dictionary with the selfLink key where the value - is the selfLink of your Network' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network + task and then set this network field to "{{ name-of-resource }}"' required: false port_range: description: @@ -172,10 +171,9 @@ options: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. - 'This field represents a link to a Subnetwork resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork - task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively, - you can set this subnetwork to a dictionary with the selfLink key where the - value is the selfLink of your Subnetwork' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_subnetwork + task and then set this subnetwork field to "{{ name-of-resource }}"' required: false target: description: @@ -186,10 +184,9 @@ options: target object. - This field is not used for internal load balancing. - 'This field represents a link to a TargetPool resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_target_pool - task and then set this target field to "{{ name-of-resource }}" Alternatively, - you can set this target to a dictionary with the selfLink key where the value - is the selfLink of your TargetPool' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_target_pool + task and then set this target field to "{{ name-of-resource }}"' required: false version_added: 2.7 network_tier: @@ -301,7 +298,7 @@ backendService: - This is used for internal load balancing. - "(not used for external load balancing) ." returned: success - type: dict + type: str ipVersion: description: - The IP Version that will be used by this forwarding rule. Valid options are IPV4 @@ -334,7 +331,7 @@ network: the default network will be used. - This field is not used for external load balancing. returned: success - type: dict + type: str portRange: description: - This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy, @@ -367,7 +364,7 @@ subnetwork: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. returned: success - type: dict + type: str target: description: - A reference to a TargetPool resource to receive the matched traffic. @@ -377,7 +374,7 @@ target: target object. - This field is not used for internal load balancing. returned: success - type: dict + type: str networkTier: description: - 'The networking tier used for configuring this address. This field can take the @@ -415,15 +412,15 @@ def main(): description=dict(type='str'), ip_address=dict(type='str'), ip_protocol=dict(type='str', choices=['TCP', 'UDP', 'ESP', 'AH', 'SCTP', 'ICMP']), - backend_service=dict(type='dict'), + backend_service=dict(), ip_version=dict(type='str', choices=['IPV4', 'IPV6']), load_balancing_scheme=dict(type='str', choices=['INTERNAL', 'EXTERNAL']), name=dict(required=True, type='str'), - network=dict(type='dict'), + network=dict(), port_range=dict(type='str'), ports=dict(type='list', elements='str'), - subnetwork=dict(type='dict'), - target=dict(type='dict'), + subnetwork=dict(), + target=dict(), network_tier=dict(type='str', choices=['PREMIUM', 'STANDARD']), region=dict(required=True, type='str') ) diff --git a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_facts.py index e5bd5fd37ee..0099c445d55 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_facts.py @@ -123,7 +123,7 @@ items: - This is used for internal load balancing. - "(not used for external load balancing) ." returned: success - type: dict + type: str ipVersion: description: - The IP Version that will be used by this forwarding rule. Valid options are @@ -156,7 +156,7 @@ items: specified, the default network will be used. - This field is not used for external load balancing. returned: success - type: dict + type: str portRange: description: - This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy, @@ -191,7 +191,7 @@ items: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. returned: success - type: dict + type: str target: description: - A reference to a TargetPool resource to receive the matched traffic. @@ -201,7 +201,7 @@ items: to the target object. - This field is not used for internal load balancing. returned: success - type: dict + type: str networkTier: description: - 'The networking tier used for configuring this address. This field can take diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_address.py b/lib/ansible/modules/cloud/google/gcp_compute_global_address.py index 4d6861a90fe..ad7b35053e2 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_address.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_address.py @@ -49,6 +49,11 @@ options: - present - absent default: present + address: + description: + - The static external IP address represented by this resource. + required: false + version_added: 2.8 description: description: - An optional description of this resource. @@ -170,6 +175,7 @@ def main(): module = GcpModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), + address=dict(type='str'), description=dict(type='str'), name=dict(required=True, type='str'), ip_version=dict(type='str', choices=['IPV4', 'IPV6']), @@ -225,6 +231,7 @@ def delete(module, link, kind): def resource_to_request(module): request = { u'kind': 'compute#address', + u'address': module.params.get('address'), u'description': module.params.get('description'), u'name': module.params.get('name'), u'ipVersion': module.params.get('ip_version'), diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py index 21acb0c69ff..4420c59546a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py @@ -98,10 +98,10 @@ options: - This is used for internal load balancing. - "(not used for external load balancing) ." - 'This field represents a link to a BackendService resource in GCP. It can be - specified in two ways. You can add `register: name-of-resource` to a gcp_compute_backend_service - task and then set this backend_service field to "{{ name-of-resource }}" Alternatively, - you can set this backend_service to a dictionary with the selfLink key where - the value is the selfLink of your BackendService' + specified in two ways. First, you can place in the selfLink of the resource + here as a string Alternatively, you can add `register: name-of-resource` to + a gcp_compute_backend_service task and then set this backend_service field to + "{{ name-of-resource }}"' required: false ip_version: description: @@ -138,10 +138,9 @@ options: specified, the default network will be used. - This field is not used for external load balancing. - 'This field represents a link to a Network resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_network - task and then set this network field to "{{ name-of-resource }}" Alternatively, - you can set this network to a dictionary with the selfLink key where the value - is the selfLink of your Network' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network + task and then set this network field to "{{ name-of-resource }}"' required: false port_range: description: @@ -174,10 +173,9 @@ options: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. - 'This field represents a link to a Subnetwork resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork - task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively, - you can set this subnetwork to a dictionary with the selfLink key where the - value is the selfLink of your Subnetwork' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_subnetwork + task and then set this subnetwork field to "{{ name-of-resource }}"' required: false target: description: @@ -321,7 +319,7 @@ backendService: - This is used for internal load balancing. - "(not used for external load balancing) ." returned: success - type: dict + type: str ipVersion: description: - The IP Version that will be used by this forwarding rule. Valid options are IPV4 @@ -354,7 +352,7 @@ network: the default network will be used. - This field is not used for external load balancing. returned: success - type: dict + type: str portRange: description: - This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy, @@ -387,7 +385,7 @@ subnetwork: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. returned: success - type: dict + type: str region: description: - A reference to the region where the regional forwarding rule resides. @@ -425,14 +423,14 @@ def main(): description=dict(type='str'), ip_address=dict(type='str'), ip_protocol=dict(type='str', choices=['TCP', 'UDP', 'ESP', 'AH', 'SCTP', 'ICMP']), - backend_service=dict(type='dict'), + backend_service=dict(), ip_version=dict(type='str', choices=['IPV4', 'IPV6']), load_balancing_scheme=dict(type='str', choices=['INTERNAL', 'EXTERNAL']), name=dict(required=True, type='str'), - network=dict(type='dict'), + network=dict(), port_range=dict(type='str'), ports=dict(type='list', elements='str'), - subnetwork=dict(type='dict'), + subnetwork=dict(), target=dict(type='str') ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_facts.py index 3e2a1340074..525ef8def2c 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_facts.py @@ -117,7 +117,7 @@ items: - This is used for internal load balancing. - "(not used for external load balancing) ." returned: success - type: dict + type: str ipVersion: description: - The IP Version that will be used by this forwarding rule. Valid options are @@ -150,7 +150,7 @@ items: specified, the default network will be used. - This field is not used for external load balancing. returned: success - type: dict + type: str portRange: description: - This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy, @@ -185,7 +185,7 @@ items: if the network is in custom subnet mode, a subnetwork must be specified. - This field is not used for external load balancing. returned: success - type: dict + type: str region: description: - A reference to the region where the regional forwarding rule resides. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_image.py b/lib/ansible/modules/cloud/google/gcp_compute_image.py index 51385be5352..fec986d9f89 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_image.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_image.py @@ -112,6 +112,11 @@ options: - The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource. required: false + labels: + description: + - Labels to apply to this Image. + required: false + version_added: 2.8 licenses: description: - Any applicable license URI. @@ -147,16 +152,16 @@ options: description: - The full Google Cloud Storage URL where disk storage is stored You must provide either this property or the sourceDisk property but not both. - required: false + required: true source_disk: description: - - Refers to a gcompute_disk object You must provide either this property or the - rawDisk.source property but not both to create an image. + - The source disk to create this image based on. + - You must provide either this property or the rawDisk.source property but not + both to create an image. - 'This field represents a link to a Disk resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_compute_disk - task and then set this source_disk field to "{{ name-of-resource }}" Alternatively, - you can set this source_disk to a dictionary with the selfLink key where the - value is the selfLink of your Disk' + in two ways. First, you can place in the selfLink of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_compute_disk + task and then set this source_disk field to "{{ name-of-resource }}"' required: false source_disk_encryption_key: description: @@ -188,6 +193,9 @@ options: choices: - RAW extends_documentation_fragment: gcp +notes: +- 'API Reference: U(https://cloud.google.com/compute/docs/reference/latest/images)' +- 'Official Documentation: U(https://cloud.google.com/compute/docs/images)' ''' EXAMPLES = ''' @@ -330,6 +338,17 @@ imageEncryptionKey: key that protects this resource. returned: success type: str +labels: + description: + - Labels to apply to this Image. + returned: success + type: dict +labelFingerprint: + description: + - The fingerprint used for optimistic locking of this resource. Used internally + during updates. + returned: success + type: str licenses: description: - Any applicable license URI. @@ -372,10 +391,11 @@ rawDisk: type: str sourceDisk: description: - - Refers to a gcompute_disk object You must provide either this property or the - rawDisk.source property but not both to create an image. + - The source disk to create this image based on. + - You must provide either this property or the rawDisk.source property but not both + to create an image. returned: success - type: dict + type: str sourceDiskEncryptionKey: description: - The customer-supplied encryption key of the source disk. Required if the source @@ -439,14 +459,15 @@ def main(): raw_key=dict(type='str'), sha256=dict(type='str') )), + labels=dict(type='dict'), licenses=dict(type='list', elements='str'), name=dict(required=True, type='str'), raw_disk=dict(type='dict', options=dict( container_type=dict(type='str', choices=['TAR']), sha1_checksum=dict(type='str'), - source=dict(type='str') + source=dict(required=True, type='str') )), - source_disk=dict(type='dict'), + source_disk=dict(), source_disk_encryption_key=dict(type='dict', options=dict( raw_key=dict(type='str'), sha256=dict(type='str') @@ -468,7 +489,7 @@ def main(): if fetch: if state == 'present': if is_different(module, fetch): - update(module, self_link(module), kind) + update(module, self_link(module), kind, fetch) fetch = fetch_resource(module, self_link(module), kind) changed = True else: @@ -492,9 +513,29 @@ def create(module, link, kind): return wait_for_operation(module, auth.post(link, resource_to_request(module))) -def update(module, link, kind): +def update(module, link, kind, fetch): + update_fields(module, resource_to_request(module), + response_to_hash(module, fetch)) + return fetch_resource(module, self_link(module), kind) + + +def update_fields(module, request, response): + if response.get('labels') != request.get('labels'): + labels_update(module, request, response) + + +def labels_update(module, request, response): auth = GcpSession(module, 'compute') - return wait_for_operation(module, auth.put(link, resource_to_request(module))) + auth.post( + ''.join([ + "https://www.googleapis.com/compute/v1/", + "projects/{project}/global/images/{name}/setLabels" + ]).format(**module.params), + { + u'labels': module.params.get('labels'), + u'labelFingerprint': response.get('labelFingerprint') + } + ) def delete(module, link, kind): @@ -510,6 +551,7 @@ def resource_to_request(module): u'family': module.params.get('family'), u'guestOsFeatures': ImageGuestosfeaturesArray(module.params.get('guest_os_features', []), module).to_request(), u'imageEncryptionKey': ImageImageencryptionkey(module.params.get('image_encryption_key', {}), module).to_request(), + u'labels': module.params.get('labels'), u'licenses': module.params.get('licenses'), u'name': module.params.get('name'), u'rawDisk': ImageRawdisk(module.params.get('raw_disk', {}), module).to_request(), @@ -591,6 +633,8 @@ def response_to_hash(module, response): u'guestOsFeatures': ImageGuestosfeaturesArray(response.get(u'guestOsFeatures', []), module).from_response(), u'id': response.get(u'id'), u'imageEncryptionKey': ImageImageencryptionkey(response.get(u'imageEncryptionKey', {}), module).from_response(), + u'labels': response.get(u'labels'), + u'labelFingerprint': response.get(u'labelFingerprint'), u'licenses': response.get(u'licenses'), u'name': response.get(u'name'), u'rawDisk': ImageRawdisk(response.get(u'rawDisk', {}), module).from_response(), diff --git a/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml b/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml index a9736e72482..c7f53425d86 100644 --- a/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml +++ b/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml @@ -129,6 +129,7 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a bucket gcp_storage_bucket: name: "bucket-backendbucket" @@ -137,3 +138,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: bucket + ignore_errors: true diff --git a/test/integration/targets/gcp_compute_backend_service/tasks/main.yml b/test/integration/targets/gcp_compute_backend_service/tasks/main.yml index c424ff3c3b4..3c73e067336 100644 --- a/test/integration/targets/gcp_compute_backend_service/tasks/main.yml +++ b/test/integration/targets/gcp_compute_backend_service/tasks/main.yml @@ -152,6 +152,7 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a http health check gcp_compute_http_health_check: name: "httphealthcheck-backendservice" @@ -164,6 +165,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: healthcheck + ignore_errors: true - name: delete a instance group gcp_compute_instance_group: name: "instancegroup-backendservice" @@ -173,3 +175,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: instancegroup + ignore_errors: true diff --git a/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml b/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml index 865cb377767..a8b9bf36f37 100644 --- a/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml +++ b/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml @@ -151,6 +151,7 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a target pool gcp_compute_target_pool: name: "targetpool-forwardingrule" @@ -160,6 +161,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: targetpool + ignore_errors: true - name: delete a address gcp_compute_address: name: "address-forwardingrule" @@ -169,3 +171,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: address + ignore_errors: true diff --git a/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml b/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml index aaaf8f35be0..e0a7c7af1ca 100644 --- a/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml +++ b/test/integration/targets/gcp_compute_global_forwarding_rule/tasks/main.yml @@ -186,6 +186,7 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a target http proxy gcp_compute_target_http_proxy: name: "targethttpproxy-globalforwardingrule" @@ -195,6 +196,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: httpproxy + ignore_errors: true - name: delete a url map gcp_compute_url_map: name: "urlmap-globalforwardingrule" @@ -204,6 +206,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: urlmap + ignore_errors: true - name: delete a backend service gcp_compute_backend_service: name: "backendservice-globalforwardingrule" @@ -217,6 +220,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: backendservice + ignore_errors: true - name: delete a http health check gcp_compute_http_health_check: name: "httphealthcheck-globalforwardingrule" @@ -229,6 +233,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: healthcheck + ignore_errors: true - name: delete a instance group gcp_compute_instance_group: name: "instancegroup-globalforwardingrule" @@ -238,6 +243,7 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: instancegroup + ignore_errors: true - name: delete a global address gcp_compute_global_address: name: "globaladdress-globalforwardingrule" @@ -246,3 +252,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: globaladdress + ignore_errors: true diff --git a/test/integration/targets/gcp_compute_image/tasks/main.yml b/test/integration/targets/gcp_compute_image/tasks/main.yml index 924ef0f6353..67dad40c4dd 100644 --- a/test/integration/targets/gcp_compute_image/tasks/main.yml +++ b/test/integration/targets/gcp_compute_image/tasks/main.yml @@ -120,6 +120,7 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a disk gcp_compute_disk: name: "disk-image" @@ -129,3 +130,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: disk + ignore_errors: true