2018-02-06 01:08:22 +01:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
|
|
|
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2019-03-01 03:25:49 +01:00
|
|
|
tenant_id: "{{ azure_tenant }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
run_once: yes
|
|
|
|
|
2018-09-05 11:48:27 +02:00
|
|
|
- name: lookup service principal object id
|
|
|
|
set_fact:
|
|
|
|
object_id: "{{ lookup('azure_service_principal_attribute',
|
|
|
|
azure_client_id=azure_client_id,
|
|
|
|
azure_secret=azure_secret,
|
|
|
|
azure_tenant=tenant_id) }}"
|
|
|
|
register: object_id
|
|
|
|
|
2018-02-06 01:08:22 +01:00
|
|
|
- name: Create instance of Key Vault -- check mode
|
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
enabled_for_deployment: yes
|
2018-09-05 11:48:27 +02:00
|
|
|
vault_tenant: "{{ tenant_id }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
sku:
|
|
|
|
name: standard
|
|
|
|
family: A
|
|
|
|
access_policies:
|
2018-09-05 11:48:27 +02:00
|
|
|
- tenant_id: "{{ tenant_id }}"
|
|
|
|
object_id: "{{ object_id }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
keys:
|
|
|
|
- get
|
|
|
|
- list
|
2018-09-05 11:48:27 +02:00
|
|
|
- update
|
|
|
|
- create
|
|
|
|
- import
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
|
|
|
secrets:
|
|
|
|
- get
|
|
|
|
- list
|
|
|
|
- set
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
2018-02-06 01:08:22 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create instance of Key Vault
|
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
enabled_for_deployment: yes
|
2018-09-05 11:48:27 +02:00
|
|
|
vault_tenant: "{{ tenant_id }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
sku:
|
|
|
|
name: standard
|
|
|
|
family: A
|
|
|
|
access_policies:
|
2018-09-05 11:48:27 +02:00
|
|
|
- tenant_id: "{{ tenant_id }}"
|
|
|
|
object_id: "{{ object_id }}"
|
|
|
|
secrets:
|
2018-02-06 01:08:22 +01:00
|
|
|
- get
|
|
|
|
- list
|
2018-09-05 11:48:27 +02:00
|
|
|
- set
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
2018-02-06 01:08:22 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
2018-09-05 11:48:27 +02:00
|
|
|
- name: Create instance of Key Vault again
|
2018-02-06 01:08:22 +01:00
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
enabled_for_deployment: yes
|
2018-09-05 11:48:27 +02:00
|
|
|
vault_tenant: "{{ tenant_id }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
sku:
|
|
|
|
name: standard
|
|
|
|
family: A
|
|
|
|
access_policies:
|
2018-09-05 11:48:27 +02:00
|
|
|
- tenant_id: "{{ tenant_id }}"
|
|
|
|
object_id: "{{ object_id }}"
|
|
|
|
secrets:
|
2018-02-06 01:08:22 +01:00
|
|
|
- get
|
|
|
|
- list
|
2018-09-05 11:48:27 +02:00
|
|
|
- set
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
2018-02-06 01:08:22 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
|
2018-09-05 10:21:15 +02:00
|
|
|
- name: Update existing Key Vault (add a rule and tags)
|
2018-02-06 01:08:22 +01:00
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
enabled_for_deployment: yes
|
2018-09-05 11:48:27 +02:00
|
|
|
vault_tenant: "{{ tenant_id }}"
|
2018-02-06 01:08:22 +01:00
|
|
|
sku:
|
|
|
|
name: standard
|
|
|
|
family: A
|
|
|
|
access_policies:
|
2018-09-05 11:48:27 +02:00
|
|
|
- tenant_id: "{{ tenant_id }}"
|
|
|
|
object_id: "{{ object_id }}"
|
|
|
|
keys:
|
2018-02-06 01:08:22 +01:00
|
|
|
- get
|
|
|
|
- list
|
2018-09-05 11:48:27 +02:00
|
|
|
- update
|
|
|
|
- create
|
|
|
|
- import
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
|
|
|
secrets:
|
2018-02-06 01:08:22 +01:00
|
|
|
- get
|
|
|
|
- list
|
2018-09-05 11:48:27 +02:00
|
|
|
- set
|
|
|
|
- delete
|
|
|
|
- recover
|
|
|
|
- backup
|
|
|
|
- restore
|
2018-09-05 10:21:15 +02:00
|
|
|
tags:
|
|
|
|
aaa: bbb
|
2018-02-06 01:08:22 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == true
|
|
|
|
|
2019-05-22 21:39:37 +02:00
|
|
|
- name: Get key vault facts
|
|
|
|
azure_rm_keyvault_info:
|
2018-09-05 10:21:15 +02:00
|
|
|
resource_group: "{{ resource_group }}"
|
2019-05-22 21:39:37 +02:00
|
|
|
name: "vault{{ rpfx }}"
|
|
|
|
register: facts
|
|
|
|
|
2018-09-05 10:21:15 +02:00
|
|
|
- name: Assert the facts are properly set
|
|
|
|
assert:
|
|
|
|
that:
|
2019-05-22 21:39:37 +02:00
|
|
|
- facts['keyvaults'] | length == 1
|
|
|
|
- facts['keyvaults'][0]['vault_uri'] != None
|
|
|
|
- facts['keyvaults'][0]['name'] != None
|
|
|
|
- facts['keyvaults'][0]['access_policies'] != None
|
|
|
|
- facts['keyvaults'][0]['sku'] != None
|
|
|
|
- facts['keyvaults'][0]['id'] != None
|
2018-09-05 11:48:27 +02:00
|
|
|
#
|
|
|
|
# azure_rm_keyvaultkey tests
|
|
|
|
#
|
|
|
|
|
2019-04-22 03:52:17 +02:00
|
|
|
- name: create a keyvault key
|
2018-09-05 11:48:27 +02:00
|
|
|
block:
|
|
|
|
- azure_rm_keyvaultkey:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
key_name: testkey
|
|
|
|
tags:
|
|
|
|
testing: test
|
|
|
|
delete: on-exit
|
|
|
|
register: output
|
|
|
|
- assert:
|
|
|
|
that: output.changed
|
|
|
|
rescue:
|
|
|
|
- azure_rm_keyvaultkey:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
state: absent
|
|
|
|
key_name: testkey
|
|
|
|
|
2019-07-18 00:55:51 +02:00
|
|
|
- name: Get key current version
|
|
|
|
azure_rm_keyvaultkey_info:
|
|
|
|
vault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
name: testkey
|
|
|
|
register: facts
|
|
|
|
|
|
|
|
- name: Assert key facts
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- facts['keys'] | length == 1
|
|
|
|
- facts['keys'][0]['kid']
|
|
|
|
- facts['keys'][0]['permitted_operations'] | length > 0
|
|
|
|
- facts['keys'][0]['type']
|
|
|
|
- facts['keys'][0]['version']
|
|
|
|
|
|
|
|
- name: delete a kevyault key
|
2018-09-05 11:48:27 +02:00
|
|
|
azure_rm_keyvaultkey:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
state: absent
|
|
|
|
key_name: testkey
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: output.changed
|
|
|
|
|
|
|
|
#
|
|
|
|
# azure_rm_keyvaultsecret tests
|
|
|
|
#
|
2019-04-22 03:52:17 +02:00
|
|
|
- name: create a keyvault secret
|
2018-09-05 11:48:27 +02:00
|
|
|
block:
|
|
|
|
- azure_rm_keyvaultsecret:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
secret_name: testsecret
|
|
|
|
secret_value: 'mysecret'
|
|
|
|
tags:
|
|
|
|
testing: test
|
|
|
|
delete: on-exit
|
|
|
|
register: output
|
|
|
|
- assert:
|
|
|
|
that: output.changed
|
|
|
|
rescue:
|
|
|
|
- azure_rm_keyvaultsecret:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
state: absent
|
|
|
|
secret_name: testsecret
|
|
|
|
|
2019-04-22 03:52:17 +02:00
|
|
|
- name: delete a keyvault secret
|
2018-09-05 11:48:27 +02:00
|
|
|
azure_rm_keyvaultsecret:
|
|
|
|
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
|
|
|
|
state: absent
|
|
|
|
secret_name: testsecret
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: output.changed
|
|
|
|
|
|
|
|
#
|
|
|
|
# azure_rm_keyvault finalize & clean up
|
|
|
|
#
|
2018-09-05 10:21:15 +02:00
|
|
|
|
2018-02-06 01:08:22 +01:00
|
|
|
- name: Delete instance of Key Vault -- check mode
|
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
state: absent
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete instance of Key Vault
|
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete unexisting instance of Key Vault
|
|
|
|
azure_rm_keyvault:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
vault_name: "vault{{ rpfx }}"
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|