Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for GCP Dns Resource Record Sets #42832

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 43 additions & 33 deletions lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
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)
Expand All @@ -48,12 +48,11 @@
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:
Expand All @@ -62,55 +61,51 @@
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:
- 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
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
'''

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
- 10.1.2.3
- 40.5.6.7
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:
Expand All @@ -120,18 +115,18 @@
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:
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
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
'''
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -346,6 +353,9 @@ def __init__(self, params, module):
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:]
Expand All @@ -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


Expand Down
66 changes: 26 additions & 40 deletions test/integration/targets/gcp_dns_resource_record_set/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,40 @@
# 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
- 40.5.6.7
- 10.1.2.3
- 40.5.6.7
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
- 40.5.6.7
- 10.1.2.3
- 40.5.6.7
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
Expand All @@ -65,18 +59,16 @@
# ----------------------------------------------------------------------------
- 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
- 40.5.6.7
- 10.1.2.3
- 40.5.6.7
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
Expand All @@ -87,18 +79,16 @@
#----------------------------------------------------------
- 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
- 40.5.6.7
- 10.1.2.3
- 40.5.6.7
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
Expand All @@ -109,18 +99,16 @@
# ----------------------------------------------------------------------------
- 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
- 40.5.6.7
- 10.1.2.3
- 40.5.6.7
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
Expand All @@ -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