I have written a module which traverses through an array of entries and created multiple vpc/tgw route tables etc. This module works great. I now have a need to add a direct connect route table/routes when this module is being called.
These resources have been created by hand and I would like to import them into my terraform state and when I do it it seems to work fine without any issues, but the next time I do a terraform plan it still shows up as a new resource to create rather than showing the existing stuff.
terraform import ‘my_module[“somestring”].aws_ec2_transit_gateway_route_table.morecrap-rt’ ‘tgw-xxxxxxxx’
The above command runs to success and terraform says these resources are now managed inside terraform.
I further did a
terraform state | egrep tgw-xxxxxxxx
When I tried, terraform says oh let me create this new route table once again.
terraform plan --var-file=<some var file>
What am I missing here?
What is the full plan output?
It goes through everything and finally tells me I am going to “add” this new tg_route_table rather than telling me there are no chances.
When I further let it move on rather cancel it, it creates this extra route table rather than adopting the existing one that is already created. Mind you this is not a big deal, I can delete the manually created and create it through terraform, but I do want to understand what I am doing wrong here.
Did you import that route table?
I tried to import the route-table with the logical name “morecrap-rt’”, terraform runs the import job to success, but in reality it is not present in the state file at all.
So why I apply the next time, it creates a route table with the logical name(inside tf) “morecrap-rt” but the existing route table that was created in the AWS console is still there.
May be I am not being clear here with my explanation.
If the plan requires
-var-file to correctly set variables in the configuration to plan the resource you want to import, then the
import command likely requires the same
-var-file. Does importing work if you supply the same variable inputs?
That was my mistake, I should have imported things in with the
Thanks for pointing out my mistake.
This really helps me out.