Import multiple AWS resources using modules

971 views
Skip to first unread message

al...@victorops.com

unread,
Apr 17, 2018, 12:40:21 PM4/17/18
to Terraform
I have three subnets that I would like to import into Terraform using a module I have created. From what I can tell the import command should look like this. 

terraform import module.network.aws_subnet.public_subnet[0] subnet-xxxx

where the module code looks like

resource "aws_subnet" "public_subnet" {
  count                  
= "${length(var.public_subnets)}"
  vpc_id                  
= "${aws_vpc.vpc.id}"
  cidr_block              
= "${lookup(var.public_subnets, element(data.aws_availability_zones.available.names, count.index))}"
  availability_zone      
= "${element(data.aws_availability_zones.available.names, count.index)}"
  map_public_ip_on_launch
= true
}



Terraform comes back with 

no matches found: module.network.aws_subnet.public_subnet[0]

This topic seems to be related but has no answer.

I am wondering if this is even possible at this time?

Thanks,

Alex

David Adams

unread,
Apr 17, 2018, 12:52:26 PM4/17/18
to terrafo...@googlegroups.com
I have successfully imported subnets with exactly that syntax. I can generate lots of different errors related to this pattern, but I can't duplicate any error that says "no matches found". Can you post the actual full output of the import command?

Also, what version of Terraform are you using?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/ca75a33d-c0aa-499e-9a2a-b2bb116c9075%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

al...@victorops.com

unread,
Apr 17, 2018, 2:26:29 PM4/17/18
to Terraform
I am using 

terraform version
Terraform v0.11.5
+ provider.aws v1.14.1

The full output, even with TF_LOG set to trace is

terraform import module.network.aws_subnet.public_subnet[0]subnet-xxxxxx
zsh
: no matches found: module.network.aws_subnet.public_subnet[0]

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

David Adams

unread,
Apr 17, 2018, 3:55:30 PM4/17/18
to terrafo...@googlegroups.com
Ah, sounds like your shell is trying to interpret the `[0]` part as a filename glob and dying before it ever even executes terraform. I'm not very familiar with zsh, but I would try wrapping the resource path in quotes:


    terraform import "module.network.aws_subnet.public_subnet[0]" subnet-xxxxxx

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/6ee39844-6b54-440a-ba02-52a69c9a6f7c%40googlegroups.com.
Message has been deleted

al...@victorops.com

unread,
Apr 17, 2018, 4:47:21 PM4/17/18
to Terraform
Yep, that is totally it. Works now. Thanks for your help David!
Reply all
Reply to author
Forward
0 new messages