Using data source in conditional expressions

I want to be able to choose route tables from either the vpc or subnets depending on input. Im using datasources to get the information, but it is not working. The temporary storing as a local is just empty when reading from vpc data… (but not from subnet data…)

I uploaded relevant code ( a test module and an example file that should be located in a subfolder) for this. But as .tf.txtfiles since apparently only image files and text os allowed… When running the example there is at first a problem with some of the data not populating, but after an extra refresh it at least populates.

The main lines causing issue is this:

vpc_rts_ids       = data.aws_route_tables.vpc_rts.ids
subnet_rts_ids = data.aws_route_table.subnet_rts[*].route_table_id
rts_ids               = var.subnets_ids == [] ? local.vpc_rts_ids : local.subnet_rts_ids

As can be seen when running the uploaded code; rts_ids (LOCAL_RTS_IDS in output) only gets a value when there are subnets given as input (var.subnet_rts_ids)
even though output of vpc_rts_ids shows a value.

Can somebody please explain or maybe confirm that this is due to some bug or something?
I do not understand what is wrong. (1.2 KB) (1.2 KB)