skip imports for existing resources

pull/33932/head
James Bardin 3 years ago
parent 9b3047368b
commit 5128b21b55

@ -4356,7 +4356,7 @@ import {
t.Errorf("wrong action reason\ngot: %s\nwant: %s", got, want)
}
if instPlan.Importing != nil {
t.Errorf("expected non-import change, got import change %+v", instPlan.Importing)
t.Errorf("expected non-import change, got import change %#v", instPlan.Importing)
}
})
}

@ -5,6 +5,7 @@ package terraform
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/hcl/v2"
@ -384,6 +385,15 @@ func (n nodeExpandPlannableResource) expandResourceImports(ctx EvalContext, addr
}
}
// filter out any import which already exist in state
state := ctx.State()
for _, el := range imports.Elements() {
if state.ResourceInstance(el.Key) != nil {
log.Printf("[DEBUG] import address %s already in state", el.Key)
imports.Remove(el.Key)
}
}
return imports, diags
}

Loading…
Cancel
Save