@@ -2,6 +2,8 @@ package import_saved_objects
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "strings"
5
7
6
8
"github.com/google/uuid"
7
9
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -71,7 +73,23 @@ func (r *Resource) importObjects(ctx context.Context, plan tfsdk.Plan, state *tf
71
73
}
72
74
73
75
if ! respModel .Success && ! model .IgnoreImportErrors .ValueBool () {
74
- diags .AddError ("not all objects were imported successfully" , "see errors attribute for more details" )
76
+ var detail strings.Builder
77
+ for i , err := range respModel .Errors {
78
+ detail .WriteString (fmt .Sprintf ("import error [%d]: %s\n " , i , err ))
79
+ }
80
+ detail .WriteString ("see the `errors` attribute for the full resposne" )
81
+
82
+ if respModel .SuccessCount > 0 {
83
+ diags .AddWarning (
84
+ "not all objects were imported successfully" ,
85
+ detail .String (),
86
+ )
87
+ } else {
88
+ diags .AddError (
89
+ "no objects imported successfully" ,
90
+ detail .String (),
91
+ )
92
+ }
75
93
}
76
94
}
77
95
@@ -90,15 +108,24 @@ type importSuccess struct {
90
108
}
91
109
92
110
type importError struct {
93
- ID string `json:"id"`
94
- Type string `json:"type"`
95
- Title string `json:"title"`
96
- Error importErrorType `json:"error"`
97
- Meta importMeta `json:"meta"`
111
+ ID string `tfsdk:"id" json:"id"`
112
+ Type string `tfsdk:"type" json:"type"`
113
+ Title string `tfsdk:"title" json:"title"`
114
+ Error importErrorType `tfsdk:"error" json:"error"`
115
+ Meta importMeta `tfsdk:"meta" json:"meta"`
116
+ }
117
+
118
+ func (ie importError ) String () string {
119
+ title := ie .Title
120
+ if title == "" {
121
+ title = ie .Meta .Title
122
+ }
123
+
124
+ return fmt .Sprintf ("[%s] error on [%s] with ID [%s] and title [%s]" , ie .Error .Type , ie .Type , ie .ID , title )
98
125
}
99
126
100
127
type importErrorType struct {
101
- Type string `json:"type"`
128
+ Type string `tfsdk:"type" json:"type"`
102
129
}
103
130
104
131
type importMeta struct {
0 commit comments