Bug fixes for gcp_dns_resource_record_set (#42832)

This commit is contained in:
Alex Stephen 2018-08-28 11:56:43 -04:00 committed by Ryan Brown
parent 473b6dbe8a
commit e9c9ccc561
2 changed files with 69 additions and 73 deletions

View file

@ -33,10 +33,10 @@ DOCUMENTATION = '''
module: gcp_dns_resource_record_set
description:
- A single DNS record that exists on a domain name (i.e. in a managed zone).
- This record defines the information about the domain and where the domain
/ subdomains direct to.
- The record will include the domain/subdomain name, a type (i.e. A, AAA,
CAA, MX, CNAME, NS, etc).
- This record defines the information about the domain and where the domain / subdomains
direct to.
- The record will include the domain/subdomain name, a type (i.e. A, AAA, CAA, MX,
CNAME, NS, etc) .
short_description: Creates a GCP ResourceRecordSet
version_added: 2.6
author: Google Inc. (@googlecloudplatform)
@ -48,12 +48,11 @@ options:
state:
description:
- Whether the given object should exist in GCP
required: true
choices: ['present', 'absent']
default: 'present'
name:
description:
- For example, www.example.com.
- For example, U(www.example.com.)
required: true
type:
description:
@ -62,8 +61,7 @@ options:
choices: ['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SPF', 'SRV', 'TXT']
ttl:
description:
- Number of seconds that this ResourceRecordSet can be cached by
resolvers.
- Number of seconds that this ResourceRecordSet can be cached by resolvers.
required: false
target:
description:
@ -71,7 +69,8 @@ options:
required: false
managed_zone:
description:
- A reference to ManagedZone resource.
- Identifies the managed zone addressed by this request.
- Can be the managed zone name or id.
required: true
extends_documentation_fragment: gcp
'''
@ -79,38 +78,34 @@ extends_documentation_fragment: gcp
EXAMPLES = '''
- name: create a managed zone
gcp_dns_managed_zone:
name: 'managedzone-rrs'
dns_name: 'testzone-4.com.'
description: 'test zone'
name: "managedzone-rrs"
dns_name: testzone-4.com.
description: test zone
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: present
register: managed_zone
- name: create a resource record set
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
- 40.5.6.7
project: testProject
auth_kind: service_account
service_account_file: /tmp/auth.pem
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
project: "test_project"
auth_kind: "service_account"
service_account_file: "/tmp/auth.pem"
state: present
'''
RETURN = '''
name:
description:
- For example, www.example.com.
- For example, U(www.example.com.)
returned: success
type: str
type:
@ -120,8 +115,7 @@ RETURN = '''
type: str
ttl:
description:
- Number of seconds that this ResourceRecordSet can be cached by
resolvers.
- Number of seconds that this ResourceRecordSet can be cached by resolvers.
returned: success
type: int
target:
@ -131,7 +125,8 @@ RETURN = '''
type: list
managed_zone:
description:
- A reference to ManagedZone resource.
- Identifies the managed zone addressed by this request.
- Can be the managed zone name or id.
returned: success
type: dict
'''
@ -165,6 +160,9 @@ def main():
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
state = module.params['state']
kind = 'dns#resourceRecordSet'
@ -227,7 +225,6 @@ def delete(module, link, kind, fetch):
def resource_to_request(module):
request = {
u'kind': 'dns#resourceRecordSet',
u'managed_zone': replace_resource_dict(module.params.get(u'managed_zone', {}), 'name'),
u'name': module.params.get('name'),
u'type': module.params.get('type'),
u'ttl': module.params.get('ttl'),
@ -263,11 +260,21 @@ def fetch_wrapped_resource(module, kind, wrap_kind, wrap_path):
def self_link(module):
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets?name={name}&type={type}".format(**module.params)
res = {
'project': module.params['project'],
'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name'),
'name': module.params['name'],
'type': module.params['type']
}
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets?name={name}&type={type}".format(**res)
def collection(module, extra_url=''):
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**module.params) + extra_url
res = {
'project': module.params['project'],
'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')
}
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res) + extra_url
def return_if_object(module, response, kind):
@ -346,6 +353,9 @@ class SOAForwardable(object):
def fail_json(self, *args, **kwargs):
self.module.fail_json(*args, **kwargs)
def raise_for_status(self, *args, **kwargs):
self.module.raise_for_status(*args, **kwargs)
def prefetch_soa_resource(module):
name = module.params['name'].split('.')[1:]
@ -365,7 +375,7 @@ def prefetch_soa_resource(module):
'dns#resourceRecordSetsListResponse',
'rrsets')
if not result:
raise ValueError("Google DNS Managed Zone %s not found" % module.params['managed_zone'])
raise ValueError("Google DNS Managed Zone %s not found" % module.params['managed_zone']['name'])
return result

View file

@ -15,21 +15,19 @@
# Pre-test setup
- name: create a managed zone
gcp_dns_managed_zone:
name: 'managedzone-rrs'
dns_name: 'testzone-4.com.'
description: 'test zone'
name: "managedzone-rrs"
dns_name: testzone-4.com.
description: test zone
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: present
register: managed_zone
- name: delete a resource record set
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
@ -37,15 +35,13 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: absent
#----------------------------------------------------------
- name: create a resource record set
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
@ -53,8 +49,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: present
register: result
- name: assert changed is true
@ -65,9 +59,9 @@
# ----------------------------------------------------------------------------
- name: create a resource record set that already exists
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
@ -75,8 +69,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: present
register: result
- name: assert changed is false
@ -87,9 +79,9 @@
#----------------------------------------------------------
- name: delete a resource record set
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
@ -97,8 +89,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: absent
register: result
- name: assert changed is true
@ -109,9 +99,9 @@
# ----------------------------------------------------------------------------
- name: delete a resource record set that does not exist
gcp_dns_resource_record_set:
name: 'www.testzone-4.com.'
name: www.testzone-4.com.
managed_zone: "{{ managed_zone }}"
type: 'A'
type: A
ttl: 600
target:
- 10.1.2.3
@ -119,8 +109,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: absent
register: result
- name: assert changed is false
@ -132,13 +120,11 @@
# Post-test teardown
- name: delete a managed zone
gcp_dns_managed_zone:
name: 'managedzone-rrs'
dns_name: 'testzone-4.com.'
description: 'test zone'
name: "managedzone-rrs"
dns_name: testzone-4.com.
description: test zone
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/ndev.clouddns.readwrite
state: absent
register: managed_zone