Skip to main content
Knowledge Base

Template_File to templatefile migration

Answer

I'm upgrading our usage of `template_file` (deprecated) to `templatefile` and I could use a little help with the following: ```data "template_file" "vpn_routes" { count = length(data.template_file.all_vpc_cidr_blocks.*.rendered) template = "${cidrhost(element(data.template_file.all_vpc_cidr_blocks.*.rendered, count.index), 0)} ${cidrnetmask(element(data.template_file.all_vpc_cidr_blocks.*.rendered, count.index))}" } data "template_file" "all_vpc_cidr_blocks" { count = length(data.terraform_remote_state.other_vpcs.*.vpc_cidr_block) + 1 template = element(concat(data.terraform_remote_state.other_vpcs.*.vpc_cidr_block, list(data.terraform_remote_state.mgmt_vpc.vpc_cidr_block)), count.index) } ``` These aren't standard paths to templates, so I'm not sure how to migrate them.

Since you are using `template_file` as a string template rather than file, the proper replacement here is actually `locals` with plain string interpolation instead of `templatefile`: ``` locals { all_vpc_cidr_blocks = concat([data.terraform_remote_state.mgmt_vpc.vpc_cidr_block], data.terraform_remote_state.other_vpcs.*.vpc_cidr_block) all_vpc_cidr_nets = [ for vpc_cidr in local.all_vpc_cidr_blocks : "${cidrhost(vpc_cidr)} ${cidrnetmask(vpc_cidr)}" ] } ```