@@ -385,33 +385,27 @@ func (r *buildingBlockV2Resource) Create(ctx context.Context, req resource.Creat
385385 )
386386 return
387387 }
388+ resp .Diagnostics .Append (setStateFromResponseV2 (& ctx , & resp .State , created )... )
389+
390+ // ensure that user inputs and wait_for_completion are passed along from the plan
391+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("spec" ).AtName ("inputs" ), plan .Spec .Inputs )... )
392+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("wait_for_completion" ), plan .WaitForCompletion )... )
388393
389394 // Poll for completion if wait_for_completion is true
390395 if ! plan .WaitForCompletion .IsNull () && plan .WaitForCompletion .ValueBool () {
391396 uuid := created .Metadata .Uuid
392397 polled , err := r .client .PollBuildingBlockV2UntilCompletion (ctx , uuid )
393398 if err != nil {
394- // Always store the initial state, even if the building block was created in a failed state
395- // This allows Terraform to track the resource and handle recreates appropriately
396- resp .Diagnostics .Append (setStateFromResponseV2 (& ctx , & resp .State , created )... )
397- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("status" ).AtName ("status" ), client .BUILDING_BLOCK_STATUS_FAILED )... )
398- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("spec" ).AtName ("inputs" ), plan .Spec .Inputs )... )
399- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("wait_for_completion" ), plan .WaitForCompletion )... )
399+ // If building block failed during or after polling, we still want to set the state to the last known state
400+ resp .Diagnostics .Append (setStateFromResponseV2 (& ctx , & resp .State , polled )... )
400401
401402 resp .Diagnostics .AddError (
402403 "Error waiting for building block completion" ,
403404 err .Error (),
404405 )
405406 return
406407 }
407- created = polled
408408 }
409-
410- resp .Diagnostics .Append (setStateFromResponseV2 (& ctx , & resp .State , created )... )
411-
412- // ensure that user inputs and wait_for_completion are passed along from the plan
413- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("spec" ).AtName ("inputs" ), plan .Spec .Inputs )... )
414- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("wait_for_completion" ), plan .WaitForCompletion )... )
415409}
416410
417411func (r * buildingBlockV2Resource ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
0 commit comments