Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vpc key to returned VPC data on create #277

Merged
merged 3 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/276-vpc-inconsistent-data-return.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- digital_ocean_vpc - add C(vpc) key to returned VPC data on create (https://github.com/ansible-collections/community.digitalocean/issues/276).
46 changes: 31 additions & 15 deletions plugins/modules/digital_ocean_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@
returned: success
type: dict
sample:
created_at: '2021-06-17T11:43:12.12121565Z'
default: false
description: ''
id: a3b72d97-192f-4984-9d71-08a5faf2e0c7
ip_range: 10.116.16.0/20
name: testvpc1
region: nyc1
urn: do:vpc:a3b72d97-192f-4984-9d71-08a5faf2e0c7
msg: Created VPC myvpc1 in nyc1
vpc:
created_at: '2021-06-17T11:43:12.12121565Z'
default: false
description: ''
id: a3b72d97-192f-4984-9d71-08a5faf2e0c7
ip_range: 10.116.16.0/20
name: testvpc1
region: nyc1
urn: do:vpc:a3b72d97-192f-4984-9d71-08a5faf2e0c7
"""


Expand Down Expand Up @@ -173,12 +175,16 @@ def create(self):
json = response.json
if response.status_code != 200:
self.module.fail_json(
msg="Failed to update VPC {0}: {1}".format(
self.name, json["message"]
msg="Failed to update VPC {0} in {1}: {2}".format(
self.name, self.region, json["message"]
)
)
else:
self.module.exit_json(changed=False, data=json)
self.module.exit_json(
changed=False,
data=json,
msg="Updated VPC {0} in {1}".format(self.name, self.region),
)
else:
self.module.fail_json(
changed=False, msg="Unexpected error, please file a bug"
Expand All @@ -198,11 +204,17 @@ def create(self):
status = response.status_code
json = response.json
if status == 201:
self.module.exit_json(changed=True, data=json["vpc"])
self.module.exit_json(
changed=True,
data=json,
msg="Created VPC {0} in {1}".format(self.name, self.region),
)
else:
self.module.fail_json(
changed=False,
msg="Failed to create VPC: {0}".format(json["message"]),
msg="Failed to create VPC {0} in {1}: {2}".format(
self.name, self.region, json["message"]
),
)

def delete(self):
Expand All @@ -211,7 +223,9 @@ def delete(self):

vpc = self.get_by_name()
if vpc is None:
self.module.fail_json(msg="Unable to find VPC {0}".format(self.name))
self.module.fail_json(
msg="Unable to find VPC {0} in {1}".format(self.name, self.region)
)
else:
vpc_id = vpc.get("id", None)
if vpc_id is not None:
Expand All @@ -221,7 +235,9 @@ def delete(self):
if status == 204:
self.module.exit_json(
changed=True,
msg="Deleted VPC {0} ({1})".format(self.name, vpc_id),
msg="Deleted VPC {0} in {1} ({2})".format(
self.name, self.region, vpc_id
),
)
else:
json = response.json
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/targets/digital_ocean_vpc/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
that:
- result.changed
- result.data is defined
- result.data != {}
- result.data.name == vpc_name
- result.data.vpc is defined
- result.data.vpc != {}
- result.data.vpc.name == vpc_name

- name: Set a fact for the VPC ID
ansible.builtin.set_fact:
vpc_id: "{{ result.data.id }}"
vpc_id: "{{ result.data.vpc.id }}"

- name: Fetch VPC members
community.digitalocean.digital_ocean_vpc_info:
Expand Down