mirror of
				https://github.com/ansible-collections/google.cloud.git
				synced 2025-10-24 21:14:08 -07:00 
			
		
		
		
	Add labels and updates to DNS managed zone
This commit is contained in:
		
					parent
					
						
							
								5e762dc9a1
							
						
					
				
			
			
				commit
				
					
						912e155d1a
					
				
			
		
					 2 changed files with 31 additions and 23 deletions
				
			
		|  | @ -52,11 +52,11 @@ options: | ||||||
|     description: |     description: | ||||||
|     - A mutable string of at most 1024 characters associated with this resource for |     - A mutable string of at most 1024 characters associated with this resource for | ||||||
|       the user's convenience. Has no effect on the managed zone's function. |       the user's convenience. Has no effect on the managed zone's function. | ||||||
|     required: false |     required: true | ||||||
|   dns_name: |   dns_name: | ||||||
|     description: |     description: | ||||||
|     - The DNS name of this managed zone, for instance "example.com.". |     - The DNS name of this managed zone, for instance "example.com.". | ||||||
|     required: false |     required: true | ||||||
|   name: |   name: | ||||||
|     description: |     description: | ||||||
|     - User assigned name for this resource. |     - User assigned name for this resource. | ||||||
|  | @ -68,6 +68,11 @@ options: | ||||||
|       is a set of DNS name servers that all host the same ManagedZones. Most users |       is a set of DNS name servers that all host the same ManagedZones. Most users | ||||||
|       will leave this field unset. |       will leave this field unset. | ||||||
|     required: false |     required: false | ||||||
|  |   labels: | ||||||
|  |     description: | ||||||
|  |     - A set of key/value label pairs to assign to this ManagedZone. | ||||||
|  |     required: false | ||||||
|  |     version_added: 2.8 | ||||||
| extends_documentation_fragment: gcp | extends_documentation_fragment: gcp | ||||||
| notes: | notes: | ||||||
| - 'API Reference: U(https://cloud.google.com/dns/api/v1/managedZones)' | - 'API Reference: U(https://cloud.google.com/dns/api/v1/managedZones)' | ||||||
|  | @ -128,6 +133,11 @@ creationTime: | ||||||
|   - This is in RFC3339 text format. |   - This is in RFC3339 text format. | ||||||
|   returned: success |   returned: success | ||||||
|   type: str |   type: str | ||||||
|  | labels: | ||||||
|  |   description: | ||||||
|  |   - A set of key/value label pairs to assign to this ManagedZone. | ||||||
|  |   returned: success | ||||||
|  |   type: dict | ||||||
| ''' | ''' | ||||||
| 
 | 
 | ||||||
| ################################################################################ | ################################################################################ | ||||||
|  | @ -151,10 +161,8 @@ def main(): | ||||||
|             description=dict(required=True, type='str'), |             description=dict(required=True, type='str'), | ||||||
|             dns_name=dict(required=True, type='str'), |             dns_name=dict(required=True, type='str'), | ||||||
|             name=dict(required=True, type='str'), |             name=dict(required=True, type='str'), | ||||||
|             name_server_set=dict(type='str'), |             name_server_set=dict(type='list', elements='str'), | ||||||
|             labels=dict(type='dict'), |             labels=dict(type='dict') | ||||||
|             visibility=dict(default='public', type='str', choices=['private', 'public']), |  | ||||||
|             private_visibility_config=dict(type='dict', options=dict(networks=dict(type='list', elements='dict', options=dict(network_url=dict(type='str'))))), |  | ||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  | @ -170,7 +178,7 @@ def main(): | ||||||
|     if fetch: |     if fetch: | ||||||
|         if state == 'present': |         if state == 'present': | ||||||
|             if is_different(module, fetch): |             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) |                 fetch = fetch_resource(module, self_link(module), kind) | ||||||
|                 changed = True |                 changed = True | ||||||
|         else: |         else: | ||||||
|  | @ -195,28 +203,27 @@ def create(module, link, kind): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def update(module, link, kind, fetch): | def update(module, link, kind, fetch): | ||||||
|     update_fields(module, resource_to_request(module), response_to_hash(module, fetch)) |     update_fields(module, resource_to_request(module), | ||||||
|  |                   response_to_hash(module, fetch)) | ||||||
|     return fetch_resource(module, self_link(module), kind) |     return fetch_resource(module, self_link(module), kind) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def update_fields(module, request, response): | def update_fields(module, request, response): | ||||||
|     if ( |     if response.get('description') != request.get('description') or response.get('labels') != request.get('labels'): | ||||||
|         response.get('description') != request.get('description') |  | ||||||
|         or response.get('labels') != request.get('labels') |  | ||||||
|         or response.get('privateVisibilityConfig') != request.get('privateVisibilityConfig') |  | ||||||
|     ): |  | ||||||
|         description_update(module, request, response) |         description_update(module, request, response) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def description_update(module, request, response): | def description_update(module, request, response): | ||||||
|     auth = GcpSession(module, 'dns') |     auth = GcpSession(module, 'dns') | ||||||
|     auth.patch( |     auth.patch( | ||||||
|         ''.join(["https://www.googleapis.com/dns/v1/", "projects/{project}/managedZones/{name}"]).format(**module.params), |         ''.join([ | ||||||
|  |             "https://www.googleapis.com/dns/v1/", | ||||||
|  |             "projects/{project}/managedZones/{name}" | ||||||
|  |         ]).format(**module.params), | ||||||
|         { |         { | ||||||
|             u'description': module.params.get('description'), |             u'description': module.params.get('description'), | ||||||
|             u'labels': module.params.get('labels'), |             u'labels': module.params.get('labels') | ||||||
|             u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(module.params.get('private_visibility_config', {}), module).to_request(), |         } | ||||||
|         }, |  | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -232,9 +239,7 @@ def resource_to_request(module): | ||||||
|         u'dnsName': module.params.get('dns_name'), |         u'dnsName': module.params.get('dns_name'), | ||||||
|         u'name': module.params.get('name'), |         u'name': module.params.get('name'), | ||||||
|         u'nameServerSet': module.params.get('name_server_set'), |         u'nameServerSet': module.params.get('name_server_set'), | ||||||
|         u'labels': module.params.get('labels'), |         u'labels': module.params.get('labels') | ||||||
|         u'visibility': module.params.get('visibility'), |  | ||||||
|         u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(module.params.get('private_visibility_config', {}), module).to_request(), |  | ||||||
|     } |     } | ||||||
|     return_vals = {} |     return_vals = {} | ||||||
|     for k, v in request.items(): |     for k, v in request.items(): | ||||||
|  | @ -307,9 +312,7 @@ def response_to_hash(module, response): | ||||||
|         u'nameServers': response.get(u'nameServers'), |         u'nameServers': response.get(u'nameServers'), | ||||||
|         u'nameServerSet': response.get(u'nameServerSet'), |         u'nameServerSet': response.get(u'nameServerSet'), | ||||||
|         u'creationTime': response.get(u'creationTime'), |         u'creationTime': response.get(u'creationTime'), | ||||||
|         u'labels': response.get(u'labels'), |         u'labels': response.get(u'labels') | ||||||
|         u'visibility': response.get(u'visibility'), |  | ||||||
|         u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(response.get(u'privateVisibilityConfig', {}), module).from_response(), |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -103,6 +103,11 @@ items: | ||||||
|       - This is in RFC3339 text format. |       - This is in RFC3339 text format. | ||||||
|       returned: success |       returned: success | ||||||
|       type: str |       type: str | ||||||
|  |     labels: | ||||||
|  |       description: | ||||||
|  |       - A set of key/value label pairs to assign to this ManagedZone. | ||||||
|  |       returned: success | ||||||
|  |       type: dict | ||||||
| ''' | ''' | ||||||
| 
 | 
 | ||||||
| ################################################################################ | ################################################################################ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue