hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.84k stars 9.19k forks source link

[Bug]: Unable to destroy appmesh virtual node and update appmesh route in apply #38444

Closed dhrkumar closed 3 months ago

dhrkumar commented 3 months ago

Terraform Core Version

1.9.2

AWS Provider Version

5.59.0

Affected Resource(s)

Expected Behavior

Apply command should have update route to remove virtual node reference followed by destroying virtual node.

Actual Behavior

Terraform attempted to destroy virtual node while route was still having referencing the virtual node as one of the targets.

Relevant Error/Panic Output Snippet

aws_appmesh_virtual_node.node: Destroying... [id=f85c92ea-e5c6-43a7-b137-d62607a7fe39]
╷
│ Error: deleting App Mesh Virtual Node (f85c92ea-e5c6-43a7-b137-d62607a7fe39): ResourceInUseException: VirtualNode with name node cannot be deleted because it is the target of one or more routes.

Terraform Configuration Files

resource "aws_appmesh_mesh" "mesh" {
  name = "mesh"
}

resource "aws_vpc" "vpc" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_support   = true
  enable_dns_hostnames = true
}

resource "aws_service_discovery_private_dns_namespace" "namespace" {
  name        = "example.terraform.local"
  description = "example"
  vpc         = aws_vpc.vpc.id
}

resource "aws_service_discovery_service" "service" {
  name = "service"
  dns_config {
    namespace_id = aws_service_discovery_private_dns_namespace.namespace.id
    dns_records {
      ttl  = 10
      type = "A"
    }
    routing_policy = "MULTIVALUE"
  }
}

resource "aws_appmesh_virtual_node" "node" {
  mesh_name = aws_appmesh_mesh.mesh.name
  name      = "node"
  spec {
    service_discovery {
      aws_cloud_map {
        namespace_name = aws_service_discovery_private_dns_namespace.namespace.name
        service_name   = "service"
      }
    }
    listener {
      port_mapping {
        port     = 80
        protocol = "http"
      }
    }
  }
}

resource "aws_appmesh_virtual_router" "router" {
  mesh_name = aws_appmesh_mesh.mesh.name
  name      = "router"
  spec {
    listener {
      port_mapping {
        port     = 80
        protocol = "http"
      }
    }
  }
}

resource "aws_appmesh_route" "route" {
  mesh_name           = aws_appmesh_mesh.mesh.name
  name                = "route"
  virtual_router_name = aws_appmesh_virtual_router.router.name
  spec {
    priority = 1000
    http_route {
      match {
        prefix = "/"
        port   = 80
      }
      action {
        weighted_target {
          virtual_node = aws_appmesh_virtual_node.node.name
          weight       = 100
          port         = 80
        }
      }
    }
  }
}

Steps to Reproduce

  1. terraform apply
  2. Comment/remove resource aws_appmesh_virtual_node.node and block aws_appmesh_route.route.spec.http_route
    
    resource "aws_appmesh_mesh" "mesh" {
    name = "mesh"
    }

resource "aws_vpc" "vpc" { cidr_block = "10.0.0.0/16" enable_dns_support = true enable_dns_hostnames = true }

resource "aws_service_discovery_private_dns_namespace" "namespace" { name = "example.terraform.local" description = "example" vpc = aws_vpc.vpc.id }

resource "aws_service_discovery_service" "service" { name = "service" dns_config { namespace_id = aws_service_discovery_private_dns_namespace.namespace.id dns_records { ttl = 10 type = "A" } routing_policy = "MULTIVALUE" } }

resource "aws_appmesh_virtual_node" "node" {

mesh_name = aws_appmesh_mesh.mesh.name

name = "node"

spec {

service_discovery {

aws_cloud_map {

namespace_name = aws_service_discovery_private_dns_namespace.namespace.name

service_name = "service"

}

}

listener {

port_mapping {

port = 80

protocol = "http"

}

}

}

}

resource "aws_appmesh_virtual_router" "router" { mesh_name = aws_appmesh_mesh.mesh.name name = "router" spec { listener { port_mapping { port = 80 protocol = "http" } } } }

resource "aws_appmesh_route" "route" { mesh_name = aws_appmesh_mesh.mesh.name name = "route" virtual_router_name = aws_appmesh_virtual_router.router.name spec { priority = 1000

http_route {

match {

prefix = "/"

port = 80

}

action {

weighted_target {

virtual_node = aws_appmesh_virtual_node.node.name

weight = 100

port = 80

}

}

}

} }


3. `terraform apply`

### Debug Output

_No response_

### Panic Output

_No response_

### Important Factoids

_No response_

### References

_No response_

### Would you like to implement a fix?

None
github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 3 months ago

Hey @dhrkumar 👋 Thank you for taking the time to raise this! Terraform Core builds the resource graph and determines the order of operations. With that in mind, you'll want to open an issue in the Terraform Core repository in order to have this properly addressed.

Since there's no action for the AWS Provider team to take on this particular issue, I'm going to close it, but if you do experience unexpected behavior with the provider in the future, please do let us know!

github-actions[bot] commented 3 months ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 2 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.