{"id":1478,"date":"2023-04-22T12:02:29","date_gmt":"2023-04-22T17:02:29","guid":{"rendered":"https:\/\/cloudlearning365.com\/?p=1478"},"modified":"2023-04-28T15:59:31","modified_gmt":"2023-04-28T20:59:31","slug":"import-existing-resources-into-cloudformation-template","status":"publish","type":"post","link":"https:\/\/cloudlearning365.com\/?p=1478","title":{"rendered":"Import existing resources into CloudFormation template"},"content":{"rendered":"\n<p>Aviatrix developed <a href=\"https:\/\/pypi.org\/project\/aviatrix-migration\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Migration Toolkit<\/a> to help customer migrate from existing AWS\/ Azure environment to Aviatrix Transit and Spoke Multi-Cloud Networking Architecture (MCNA). I have discussed the process in blog: <a href=\"https:\/\/cloudlearning365.com\/?p=1102\" target=\"_blank\" rel=\"noopener\" title=\"\">Migrate from Azure vNet hub and spoke architecture to Aviatrix Transit<\/a>. The AWS migration process is similar, where the toolkit make copies of existing route tables, when Aviatrix Spoke is attached to Aviatrix Transit, we are using these copied route tables, hence no traffic interruption would happen. During the traffic switching phrase, subnets will be associated with the copied route table, and in TGW we disable the migrating VPC router advertisement, so the traffic would swing over to Aviatrix Spoke\/Transit.<\/p>\n\n\n\n<p>Some of our customers are using CloudFormation to manage the deployment of their environment, while Aviatrix Controller will handle bulk of the work such as populating RFC1918 and\/or default route in the route table and\/or non-RFC1918 routes from External connections, they still would like to have the ability to continue to use CloudFormation to manage endpoint routes. This created a split brain scenario, how do we handle this?<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>If you are familiar with Terraform, you would understand anything declared in .tf file is called desired state, when you run terraform apply and found current state in the cloud isn&#8217;t matching the desired state, terraform will try to correct current state to match desired state declared. If things are not declared in the terraform file, terraform will not manage these and will not make corrections. The same concept applies to CloudFormation template.<\/p>\n\n\n\n<p>For example, let&#8217;s use following CloudFormation template create a VPC. The VPC have one public subnet and one private subnet, where the public subnet route table has 0.0.0.0\/0 point to internet gateway.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Resources:\n  MyVPC:\n    Type: AWS::EC2::VPC\n    Properties:\n      CidrBlock: \"10.0.0.0\/16\"\n      Tags:\n        - Key: Name\n          Value: my-vpc\n\n  PublicSubnet:\n    Type: AWS::EC2::Subnet\n    Properties:\n      VpcId: !Ref MyVPC\n      CidrBlock: \"10.0.1.0\/24\"\n      AvailabilityZone:\n        Fn::Select: \n        - 0\n        - Fn::GetAZs: \"\"\n      Tags:\n        - Key: Name\n          Value: public-subnet\n\n  PrivateSubnet:\n    Type: AWS::EC2::Subnet\n    Properties:\n      VpcId: !Ref MyVPC\n      CidrBlock: \"10.0.2.0\/24\"\n      AvailabilityZone: \n        Fn::Select: \n        - 0\n        - Fn::GetAZs: \"\"\n      Tags:\n        - Key: Name\n          Value: private-subnet\n\n  PublicRouteTable:\n    Type: AWS::EC2::RouteTable\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: public-route-table\n\n  PrivateRouteTable:\n    Type: AWS::EC2::RouteTable\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: private-route-table\n\n  InternetGateway:\n    Type: AWS::EC2::InternetGateway\n    Properties:\n      Tags:\n        - Key: Name\n          Value: my-igw\n\n  GatewayAttachment:\n    Type: AWS::EC2::VPCGatewayAttachment\n    Properties:\n      VpcId: !Ref MyVPC\n      InternetGatewayId: !Ref InternetGateway\n\n  PublicRoute:\n    Type: AWS::EC2::Route\n    DependsOn: GatewayAttachment\n    Properties:\n      RouteTableId: !Ref PublicRouteTable\n      DestinationCidrBlock: \"0.0.0.0\/0\"\n      GatewayId: !Ref InternetGateway\n\n  PublicSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    Properties:\n      SubnetId: !Ref PublicSubnet\n      RouteTableId: !Ref PublicRouteTable\n\n  PrivateSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    Properties:\n      SubnetId: !Ref PrivateSubnet\n      RouteTableId: !Ref PrivateRouteTable\n<\/code><\/pre>\n\n\n\n<p>Public Route table shown in AWS Console<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"505\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-1024x505.png\" alt=\"\" class=\"wp-image-1479\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-1024x505.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-300x148.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-768x379.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-1536x757.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72-500x246.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-72.png 1765w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Explore resources created by the CloudFormation template:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-1024x492.png\" alt=\"\" class=\"wp-image-1482\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-1024x492.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-300x144.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-768x369.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-1536x738.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75-500x240.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-75.png 2028w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Assume we created another public route table in AWS Console, simulating the copied route table via Aviatrix Migration Toolkit<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"764\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73-1024x764.png\" alt=\"\" class=\"wp-image-1480\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73-1024x764.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73-300x224.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73-768x573.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73-402x300.png 402w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-73.png 1136w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Assume we create a default route in new-public-route-table point to IGW in AWS Console<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"336\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-1024x336.png\" alt=\"\" class=\"wp-image-1481\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-1024x336.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-300x99.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-768x252.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-1536x505.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74-500x164.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-74.png 1656w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s see how we import the new-public-route-table<\/p>\n\n\n\n<p>For import to work, all resources in the CloudFormation template must have <a href=\"https:\/\/docs.aws.amazon.com\/AWSCloudFormation\/latest\/UserGuide\/aws-attribute-deletionpolicy.html\" target=\"_blank\" rel=\"noopener\" title=\"\">DeletionPolicy <\/a>set.<\/p>\n\n\n\n<p>First add following resource declaration into existing CloudFormation template, this is to tell CloudFormation to manage a new route table of a Logic Resource ID of NewPublicRouteTable<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  NewPublicRouteTable:\n    Type: AWS::EC2::RouteTable\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: new-public-route-table<\/code><\/pre>\n\n\n\n<p>The new-public-route-table has a unique Resource Identifier of: rtb-0ebd453646fdff442<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"55\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-76.png\" alt=\"\" class=\"wp-image-1483\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-76.png 694w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-76-300x24.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-76-500x40.png 500w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p>We need to tell CloudFormation how to link the Logical Resource ID and the unique Resource Identifier, by creating a json file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n  {\n      \"ResourceType\":\"AWS::EC2::RouteTable\",\n      \"LogicalResourceId\":\"NewPublicRouteTable\",\n      \"ResourceIdentifier\": {\n        \"RouteTableId\":\"rtb-0ebd453646fdff442\"\n      }\n  }\n]<\/code><\/pre>\n\n\n\n<p>The structure of the json file is described in <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/reference\/cloudformation\/create-change-set.html\" title=\"\">this article<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n  {\n    \"ResourceType\": \"string\",\n    \"LogicalResourceId\": \"string\",\n    \"ResourceIdentifier\": {\"string\": \"string\"\n      ...}\n  }\n  ...\n]<\/code><\/pre>\n\n\n\n<p>To get the format of ResourceType, LogicalResourceId and ResourceIdentifier, run following command, note the highlighted section.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws cloudformation get-template-summary --stack-name myvpc\n\n{\n    \"Parameters\": &#91;],\n    \"ResourceTypes\": &#91;\n        \"AWS::EC2::InternetGateway\",\n        \"AWS::EC2::VPC\",\n        \"AWS::EC2::RouteTable\",\n        \"AWS::EC2::RouteTable\",\n        \"AWS::EC2::VPCGatewayAttachment\",\n        \"AWS::EC2::Subnet\",\n        \"AWS::EC2::RouteTable\",\n        \"AWS::EC2::Subnet\",\n        \"AWS::EC2::Route\",\n        \"AWS::EC2::SubnetRouteTableAssociation\",\n        \"AWS::EC2::Route\",\n        \"AWS::EC2::SubnetRouteTableAssociation\"\n    ],\n    \"Version\": \"2010-09-09\",\n    \"ResourceIdentifierSummaries\": &#91;\n        {\n            \"ResourceType\": \"AWS::EC2::VPC\",\n            \"LogicalResourceIds\": &#91;\n                \"MyVPC\"\n            ],\n            \"ResourceIdentifiers\": &#91;\n                \"VpcId\"\n            ]\n        },\n        <mark style=\"background-color:#e2e2e2\" class=\"has-inline-color\">{\n            \"ResourceType\": \"AWS::EC2::RouteTable\",\n            \"LogicalResourceIds\": &#91;\n                \"PublicRouteTable\",\n                \"PrivateRouteTable\",\n                \"NewPublicRouteTable\"\n            ],\n            \"ResourceIdentifiers\": &#91;\n                \"RouteTableId\"\n            ]\n        },<\/mark>\n        {\n            \"ResourceType\": \"AWS::EC2::SubnetRouteTableAssociation\",\n            \"LogicalResourceIds\": &#91;\n                \"PrivateSubnetRouteTableAssociation\",\n                \"PublicSubnetRouteTableAssociation\"\n            ],\n            \"ResourceIdentifiers\": &#91;\n                \"Id\"\n            ]\n        },\n        {\n            \"ResourceType\": \"AWS::EC2::InternetGateway\",\n            \"LogicalResourceIds\": &#91;\n                \"InternetGateway\"\n            ],\n            \"ResourceIdentifiers\": &#91;\n                \"InternetGatewayId\"\n            ]\n        },\n        {\n            \"ResourceType\": \"AWS::EC2::Subnet\",\n            \"LogicalResourceIds\": &#91;\n                \"PrivateSubnet\",\n                \"PublicSubnet\"\n            ],\n            \"ResourceIdentifiers\": &#91;\n                \"SubnetId\"\n            ]\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>The new template would looks like this now:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Resources:\n  MyVPC:\n    Type: AWS::EC2::VPC\n    DeletionPolicy: Delete\n    Properties:\n      CidrBlock: \"10.0.0.0\/16\"\n      Tags:\n        - Key: Name\n          Value: my-vpc\n\n  PublicSubnet:\n    Type: AWS::EC2::Subnet\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      CidrBlock: \"10.0.1.0\/24\"\n      AvailabilityZone:\n        Fn::Select: \n        - 0\n        - Fn::GetAZs: \"\"\n      Tags:\n        - Key: Name\n          Value: public-subnet\n\n  PrivateSubnet:\n    Type: AWS::EC2::Subnet\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      CidrBlock: \"10.0.2.0\/24\"\n      AvailabilityZone: \n        Fn::Select: \n        - 0\n        - Fn::GetAZs: \"\"\n      Tags:\n        - Key: Name\n          Value: private-subnet\n\n  PublicRouteTable:\n    Type: AWS::EC2::RouteTable\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: public-route-table\n\n  PrivateRouteTable:\n    Type: AWS::EC2::RouteTable\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: private-route-table\n\n  InternetGateway:\n    Type: AWS::EC2::InternetGateway\n    DeletionPolicy: Delete\n    Properties:\n      Tags:\n        - Key: Name\n          Value: my-igw\n\n  GatewayAttachment:\n    Type: AWS::EC2::VPCGatewayAttachment\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      InternetGatewayId: !Ref InternetGateway\n\n  PublicRoute:\n    Type: AWS::EC2::Route\n    DeletionPolicy: Delete\n    DependsOn: GatewayAttachment\n    Properties:\n      RouteTableId: !Ref PublicRouteTable\n      DestinationCidrBlock: \"0.0.0.0\/0\"\n      GatewayId: !Ref InternetGateway\n\n  PublicSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    DeletionPolicy: Delete\n    Properties:\n      SubnetId: !Ref PublicSubnet\n      RouteTableId: !Ref PublicRouteTable\n\n  PrivateSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    DeletionPolicy: Delete\n    Properties:\n      SubnetId: !Ref PrivateSubnet\n      RouteTableId: !Ref PrivateRouteTable\n\n  NewPublicRouteTable:\n    Type: AWS::EC2::RouteTable\n    DeletionPolicy: Delete\n    Properties:\n      VpcId: !Ref MyVPC\n      Tags:\n        - Key: Name\n          Value: new-public-route-table<\/code><\/pre>\n\n\n\n<p>Upload both modified template and the json file to CloudShell<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-1024x458.png\" alt=\"\" class=\"wp-image-1484\" width=\"614\" height=\"274\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-1024x458.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-300x134.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-768x343.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-1536x687.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77-500x224.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-77.png 1675w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/figure>\n\n\n\n<p>Run following command for the change set<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws cloudformation create-change-set --stack-name myvpc --change-set-name ImportChangeSet --change-set-type IMPORT --resources-to-import file:\/\/import.json --template-body file:\/\/vpc.yaml<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"136\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-1024x136.png\" alt=\"\" class=\"wp-image-1486\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-1024x136.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-300x40.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-768x102.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-1536x204.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-2048x272.png 2048w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-78-500x66.png 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Validate change set in AWS Console, then Execute change set<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"394\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-1024x394.png\" alt=\"\" class=\"wp-image-1487\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-1024x394.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-300x115.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-768x295.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-1536x590.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79-500x192.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-79.png 1556w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Upon completion, validate Resources under stack and find the route table is now been managed<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"591\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-1024x591.png\" alt=\"\" class=\"wp-image-1488\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-1024x591.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-300x173.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-768x443.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-1536x887.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80-500x289.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-80.png 2009w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This is great, then how about import the routes? In above screenshot, we can see that the PublicRoute have a physical id of myvpc-Publi-1O66C3YL5SCJE<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-1024x585.png\" alt=\"\" class=\"wp-image-1490\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-1024x585.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-300x171.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-768x439.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-1536x877.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81-500x286.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-81.png 1961w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>It can be obtained via cloudformation cli:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;cloudshell-user@ip-10-4-89-56 ~]$ aws cloudformation describe-stack-resources --stack-name myvpc --query 'StackResources&#91;?ResourceType==`AWS::EC2::Route`]'\n&#91;\n    {\n        \"StackName\": \"myvpc\",\n        \"StackId\": \"arn:aws:cloudformation:us-east-1:&lt;account-id&gt;:stack\/myvpc\/99dde040-e06f-11ed-b816-12c48b848691\",\n        \"LogicalResourceId\": \"PublicRoute\",\n        \"PhysicalResourceId\": \"myvpc-Publi-1O66C3YL5SCJE\",\n        \"ResourceType\": \"AWS::EC2::Route\",\n        \"Timestamp\": \"2023-04-21T18:10:02.288000+00:00\",\n        \"ResourceStatus\": \"CREATE_COMPLETE\",\n        \"DriftInformation\": {\n            \"StackResourceDriftStatus\": \"NOT_CHECKED\"\n        }\n    }\n]<\/code><\/pre>\n\n\n\n<p>But it appears to be impossible to obtain this physical ID for a route created outside of CloudFormation, as each route doesn&#8217;t really have a unique ID:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;cloudshell-user@ip-10-4-89-56 ~]$ aws ec2 describe-route-tables --route-table-id rtb-0bfc1da00ea922888\n{\n    \"RouteTables\": &#91;\n        {\n            \"Associations\": &#91;\n                {\n                    \"Main\": false,\n                    \"RouteTableAssociationId\": \"rtbassoc-002eb5d86d30c4067\",\n                    \"RouteTableId\": \"rtb-0bfc1da00ea922888\",\n                    \"SubnetId\": \"subnet-0a792e7973a2fbad7\",\n                    \"AssociationState\": {\n                        \"State\": \"associated\"\n                    }\n                }\n            ],\n            \"PropagatingVgws\": &#91;],\n            \"RouteTableId\": \"rtb-0bfc1da00ea922888\",\n<mark style=\"background-color:#e2e2e2\" class=\"has-inline-color\">            \"Routes\": &#91;\n                {\n                    \"DestinationCidrBlock\": \"10.0.0.0\/16\",\n                    \"GatewayId\": \"local\",\n                    \"Origin\": \"CreateRouteTable\",\n                    \"State\": \"active\"\n                },\n                {\n                    \"DestinationCidrBlock\": \"0.0.0.0\/0\",\n                    \"GatewayId\": \"igw-082f5b8803aa503e2\",\n                    \"Origin\": \"CreateRoute\",\n                    \"State\": \"active\"\n                }\n            ],<\/mark>\n            \"Tags\": &#91;\n                {\n                    \"Key\": \"aws:cloudformation:logical-id\",\n                    \"Value\": \"PublicRouteTable\"\n                },\n                {\n                    \"Key\": \"Name\",\n                    \"Value\": \"public-route-table\"\n                },\n                {\n                    \"Key\": \"aws:cloudformation:stack-id\",\n                    \"Value\": \"arn:aws:cloudformation:us-east-1:&lt;account-id&gt;:stack\/myvpc\/99dde040-e06f-11ed-b816-12c48b848691\"\n                },\n                {\n                    \"Key\": \"aws:cloudformation:stack-name\",\n                    \"Value\": \"myvpc\"\n                }\n            ],\n            \"VpcId\": \"vpc-0023fa5f554d32f7c\",\n            \"OwnerId\": \"&lt;account-id&gt;\"\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>Turned out not route cannot be imported<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>An error occurred (ValidationError) when calling the CreateChangeSet operation: ResourceTypes &#91;AWS::EC2::Route] are not supported for Import<\/code><\/pre>\n\n\n\n<p>If tried to append following in the CloudFormation template:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  NewPublicRoute:\n    Type: AWS::EC2::Route\n    DependsOn: GatewayAttachment\n    Properties:\n      RouteTableId: !Ref NewPublicRouteTable1\n      DestinationCidrBlock: \"0.0.0.0\/0\"\n      GatewayId: !Ref InternetGateway<\/code><\/pre>\n\n\n\n<p>Run stack update, and it will fail as the default route already exist<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"497\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-1024x497.png\" alt=\"\" class=\"wp-image-1491\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-1024x497.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-300x145.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-768x372.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-1536x745.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82-500x242.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-82.png 1794w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Based on above testing, Customer need to perform the task of make copy of the route table, then Aviatrix would utilize the copied route table for traffic switching.<\/p>\n\n\n\n<p>Once the traffic switch is completed, the copied route table would be associated with the subnet, need to be able to update the CloudFormation to reflect this association change.<\/p>\n\n\n\n<p>Edit public subnet association in AWS Console<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"275\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83-1024x275.png\" alt=\"\" class=\"wp-image-1493\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83-1024x275.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83-300x81.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83-768x206.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83-500x134.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-83.png 1478w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Switch from public-route-table to new-public-route-table1<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"473\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84-1024x473.png\" alt=\"\" class=\"wp-image-1494\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84-1024x473.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84-300x138.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84-768x355.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84-500x231.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-84.png 1055w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Update CloudFormation template, from:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  PublicSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    DeletionPolicy: Delete\n    Properties:\n      SubnetId: !Ref PublicSubnet\n      RouteTableId: !Ref <mark style=\"background-color:#e2e2e2\" class=\"has-inline-color\">PublicRouteTable<\/mark><\/code><\/pre>\n\n\n\n<p>To: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  PublicSubnetRouteTableAssociation:\n    Type: AWS::EC2::SubnetRouteTableAssociation\n    DeletionPolicy: Delete\n    Properties:\n      SubnetId: !Ref PublicSubnet\n      RouteTableId: !Ref <mark style=\"background-color:#e2e2e2\" class=\"has-inline-color\">NewPublicRouteTable<\/mark><\/code><\/pre>\n\n\n\n<p>Stack -&gt; Update and replace current template:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-1024x344.png\" alt=\"\" class=\"wp-image-1498\" width=\"614\" height=\"206\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-1024x344.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-300x101.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-768x258.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-1536x516.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-2048x688.png 2048w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-87-500x168.png 500w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"312\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-1024x312.png\" alt=\"\" class=\"wp-image-1500\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-1024x312.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-300x91.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-768x234.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-1536x468.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-2048x624.png 2048w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-89-500x152.png 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Note: If selected preserve successfully provisioned resources in Stack failure options<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"197\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-1024x197.png\" alt=\"\" class=\"wp-image-1499\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-1024x197.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-300x58.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-768x148.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-1536x296.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88-500x96.png 500w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-88.png 1842w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The update would fail, as it was trying to replace the deployed association<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"215\" src=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-1024x215.png\" alt=\"\" class=\"wp-image-1501\" srcset=\"https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-1024x215.png 1024w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-300x63.png 300w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-768x161.png 768w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-1536x322.png 1536w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-2048x430.png 2048w, https:\/\/cloudlearning365.com\/wp-content\/uploads\/2023\/04\/image-90-500x105.png 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Aviatrix developed Migration Toolkit to help customer migrate from existing AWS\/ Azure environment to Aviatrix Transit and Spoke Multi-Cloud Networking Architecture (MCNA). I have discussed the process in blog: Migrate from Azure vNet hub and spoke architecture to Aviatrix Transit. &hellip; <a href=\"https:\/\/cloudlearning365.com\/?p=1478\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1478","post","type-post","status-publish","format-standard","hentry","category-aws"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/posts\/1478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1478"}],"version-history":[{"count":9,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/posts\/1478\/revisions"}],"predecessor-version":[{"id":1520,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=\/wp\/v2\/posts\/1478\/revisions\/1520"}],"wp:attachment":[{"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudlearning365.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}