7 // EvalImportState is an EvalNode implementation that performs an
8 // ImportState operation on a provider. This will return the imported
9 // states but won't modify any actual state.
10 type EvalImportState struct {
11 Provider *ResourceProvider
14 Output *[]*InstanceState
18 func (n *EvalImportState) Eval(ctx EvalContext) (interface{}, error) {
19 provider := *n.Provider
22 // Call pre-import hook
23 err := ctx.Hook(func(h Hook) (HookAction, error) {
24 return h.PreImportState(n.Info, n.Id)
32 state, err := provider.ImportState(n.Info, n.Id)
34 return nil, fmt.Errorf(
35 "import %s (id: %s): %s", n.Info.HumanId(), n.Id, err)
43 // Call post-import hook
44 err := ctx.Hook(func(h Hook) (HookAction, error) {
45 return h.PostImportState(n.Info, state)
55 // EvalImportStateVerify verifies the state after ImportState and
56 // after the refresh to make sure it is non-nil and valid.
57 type EvalImportStateVerify struct {
64 func (n *EvalImportStateVerify) Eval(ctx EvalContext) (interface{}, error) {
67 return nil, fmt.Errorf(
68 "import %s (id: %s): Terraform detected a resource with this ID doesn't\n"+
69 "exist. Please verify the ID is correct. You cannot import non-existent\n"+
70 "resources using Terraform import.",