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 utils for ec2_vpc_vgw_* #2331

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- module_utils/ec2 - add utils for the ec2_vpc_vgw_* modules (https://github.com/ansible-collections/amazon.aws/pull/2331).
54 changes: 53 additions & 1 deletion plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def reject_vpc_peering_connection(client, peering_id: str) -> bool:
return True


# EC2 VPC VPN
# EC2 vpn
class EC2VpnErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error

Expand Down Expand Up @@ -648,6 +648,58 @@ def create_dhcp_options(
return client.create_dhcp_options(**params)["DhcpOptions"]


# EC2 vpn Gateways
class EC2VpnGatewaysErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error

@classmethod
def _is_missing(cls):
return is_boto3_error_code(["InvalidVpnGatewayID.NotFound", "InvalidVpnGatewayState"])


@EC2VpnGatewaysErrorHandler.list_error_handler("describe vpn gateways", [])
@AWSRetry.jittered_backoff()
def describe_vpn_gateways(
client, **params: Dict[str, Union[List[str], int, List[Dict[str, Union[str, List[str]]]]]]
) -> List[Dict[str, Any]]:
return client.describe_vpn_gateways(**params)["VpnGateways"]


@EC2VpnGatewaysErrorHandler.common_error_handler("create vpn gateway")
@AWSRetry.jittered_backoff()
mandar242 marked this conversation as resolved.
Show resolved Hide resolved
def create_vpn_gateway(
client, **params: Dict[str, Union[List[str], int, List[Dict[str, Union[str, List[str]]]]]]
) -> Dict[str, Any]:
return client.create_vpn_gateway(**params)["VpnGateway"]


@EC2VpnGatewaysErrorHandler.deletion_error_handler("delete vpn gateway")
@AWSRetry.jittered_backoff()
def delete_vpn_gateway(
client, vpn_gateway_id: str
) -> bool:
client.delete_vpn_gateway(VpnGatewayId=vpn_gateway_id)
return True


@EC2VpnGatewaysErrorHandler.common_error_handler("attach vpn gateway")
@AWSRetry.jittered_backoff()
def attach_vpn_gateway(
client, vpc_id: str, vpn_gateway_id: str
) -> bool:
client.attach_vpn_gateway(VpcId=vpc_id, VpnGatewayId=vpn_gateway_id)
return True


@EC2VpnGatewaysErrorHandler.common_error_handler("detach vpn gateway")
@AWSRetry.jittered_backoff()
def detach_vpn_gateway(
client, vpc_id: str, vpn_gateway_id: str
) -> bool:
client.detach_vpn_gateway(VpcId=vpc_id, VpnGatewayId=vpn_gateway_id)
return True


# EC2 Volumes
class EC2VolumeErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error
Expand Down
24 changes: 21 additions & 3 deletions plugins/module_utils/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,23 @@
"operation": "DescribeVpnGateways",
"acceptors": [
{
"matcher": "path",
"expected": True,
"argument": "VpnGateways[0].State == 'available'",
"expected": "detached",
"matcher": "pathAll",
"state": "success",
"argument": "VpnGateways[].VpcAttachments[].State",
},
],
},
"VpnGatewayAttached": {
"delay": 5,
"maxAttempts": 40,
"operation": "DescribeVpnGateways",
"acceptors": [
{
"expected": "attached",
"matcher": "pathAll",
"state": "success",
"argument": "VpnGateways[].VpcAttachments[].State",
},
],
},
Expand Down Expand Up @@ -920,6 +933,11 @@ def route53_model(name):
ec2_model("VpnGatewayDetached"),
core_waiter.NormalizedOperationMethod(ec2.describe_vpn_gateways),
),
("EC2", "vpn_gateway_attached"): lambda ec2: core_waiter.Waiter(
"vpn_gateway_attached",
ec2_model("VpnGatewayAttached"),
core_waiter.NormalizedOperationMethod(ec2.describe_vpn_gateways),
),
("EC2", "nat_gateway_deleted"): lambda ec2: core_waiter.Waiter(
"nat_gateway_deleted",
ec2_model("NatGatewayDeleted"),
Expand Down
Loading