Add test case when specified service account does not exist

This commit is contained in:
Benjamin Gandon 2024-01-22 17:44:42 +01:00
parent f404ab3a00
commit 6d61b6699b

View file

@ -100,3 +100,41 @@
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: absent
- name: Delete a service account key file
connection: local
ansible.builtin.file:
path: "{{ gcp_cred_file }}-temporary-service-account-key"
state: absent
#----------------------------------------------------------
- name: Create a service account key with icorrect service account name
google.cloud.gcp_iam_service_account_key:
service_account:
name: service-{{ resource_name.split("-")[-1] }}
private_key_type: TYPE_GOOGLE_CREDENTIALS_FILE
path: "{{ gcp_cred_file }}-temporary-service-account-key"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: present
register: result
failed_when: result.failed == false
- name: Assert changed is true
ansible.builtin.assert:
that:
- result.msg is match('No such Service Account')
- name: Verify that service_account_key was not created
connection: local
ansible.builtin.stat:
path: "{{ gcp_cred_file }}-temporary-service-account-key"
register: key_file
- name: Verify that command succeeded
ansible.builtin.assert:
that:
- key_file.stat.exists == false