---
# ----------------------------------------------------------------------------
#
#     ***     AUTO GENERATED CODE    ***    Type: MMv1     ***
#
# ----------------------------------------------------------------------------
#
#     This file is automatically generated by Magic Modules and manual
#     changes will be clobbered when the file is regenerated.
#
#     Please read more about how to change this file at
#     https://www.github.com/GoogleCloudPlatform/magic-modules
#
# ----------------------------------------------------------------------------
# Pre-test setup
- name: create a managed zone
  google.cloud.gcp_dns_managed_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 }}"
    state: present
  register: managed_zone
- name: delete a resource record set
  google.cloud.gcp_dns_resource_record_set:
    name: www.testzone-4.com.
    managed_zone: "{{ managed_zone }}"
    type: A
    ttl: 600
    target:
    - 10.1.2.3
    - 40.5.6.7
    project: "{{ gcp_project }}"
    auth_kind: "{{ gcp_cred_kind }}"
    service_account_file: "{{ gcp_cred_file }}"
    state: absent
#----------------------------------------------------------
- name: create a resource record set
  google.cloud.gcp_dns_resource_record_set:
    name: www.testzone-4.com.
    managed_zone: "{{ managed_zone }}"
    type: A
    ttl: 600
    target:
    - 10.1.2.3
    - 40.5.6.7
    project: "{{ gcp_project }}"
    auth_kind: "{{ gcp_cred_kind }}"
    service_account_file: "{{ gcp_cred_file }}"
    state: present
  register: result
- name: assert changed is true
  assert:
    that:
      - result.changed == true
- name: verify that resource_record_set was created
  google.cloud.gcp_dns_resource_record_set_info:
      managed_zone: "{{ managed_zone }}"
      project: "{{ gcp_project }}"
      auth_kind: "{{ gcp_cred_kind }}"
      service_account_file: "{{ gcp_cred_file }}"
      scopes:
        - https://www.googleapis.com/auth/ndev.clouddns.readwrite
  register: results
- name: verify that command succeeded
  assert:
    that:
      - "'www.testzone-4.com.'in \"{{ results['resources'] | map(attribute='name') | list }}\""
# ----------------------------------------------------------------------------
- name: create a resource record set that already exists
  google.cloud.gcp_dns_resource_record_set:
    name: www.testzone-4.com.
    managed_zone: "{{ managed_zone }}"
    type: A
    ttl: 600
    target:
    - 10.1.2.3
    - 40.5.6.7
    project: "{{ gcp_project }}"
    auth_kind: "{{ gcp_cred_kind }}"
    service_account_file: "{{ gcp_cred_file }}"
    state: present
  register: result
- name: assert changed is false
  assert:
    that:
      - result.changed == false
#----------------------------------------------------------
- name: delete a resource record set
  google.cloud.gcp_dns_resource_record_set:
    name: www.testzone-4.com.
    managed_zone: "{{ managed_zone }}"
    type: A
    ttl: 600
    target:
    - 10.1.2.3
    - 40.5.6.7
    project: "{{ gcp_project }}"
    auth_kind: "{{ gcp_cred_kind }}"
    service_account_file: "{{ gcp_cred_file }}"
    state: absent
  register: result
- name: assert changed is true
  assert:
    that:
      - result.changed == true
- name: verify that resource_record_set was deleted
  google.cloud.gcp_dns_resource_record_set_info:
      managed_zone: "{{ managed_zone }}"
      project: "{{ gcp_project }}"
      auth_kind: "{{ gcp_cred_kind }}"
      service_account_file: "{{ gcp_cred_file }}"
      scopes:
        - https://www.googleapis.com/auth/ndev.clouddns.readwrite
  register: results
- name: verify that command succeeded
  assert:
    that:
      - "'www.testzone-4.com.'not in \"{{ results['resources'] | map(attribute='name') | list }}\""
# ----------------------------------------------------------------------------
- name: delete a resource record set that does not exist
  google.cloud.gcp_dns_resource_record_set:
    name: www.testzone-4.com.
    managed_zone: "{{ managed_zone }}"
    type: A
    ttl: 600
    target:
    - 10.1.2.3
    - 40.5.6.7
    project: "{{ gcp_project }}"
    auth_kind: "{{ gcp_cred_kind }}"
    service_account_file: "{{ gcp_cred_file }}"
    state: absent
  register: result
- name: assert changed is false
  assert:
    that:
      - result.changed == false
#---------------------------------------------------------
# Post-test teardown
# If errors happen, don't crash the playbook!
- name: delete a managed zone
  google.cloud.gcp_dns_managed_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 }}"
    state: absent
  register: managed_zone
  ignore_errors: true
