I am upgrading from terraform v12.xx to v14.xx , count syntax error

I am upgrading from terraform v12.xx to v14.xx.

An error occurs in the existing count syntax, but I don’t know how.

What’s the problem?

// fargate child module - codepipeline.tf

resource "aws_s3_bucket_policy" "codepipeline" {
  count  = var.fargate_use && var.codepipeline_use ? var.vpc[0].owner_id == var.codecommit_account_id ? 0 : 1 : 0
// variable.tf
variable "name" {

variable "service_name" {  

variable "peer_name" {  

variable "peer_owner_id" {
  # type        = bool
  # default     = true

variable "peer_vpc_id" {  

variable "vpc_id" {  

variable tags {

variable "route_table_ids" {  

variable "destination_cidr_blocks" {  

variable peer_use {
  default = false

Hi @oliverpark999,

This message suggests that one of those three input variables in your expression has a value that was derived from a resource attribute that the relevant provider can’t predict during the planning phase, perhaps because the provider detected that it needs to be replaced and so its ID isn’t known yet.

Although you can’t use variables directly with -target, the error message there is still pointing indirectly at a path forward here: look in your parent module to see which resources (if any) contribute to the fargate_use, vpc, and codecommit_account_id variable values inside the module block, and try running terrafor plan with a -target option for each of them to tell Terraform to focus only on planning those.

For example, you might see that vpc is defined by assigning the value of a resource, like this:

module "example" {
  # ...

  vpc = aws_vpc.example

In that case, you could run terraform plan -target=aws_vpc.example to tell Terraform to plan changes only for that resource and other resources it depends on. Because this count depends on all three of those variables you’ll need to include the resources for all three in multiple -target options in order to get the full effect, but once you do Terraform should be able to show you a plan for that subset of resources, and it’ll probably reveal that at least one of them “must be replaced” (to use the plan output terminology).

What to do next then will depend on what you learn from that plan. If the object is being replaced unnecessarily due to some configuration changes you made as part of the upgrade then you can hopefully adjust the configuration some more to make it match the old values, and thus avoid the need to replace the object. If you do see a plan and you’re not sure how to interpret it, please share the full plan here and I will do my best to help with interpreting it.