Error tagging resources

Hello,

sometimes I am getting issues while tagging resources in terraform in the resource block:

resource "aws_vpc_peering_connection" "src_peering" {
provider = aws.src
peer_owner_id = var.peering.different_account ? var.peering.account_id : null
vpc_id = var.peering.src_vpc_id
peer_vpc_id = var.peering.dst_vpc_id
peer_region   = var.stackCommon.stack_region
auto_accept   = false

tags = merge(
    map(
        "Name", "${var.stackCommon.stack_name}-${var.peering.peering_connection_name}"
    ),
    var.stackCommon.common_tags
)

lifecycle {
    create_before_destroy = true
}

Error:

    error updating EC2 VPC Peering Connection (pcx-002e3d030ff430f7c) tags: error tagging resource (pcx-002e3d030ff430f7c): InvalidVpcPeeringConnectionID.NotFound: The vpcPeeringConnection ID 'pcx-002e3d030ff430f7c' does not exist
	status code: 400, request id: 0ade2c59-4cea-4ec9-bcef-ba1a480a41ec

Tagging fails not only for peering but often for Security groups, EIP’s with the same kind of error. Dependencies are OK. Am I doing this wrong? 95% of the time it works properly.

Encountered the same issue. If this occurs, it’s usually the tagging of TargetGroups that makes a problem.

The whole TF code worked pretty well for quite some time but recently the issue appears more often. I updated to the most recent Terraform binaries and AWS provider version…without difference.

The behavior unfortunately isn’t reliably reproducible.

Some idea would be appreciated.