Terraform resouce aws_vpc_endpoint constantly asking for replacing because vpc_id change which is not the case

Hi,all!
Trying to understand strange behavior of aws_vpc_endpoint constantly asking for replacing because vpc_id change which is not the case.
i am creating an endpoint like this :

resource “aws_vpc_endpoint” “transfer_vpc_endpoint” {
vpc_id = data.aws_vpc.ingress_vpc.id
service_name = “com.amazonaws.region.transfer.server”
vpc_endpoint_type = “Interface”
security_group_ids = [
aws_security_group.transfer_vpc_endpoint_sg.id
]
subnet_ids = data.aws_subnets.ingressinfra_subnets.ids
tags = {
Name = “aws-env-short_region-vpc_id-z-vpce-shrdsvcs-sftp-z”
}
}

and very often when i execute the code is it saying
module.transfer_family.aws_vpc_endpoint.transfer_vpc_endpoint must be replaced
~ vpc_id = “vpc-0a3cc268ae5f122dc” # forces replacement → (known after apply) # forces replacement

issues is because for vpc_id we are using data resource but what we can do to overcome it?

data “aws_vpc” “ingress_vpc” {
filter {
name = “tag:Name”
values = [“aws-env-short_region-z-z-vpc-shrdsvcs-ingress-z”]
}
}

Thanks in advance,
Vladimir

Hi @tahchiev,

You have something in your configuration which is preventing the data source from being read. Since the data source configuration block has no references, and does not use depends_on, I would guess that the containing module is declaring the dependencies using depends_on. If a data source depends on any changes, it cannot be read until those changes have ben applied, so you need to remove the depends_on from the module and use more specific dependencies. (There is never a reason that depends_on is required for a module, and it’s usually a mistake to use it there).

Thanks, you are right . All these code is in a module which depends on other module. so i will remove dependency and make it in another way passing variable. Let me test.