diff --git a/tests/integration/targets/gcp_iam_service_account_key/tasks/service-account-keys.yml b/tests/integration/targets/gcp_iam_service_account_key/tasks/service-account-keys.yml index 8f37ca7..6712476 100644 --- a/tests/integration/targets/gcp_iam_service_account_key/tasks/service-account-keys.yml +++ b/tests/integration/targets/gcp_iam_service_account_key/tasks/service-account-keys.yml @@ -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