From e4882b3a3ffd53de730951c78ee261cc763ca551 Mon Sep 17 00:00:00 2001 From: pmangin <96626847+pmangin@users.noreply.github.com> Date: Tue, 28 Dec 2021 15:03:14 +0100 Subject: [PATCH] Add support of project id for scawelay_compute (#3951) * Add support of project id for scawelay_compute * Create 3951-scaleway_compute_add_project_id * rename changelog frament * remove useless whitespace in scaleway_compute.py * Update changelogs/fragments/3951-scaleway_compute_add_project_id.yml Co-authored-by: Felix Fontein * Update plugins/modules/cloud/scaleway/scaleway_compute.py Co-authored-by: Felix Fontein * correct documentation * Update changelogs/fragments/3951-scaleway_compute_add_project_id.yml Co-authored-by: Felix Fontein * Update changelogs/fragments/3951-scaleway_compute_add_project_id.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../3951-scaleway_compute_add_project_id.yml | 2 ++ .../cloud/scaleway/scaleway_compute.py | 36 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/3951-scaleway_compute_add_project_id.yml diff --git a/changelogs/fragments/3951-scaleway_compute_add_project_id.yml b/changelogs/fragments/3951-scaleway_compute_add_project_id.yml new file mode 100644 index 0000000000..70c6b2a715 --- /dev/null +++ b/changelogs/fragments/3951-scaleway_compute_add_project_id.yml @@ -0,0 +1,2 @@ +minor_changes: + - scaleway_compute - add possibility to use project identifier (new ``project`` option) instead of deprecated organization identifier (https://github.com/ansible-collections/community.general/pull/3951). diff --git a/plugins/modules/cloud/scaleway/scaleway_compute.py b/plugins/modules/cloud/scaleway/scaleway_compute.py index 0b4e1a1b1d..a195d7fb93 100644 --- a/plugins/modules/cloud/scaleway/scaleway_compute.py +++ b/plugins/modules/cloud/scaleway/scaleway_compute.py @@ -54,8 +54,15 @@ options: organization: type: str description: - - Organization identifier - required: true + - Organization identifier. + - Exactly one of I(project) and I(organization) must be specified. + + project: + type: str + description: + - Project identifier. + - Exactly one of I(project) and I(organization) must be specified. + version_added: 4.3.0 state: type: str @@ -132,7 +139,7 @@ EXAMPLES = ''' name: foobar state: present image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe - organization: 951df375-e094-4d26-97c1-ba548eeb9c42 + project: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S tags: @@ -144,7 +151,7 @@ EXAMPLES = ''' name: foobar state: present image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe - organization: 951df375-e094-4d26-97c1-ba548eeb9c42 + project: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S security_group: 4a31b633-118e-4900-bd52-facf1085fc8d @@ -157,7 +164,7 @@ EXAMPLES = ''' name: foobar state: absent image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe - organization: 951df375-e094-4d26-97c1-ba548eeb9c42 + project: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S ''' @@ -269,10 +276,15 @@ def create_server(compute_api, server): "commercial_type": server["commercial_type"], "image": server["image"], "dynamic_ip_required": server["dynamic_ip_required"], - "name": server["name"], - "organization": server["organization"] + "name": server["name"] } + if server["project"]: + data["project"] = server["project"] + + if server["organization"]: + data["organization"] = server["organization"] + if server["security_group"]: data["security_group"] = server["security_group"] @@ -628,6 +640,7 @@ def core(module): "enable_ipv6": module.params["enable_ipv6"], "tags": module.params["tags"], "organization": module.params["organization"], + "project": module.params["project"], "security_group": module.params["security_group"] } module.params['api_url'] = SCALEWAY_LOCATION[region]["api_endpoint"] @@ -655,7 +668,8 @@ def main(): public_ip=dict(default="absent"), state=dict(choices=list(state_strategy.keys()), default='present'), tags=dict(type="list", elements="str", default=[]), - organization=dict(required=True), + organization=dict(), + project=dict(), wait=dict(type="bool", default=False), wait_timeout=dict(type="int", default=300), wait_sleep_time=dict(type="int", default=3), @@ -664,6 +678,12 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, + mutually_exclusive=[ + ('organization', 'project'), + ], + required_one_of=[ + ('organization', 'project'), + ], ) core(module)