Bug fixes for gcp_dns_resource_record_set (#42832)

pull/44749/merge
Alex Stephen 6 years ago committed by Ryan Brown
parent 473b6dbe8a
commit e9c9ccc561

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

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

Loading…
Cancel
Save