core: Update error message for non-existing "terraform import"
The previous wording of this message was a little awkward, and a little confusing due to the mention of it being a non-existing "resource", when elsewhere in our output we use that noun to refer to the configuration construct rather than the remote object. Here we rework it as a diagnostic message, and while here also include an extra note about a common problem of using an id from a different region than the provider is configured for, to help the user realize what is wrong in that case.
This commit is contained in:
parent
3de6a3db82
commit
7f3d7313d8
|
@ -190,6 +190,12 @@ func TestContextImport_missingType(t *testing.T) {
|
||||||
|
|
||||||
func TestContextImport_moduleProvider(t *testing.T) {
|
func TestContextImport_moduleProvider(t *testing.T) {
|
||||||
p := mockProviderWithResourceTypeSchema("aws_instance", &configschema.Block{})
|
p := mockProviderWithResourceTypeSchema("aws_instance", &configschema.Block{})
|
||||||
|
p.GetSchemaReturn.Provider = &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {Type: cty.String, Optional: true},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "import-provider")
|
m := testModule(t, "import-provider")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
"github.com/hashicorp/terraform/addrs"
|
||||||
|
"github.com/hashicorp/terraform/tfdiags"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EvalImportState is an EvalNode implementation that performs an
|
// EvalImportState is an EvalNode implementation that performs an
|
||||||
|
@ -64,15 +65,19 @@ type EvalImportStateVerify struct {
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
func (n *EvalImportStateVerify) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalImportStateVerify) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
state := *n.State
|
state := *n.State
|
||||||
if state.Empty() {
|
if state.Empty() {
|
||||||
return nil, fmt.Errorf(
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
"import %s (id: %s): Terraform detected a resource with this ID doesn't\n"+
|
tfdiags.Error,
|
||||||
"exist. Please verify the ID is correct. You cannot import non-existent\n"+
|
"Cannot import non-existent remote object",
|
||||||
"resources using Terraform import.",
|
fmt.Sprintf(
|
||||||
n.Addr.String(),
|
"While attempting to import an existing object to %s, the provider detected that no object exists with the id %q. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use \"terraform apply\" to create a new remote object for this resource.",
|
||||||
n.Id)
|
n.Addr.String(), n.Id,
|
||||||
|
),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, diags.ErrWithWarnings()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue