How to use/create an attribute based on condition

Hello,
I am trying to create VPC endpoint.
The Gateway endpoints have an attribute called “route_table_ids”.
Where as the “Interface” endpoints don’t have this attribute.

I tried doing something like this. Check if endpoint is of “Interface” type or “Gateway” type.
If Gateway type then get the route_id else it should be null or it should not be used for “Interface” types. But I am getting error below. Please advise.

route_table_ids = each.value.vpc_endpoint_type == “Gateway” ? aws_vpc.aws_vpc[each.value.vpc_id].default_route_table_id : null


│ **aws_vpc.aws_vpc** is object with 1 attribute "dev_vpc"

│ │ **each.value.vpc_endpoint_type** is "Interface"

│ │ **each.value.vpc_id** is "dev_vpc"

│

│ Inappropriate value for attribute "route_table_ids": set of string required.