Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar242 committed Oct 22, 2024
1 parent 7ce1585 commit b9f5670
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
49 changes: 19 additions & 30 deletions plugins/modules/ec2_transit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,14 @@ def wait_for_status(self, wait_timeout: int, tgw_id: str, status: str, skip_dele

waiter_method = f"transit_gateway_{status}"

try:
wait_for_resource_state(
self._connection,
self._module,
waiter_method,
TransitGatewayIds=[tgw_id],
delay=polling_increment_secs,
max_attempts=max_attempts,
)
except AnsibleEC2Error as e:
self._module.fail_json_aws_error(e)
wait_for_resource_state(
self._connection,
self._module,
waiter_method,
TransitGatewayIds=[tgw_id],
delay=polling_increment_secs,
max_attempts=max_attempts,
)

transit_gateway = self.get_matching_tgw(tgw_id=tgw_id, skip_deleted=skip_deleted)
if transit_gateway is None:
Expand Down Expand Up @@ -375,10 +372,8 @@ def delete_tgw(self, tgw_id: str) -> Dict[str, Any]:
"""
wait = self._module.params.get("wait")
wait_timeout = self._module.params.get("wait_timeout")
try:
response = delete_ec2_transit_gateway(self._connection, tgw_id)
except AnsibleEC2Error as e:
self._module.fail_json_aws_error(e)

delete_ec2_transit_gateway(self._connection, tgw_id)

if wait:
result = self.wait_for_status(
Expand Down Expand Up @@ -407,13 +402,10 @@ def ensure_tgw_present(self, tgw_id: Optional[str] = None, description: Optional
self._results["transit_gateway_id"] = None
return self._results

try:
if not description:
self._module.fail_json(msg="Failed to create Transit Gateway: description argument required")
tgw = self.create_tgw(description)
self._results["changed"] = True
except AnsibleEC2Error as e:
self._module.fail_json_aws(e, msg="Unable to create Transit Gateway")
if not description:
self._module.fail_json(msg="Failed to create Transit Gateway: description argument required")
tgw = self.create_tgw(description)
self._results["changed"] = True

self._results["changed"] |= ensure_ec2_tags(
self._connection,
Expand Down Expand Up @@ -442,14 +434,11 @@ def ensure_tgw_absent(self, tgw_id: Optional[str] = None, description: Optional[
self._results["changed"] = True
return self._results

try:
tgw = self.delete_tgw(tgw_id=tgw["transit_gateway_id"])
self._results["changed"] = True
self._results["transit_gateway"] = self.get_matching_tgw(
tgw_id=tgw["transit_gateway_id"], skip_deleted=False
)
except AnsibleEC2Error as e:
self._module.fail_json_aws(e, msg="Unable to delete Transit Gateway")
tgw = self.delete_tgw(tgw_id=tgw["transit_gateway_id"])
self._results["changed"] = True
self._results["transit_gateway"] = self.get_matching_tgw(
tgw_id=tgw["transit_gateway_id"], skip_deleted=False
)

return self._results

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/ec2_transit_gateway/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
block:

- name: Generate unique value for testing
set_fact:
ansible.builtin.set_fact:
tgw_description: "{{ resource_prefix }}-tgw"

- name: Test create transit gateway without tags - check_mode
Expand Down Expand Up @@ -181,7 +181,7 @@
- result.changed == False

- name: Generate unique value for testing
set_fact:
ansible.builtin.set_fact:
tgw_description_multicast: "{{ resource_prefix }}-tgw-multicast"

- name: Test create transit gateway with multicast enabled - check_mode
Expand Down

0 comments on commit b9f5670

Please sign in to comment.