- result, err := filter.Filter(addr.String())
- if err != nil {
- return nil, fmt.Errorf("Error verifying address %s: %s", addr, err)
- }
-
- // Go through the filter results and it is an error if we find
- // a matching InstanceState, meaning that we would have a collision.
- for _, r := range result {
- if _, ok := r.Value.(*InstanceState); ok {
- return nil, fmt.Errorf(
- "Can't import %s, would collide with an existing resource.\n\n"+
- "Please remove or rename this resource before continuing.",
- addr)
- }
+ existing := state.ResourceInstance(addr)
+ if existing != nil {
+ diags = diags.Append(tfdiags.Sourceless(
+ tfdiags.Error,
+ "Resource already managed by Terraform",
+ fmt.Sprintf("Terraform is already managing a remote object for %s. To import to this address you must first remove the existing object from the state.", addr),
+ ))
+ continue