mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-07-28 15:41:32 -07:00
108 lines
4.6 KiB
YAML
108 lines
4.6 KiB
YAML
# Copyright 2025 Google Inc.
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
---
|
|
# Pre-test setup
|
|
- name: Delete the test parameter if it exists
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
project: "{{ gcp_project }}"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: absent
|
|
- name: Create a parameter
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
version: "test_version"
|
|
value: "ansible lookup test parameter value"
|
|
labels:
|
|
key1: "val1"
|
|
key2: "val2"
|
|
project: "{{ gcp_project }}"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: present
|
|
- name: Add a new version to a parameter
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
version: "test_version_1"
|
|
value: "ansible lookup test parameter value updated"
|
|
project: "{{ gcp_project }}"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: present
|
|
# ----------------------------------------------------------
|
|
- name: Retrieve the latest parameter version of a parameter
|
|
ansible.builtin.debug:
|
|
msg: "{{ lookup('google.cloud.gcp_parameter_manager', key=lookup_resource_name, project=gcp_project, auth_kind=gcp_cred_kind, service_account_file=gcp_cred_file | default(omit)) }}"
|
|
register: result
|
|
- name: Assert parameter value
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.msg == "ansible lookup test parameter value updated"
|
|
# ----------------------------------------------------------
|
|
- name: Retrieve the specified parameter version of a parameter
|
|
ansible.builtin.debug:
|
|
msg: "{{ lookup('google.cloud.gcp_parameter_manager', key=lookup_resource_name, version='test_version', project=gcp_project, auth_kind=gcp_cred_kind, service_account_file=gcp_cred_file | default(omit)) }}"
|
|
register: result
|
|
- name: Assert parameter value
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.msg == "ansible lookup test parameter value"
|
|
# ---------------------------------------------------------
|
|
- name: Render the latest parameter version of a parameter
|
|
ansible.builtin.debug:
|
|
msg: "{{ lookup('google.cloud.gcp_parameter_manager', key=lookup_resource_name, project=gcp_project, auth_kind=gcp_cred_kind, render_secret=True, service_account_file=gcp_cred_file | default(omit)) }}"
|
|
register: result
|
|
- name: Assert parameter value
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.msg == "ansible lookup test parameter value updated"
|
|
# ----------------------------------------------------------
|
|
- name: Render the specified parameter version of a parameter
|
|
ansible.builtin.debug:
|
|
msg: "{{ lookup('google.cloud.gcp_parameter_manager', key=lookup_resource_name, version='test_version', project=gcp_project, auth_kind=gcp_cred_kind, render_secret=True, service_account_file=gcp_cred_file | default(omit)) }}"
|
|
register: result
|
|
- name: Assert parameter value
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.msg == "ansible lookup test parameter value"
|
|
# ---------------------------------------------------------
|
|
# Post-test teardown
|
|
# If errors happen, don't crash the playbook!
|
|
- name: Delete the test parameter version
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
project: "{{ gcp_project }}"
|
|
version: "test_version"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: absent
|
|
ignore_errors: true
|
|
- name: Delete the test parameter version
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
project: "{{ gcp_project }}"
|
|
version: "test_version_1"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: absent
|
|
ignore_errors: true
|
|
- name: Delete the test parameter
|
|
google.cloud.gcp_parameter_manager:
|
|
name: "{{ lookup_resource_name }}"
|
|
project: "{{ gcp_project }}"
|
|
auth_kind: "{{ gcp_cred_kind }}"
|
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
state: absent
|
|
ignore_errors: true
|