|
8 | 8 | "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" |
9 | 9 | "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" |
10 | 10 | "github.com/elastic/terraform-provider-elasticstack/internal/utils" |
| 11 | + "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" |
11 | 12 | "github.com/hashicorp/terraform-plugin-framework/attr" |
12 | 13 | "github.com/hashicorp/terraform-plugin-framework/diag" |
13 | 14 | "github.com/hashicorp/terraform-plugin-framework/resource" |
@@ -140,24 +141,8 @@ func (r *ExceptionItemResource) Create(ctx context.Context, req resource.CreateR |
140 | 141 | return |
141 | 142 | } |
142 | 143 |
|
143 | | - // Read back the created resource to get computed fields |
144 | | - readParams := &kbapi.ReadExceptionListItemParams{ |
145 | | - Id: (*kbapi.SecurityExceptionsAPIExceptionListItemId)(&createResp.JSON200.Id), |
146 | | - } |
147 | | - |
148 | | - readResp, diags := kibana_oapi.GetExceptionListItem(ctx, client, readParams) |
149 | | - resp.Diagnostics.Append(diags...) |
150 | | - if resp.Diagnostics.HasError() { |
151 | | - return |
152 | | - } |
153 | | - |
154 | | - if readResp == nil || readResp.JSON200 == nil { |
155 | | - resp.Diagnostics.AddError("Failed to read created exception item", "API returned empty response") |
156 | | - return |
157 | | - } |
158 | | - |
159 | | - // Update state with response |
160 | | - diags = r.updateStateFromAPIResponse(ctx, &plan, readResp.JSON200) |
| 144 | + // Update state with create response |
| 145 | + diags = r.updateStateFromAPIResponse(ctx, &plan, createResp.JSON200) |
161 | 146 | resp.Diagnostics.Append(diags...) |
162 | 147 | if resp.Diagnostics.HasError() { |
163 | 148 | return |
@@ -224,13 +209,13 @@ func (r *ExceptionItemResource) updateStateFromAPIResponse(ctx context.Context, |
224 | 209 | model.Meta = types.StringNull() |
225 | 210 | } |
226 | 211 |
|
227 | | - // Set entries (convert back to JSON) |
| 212 | + // Set entries (convert back to JSON and normalize) |
228 | 213 | entriesJSON, err := json.Marshal(apiResp.Entries) |
229 | 214 | if err != nil { |
230 | 215 | diags.AddError("Failed to serialize entries", err.Error()) |
231 | 216 | return diags |
232 | 217 | } |
233 | | - model.Entries = types.StringValue(string(entriesJSON)) |
| 218 | + model.Entries = jsontypes.NewNormalizedValue(string(entriesJSON)) |
234 | 219 |
|
235 | 220 | // Set optional comments |
236 | 221 | if len(apiResp.Comments) > 0 { |
|
0 commit comments