2019-02-07 01:06:44 +01:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
|
|
|
dbname: "cosmos{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2019-02-18 04:58:43 +01:00
|
|
|
vnname: "vn{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
subnetname: "subnet{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2019-02-07 01:06:44 +01:00
|
|
|
run_once: yes
|
|
|
|
|
2019-02-18 04:58:43 +01:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ vnname }}"
|
|
|
|
address_prefixes_cidr:
|
|
|
|
- 10.1.0.0/16
|
|
|
|
- 172.100.0.0/16
|
|
|
|
dns_servers:
|
|
|
|
- 127.0.0.1
|
|
|
|
- 127.0.0.3
|
|
|
|
|
|
|
|
- name: Add subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
name: "{{ subnetname }}"
|
|
|
|
virtual_network_name: "{{ vnname }}"
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
address_prefix_cidr: "10.1.0.0/24"
|
|
|
|
|
2019-02-07 01:06:44 +01:00
|
|
|
- name: Create instance of Database Account -- check mode
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
location: eastus
|
|
|
|
geo_rep_locations:
|
|
|
|
- name: eastus
|
|
|
|
failover_priority: 0
|
|
|
|
database_account_offer_type: Standard
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create instance of Database Account
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
location: eastus
|
|
|
|
geo_rep_locations:
|
|
|
|
- name: eastus
|
|
|
|
failover_priority: 0
|
|
|
|
- name: westus
|
|
|
|
failover_priority: 1
|
|
|
|
database_account_offer_type: Standard
|
2019-02-18 04:58:43 +01:00
|
|
|
is_virtual_network_filter_enabled: yes
|
|
|
|
virtual_network_rules:
|
|
|
|
- subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
virtual_network_name: "{{ vnname }}"
|
|
|
|
subnet_name: "{{ subnetname }}"
|
|
|
|
ignore_missing_vnet_service_endpoint: yes
|
2019-02-07 01:06:44 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create again instance of Database Account
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
location: eastus
|
|
|
|
geo_rep_locations:
|
|
|
|
- name: eastus
|
|
|
|
failover_priority: 0
|
|
|
|
- name: westus
|
|
|
|
failover_priority: 1
|
|
|
|
database_account_offer_type: Standard
|
2019-02-18 04:58:43 +01:00
|
|
|
is_virtual_network_filter_enabled: yes
|
|
|
|
virtual_network_rules:
|
|
|
|
- subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
virtual_network_name: "{{ vnname }}"
|
|
|
|
subnet_name: "{{ subnetname }}"
|
|
|
|
ignore_missing_vnet_service_endpoint: yes
|
2019-02-07 01:06:44 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
|
|
|
|
- name: Create again instance of Database Account -- change something
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
location: eastus
|
|
|
|
geo_rep_locations:
|
|
|
|
- name: eastus
|
|
|
|
failover_priority: 0
|
|
|
|
- name: westus
|
|
|
|
failover_priority: 1
|
|
|
|
database_account_offer_type: Standard
|
2019-02-18 04:58:43 +01:00
|
|
|
is_virtual_network_filter_enabled: yes
|
|
|
|
virtual_network_rules:
|
|
|
|
- subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
virtual_network_name: "{{ vnname }}"
|
|
|
|
subnet_name: "{{ subnetname }}"
|
|
|
|
ignore_missing_vnet_service_endpoint: yes
|
2019-02-07 01:06:44 +01:00
|
|
|
enable_automatic_failover: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete instance of Database Account -- check mode
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
state: absent
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete instance of Database Account
|
|
|
|
azure_rm_cosmosdbaccount:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ dbname }}"
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
# currently disabled as there's a bug in SDK / Service
|
|
|
|
#- name: Delete unexisting instance of Database Account
|
|
|
|
# azure_rm_cosmosdbaccount:
|
|
|
|
# resource_group: "{{ resource_group }}"
|
|
|
|
# name: "{{ dbname }}"
|
|
|
|
# state: absent
|
|
|
|
# register: output
|
|
|
|
#- name: Assert the state has changed
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - output.changed == false
|