Skip to content

Commit

Permalink
better state validation for vpc endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon committed Apr 30, 2024
1 parent 49c563a commit a550a30
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions localstack/services/ec2/resource_providers/aws_ec2_vpcendpoint.py
Expand Up @@ -104,11 +104,22 @@ def create(
message="Resource not found after creation",
)

return ProgressEvent(
status=OperationStatus.SUCCESS,
resource_model=model,
custom_context=request.custom_context,
)
state = response["VpcEndpoints"][0][
"State"
].lower() # API specifies capital but lowercase is returned
match state:
case "available":
return ProgressEvent(status=OperationStatus.SUCCESS, resource_model=model)
case "pending":
return ProgressEvent(status=OperationStatus.IN_PROGRESS, resource_model=model)
case "pendingacceptance":
return ProgressEvent(status=OperationStatus.IN_PROGRESS, resource_model=model)
case _:
return ProgressEvent(
status=OperationStatus.FAILED,
resource_model=model,
message=f"Invalid state '{state}' for resource",
)

def read(
self,
Expand Down Expand Up @@ -138,11 +149,22 @@ def delete(
VpcEndpointIds=[model["Id"]]
)

if not response["VpcEndpoints"] or response["VpcEndpoints"][0]["State"] == "deleted":
return ProgressEvent(status=OperationStatus.SUCCESS, resource_model=model)
if not response["VpcEndpoints"]:
return ProgressEvent(
status=OperationStatus.FAILED,
resource_model=model,
message="Resource not found for deletion",
)

request.aws_client_factory.ec2.delete_vpc_endpoints(VpcEndpointIds=[model["Id"]])
return ProgressEvent(status=OperationStatus.IN_PROGRESS, resource_model=model)
state = response["VpcEndpoints"][0]["State"].lower()
match state:
case "deleted":
return ProgressEvent(status=OperationStatus.SUCCESS, resource_model=model)
case "deleting":
return ProgressEvent(status=OperationStatus.IN_PROGRESS, resource_model=model)
case _:
request.aws_client_factory.ec2.delete_vpc_endpoints(VpcEndpointIds=[model["Id"]])
return ProgressEvent(status=OperationStatus.IN_PROGRESS, resource_model=model)

def update(
self,
Expand Down

0 comments on commit a550a30

Please sign in to comment.