diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index bf233f5..8dd37b0 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -278,7 +278,7 @@ """,""" - name: Fetch the connection hosts: localhost - tasks: + tasks: - equinix.cloud.metal_connection: project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" name: "new connection" @@ -323,12 +323,15 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, - required_one_of=[("name", "connection_id"), ("project_id", "organization_id")], + required_one_of=[("name", "connection_id", "id"), ("project_id", "organization_id")], ) - - vlans = module.params.get("vlans") + vlans = module.params.get("vlans") connection_type = module.params.get("type") + if not module.params.get("connection_id") and module.params.get("id"): + module.params["connection_id"] = module.params["id"] + + if connection_type == "dedicated": if vlans: module.fail_json(msg="A 'dedicated' connection can't have vlans.") diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index 636ec10..e1a7030 100755 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -87,18 +87,25 @@ project_id: "{{ project.id }}" name: "{{ test_connection.name }}" register: test_connection_fetched - + + - name: fetch existing connection using id + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + id: "{{ test_connection.id }}" + register: test_connection_fetched_with_id + - assert: that: - test_connection.name == "{{ test_name }}" - test_connection.id == "{{ test_connection_fetched.id }}" - + - test_connection.id == "{{ test_connection_fetched_with_id.id }}" + - name: list test connections equinix.cloud.metal_connection_info: project_id: "{{ project.id }}" name: "{{ test_name }}" register: test_connections_list - + - assert: that: - "test_connections_list.resources | length >= 1"