0
votes

When instantiating resources (Security Groups, EC2 instances, etc) using a CloudFormation template, one does not always have to specify a VpcId explicitly. When one does not do so, the default VPC for a given account is selected automatically.

Is it possible to designate a different VPC as the default for the purposes of creating a stack, so that this other VPC is used in cases where a VpcId is not specified explicitly?

I am aware of this answer which suggests that one can pass a different VPC explicitly to all resources that require it, but this seems more verbose than necessary if there's a way to tell CloudFormation "Please treat VPC X as the default for all resources".

1

1 Answers

1
votes

Sadly - There is no way to override the defaults in which AWS use through CloudFormation, and I would argue that being explicit when it comes to CloudFormation is a good thing.

However a way you this could be done is to delete the current default VPC and create a new VPC as the new default, with the configuration you want. Doing this requires slightly different creation steps to a standard VPC. Which you can find here : https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html#create-default-vpc

Unfortunately you cannot simply unset the current default and change it to a new existing VPC, it has to be made from scratch, as in the docs it states "If you delete your default VPC, you can create a new one. You cannot restore a previous default VPC that you deleted, and you cannot mark an existing nondefault VPC as a default VPC." .