-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
We have two different CF stacks in which we create a VPC and IGW in each of them.
First we deploy the first stack which creates a VPCa, creates a IGW and attaches the IGW to the VPCa.
Now when we create the second stack, in this stack also we create a VPCb, create a IGW and attach to the VPCb.
But when I am creating the second stack I get Internet Gateway already associated error.
The second stack creates a new internet gateway but in the attachment step it uses the gateway created in the previous stack (which causes the already associated error).
This error happens for all the subsequent stacks created after the first stack.
This is the CF snippet
InternetGatewaySvc:
Type: 'AWS::EC2::InternetGateway'
VPCSvcGatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
DependsOn: [InternetGatewaySvc]
Properties:
InternetGatewayId: !GetAtt 'InternetGatewaySvc.InternetGatewayId'
VpcId: !Ref VPCSvc
The !GetAtt 'InternetGatewaySvc.InternetGatewayId' in the above snippet returns the id of the gateway created in the first stack instead of the one created in the second stack. (same happens with !Ref also)
The following error is raised
2023-02-11T20:30:54.321 DEBUG --- [uncthread367] l.s.c.e.template_deployer : Error applying changes for CloudFormation stack "hcservices": An error occurred (Resource.AlreadyAssociated) when calling the AttachInternetGateway operation: Resource igw-4eea8dbb is already associated. Traceback (most recent call last):
File "/opt/code/localstack/localstack/services/cloudformation/engine/template_deployer.py", line 1304, in _run
self.do_apply_changes_in_loop(changes, stack)
File "/opt/code/localstack/localstack/services/cloudformation/engine/template_deployer.py", line 1381, in do_apply_changes_in_loop
self.apply_change(change, stack=stack)
File "/opt/code/localstack/localstack/services/cloudformation/engine/template_deployer.py", line 1461, in apply_change
result = execute_resource_action(resource_id, self, ACTION_CREATE)
File "/opt/code/localstack/localstack/services/cloudformation/engine/template_deployer.py", line 738, in execute_resource_action
result = func["function"](resource_id, resources, resource_type, func, stack_name)
File "/opt/code/localstack/localstack/services/cloudformation/models/ec2.py", line 217, in _attach_gateway
client.attach_internet_gateway(VpcId=vpc_id, InternetGatewayId=igw_id)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 530, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 960, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (Resource.AlreadyAssociated) when calling the AttachInternetGateway operation: Resource igw-4eea8dbb is already associated.
Expected Behavior
No response
How are you starting LocalStack?
With the localstack script
Environment
- OS: MacOS 12 - M1
- LocalStack: 1.3.2.devAnything else?
No response