Attaching S3 endpoint to multiple routing tables

203 views
Skip to first unread message

Andrew Hodgson

unread,
Apr 25, 2016, 11:43:29 AM4/25/16
to terrafo...@googlegroups.com
Hi,

I am defining a few routing tables like so:

variable "nat_count" {
default= 2
}

resource "aws_route_table" "public" {
count = "${var.nat_count}"
vpc_id = "${aws_vpc.vpc.id}"
}

resource "aws_route_table" "private" {
count = "${var.nat_count}"
vpc_id = "${aws_vpc.vpc.id}"
}


I now want to create an S3 endpoint for the VPC and assign it to the 4 custom routing tables I have created:

resource "aws_vpc_endpoint" "s3" {
vpc_id = "${aws_vpc.vpc.id}"
service_name = "com.amazonaws.eu-west-1.s3"
route_table_ids = ["${element(aws_route_table.private.*.id, var.nat_count.index)}", "${element(aws_route_table.public.*.id, var.nat_count.index)}"]
}

This is giving me an error that the variable var.nat_count.index is unknown. What is the best way of associating this S3 endpoint with the 4 routing tables created earlier?

Thanks.
Andrew.

Igor Cicimov

unread,
Apr 26, 2016, 4:44:24 AM4/26/16
to Terraform
On Tuesday, April 26, 2016 at 1:43:29 AM UTC+10, Andrew Hodgson wrote:
> Hi,
>
> I am defining a few routing tables like so:
>
> variable "nat_count" {
> default= 2
> }
>
> resource "aws_route_table" "public" {
> count = "${var.nat_count}"
> vpc_id = "${aws_vpc.vpc.id}"
> }
>
> resource "aws_route_table" "private" {
> count = "${var.nat_count}"
> vpc_id = "${aws_vpc.vpc.id}"
> }
>
>
> I now want to create an S3 endpoint for the VPC and assign it to the 4 custom routing tables I have created:
>
> resource "aws_vpc_endpoint" "s3" {
> vpc_id = "${aws_vpc.vpc.id}"
> service_name = "com.amazonaws.eu-west-1.s3"
> route_table_ids = ["${element(aws_route_table.private.*.id, var.nat_count.index)}", "${element(aws_route_table.public.*.id, var.nat_count.index)}"]
> }
You are missing count = "${var.nat_count}" here

Andrew Hodgson

unread,
Apr 26, 2016, 12:34:47 PM4/26/16
to terrafo...@googlegroups.com
Igor Cicimov wrote:

>On Tuesday, April 26, 2016 at 1:43:29 AM UTC+10, Andrew Hodgson wrote:
>> Hi,
>>
>> I am defining a few routing tables like so:
>>
>> variable "nat_count" {
>> default= 2
>> }
>>
>> resource "aws_route_table" "public" {
>> count = "${var.nat_count}"
>> vpc_id = "${aws_vpc.vpc.id}"
>> }
>>
>> resource "aws_route_table" "private" {
>> count = "${var.nat_count}"
>> vpc_id = "${aws_vpc.vpc.id}"
>> }
>>
>>
>> I now want to create an S3 endpoint for the VPC and assign it to the 4 custom routing tables I have created:
>>
>> resource "aws_vpc_endpoint" "s3" {
>> vpc_id = "${aws_vpc.vpc.id}"
>> service_name = "com.amazonaws.eu-west-1.s3"
>> route_table_ids = ["${element(aws_route_table.private.*.id,
>> var.nat_count.index)}", "${element(aws_route_table.public.*.id,
>> var.nat_count.index)}"] }
>You are missing count = "${var.nat_count}" here

Thanks for that. I did that this morning, it works fine but gives me an extra S3 endpoint. I wanted to get the single S3 endpoint associated with the 4 route tables, but am happy to live with things as they are now.

Best,
Andrew.
Reply all
Reply to author
Forward
0 new messages