diff --git a/plugins/modules/ec2_transit_gateway.py b/plugins/modules/ec2_transit_gateway.py index e0bd520b2b0..853479747ea 100644 --- a/plugins/modules/ec2_transit_gateway.py +++ b/plugins/modules/ec2_transit_gateway.py @@ -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: @@ -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( @@ -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, @@ -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 diff --git a/tests/integration/targets/ec2_transit_gateway/tasks/main.yml b/tests/integration/targets/ec2_transit_gateway/tasks/main.yml index 1bd6658fb00..fe542b1e1ec 100644 --- a/tests/integration/targets/ec2_transit_gateway/tasks/main.yml +++ b/tests/integration/targets/ec2_transit_gateway/tasks/main.yml @@ -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 @@ -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