@@ -360,6 +360,9 @@ func resourceEnvironment() *schema.Resource {
360360 Computed : true ,
361361 },
362362 },
363+ Importer : & schema.ResourceImporter {
364+ StateContext : schema .ImportStatePassthroughContext ,
365+ },
363366 }
364367}
365368
@@ -734,20 +737,27 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
734737 if diags := apiErrorResponseHelper (ctx , res , httpRes , err ); diags != nil {
735738 revertChanges (d , changedKeys )
736739 updateFailure = true
737- failureEvents = append (failureEvents , httpRes .Body .Close ().Error ())
740+ if len (diags ) > 0 {
741+ failureEvents = append (failureEvents , diags [0 ].Summary )
742+ } else {
743+ tflog .Warn (ctx , "UpdateEnvironment Diagnostics is empty or nil; skipping appending to failureEvents" )
744+ }
738745 }
739746
740- job_res , job_err := PollJobStatus (res .Job .GetId (), ctx , client )
741- if job_err != "" {
742- tflog .Warn (ctx , DLPX + WARN + "Env Host Update Job Polling failed but continuing with update. Error: " + job_err )
743- }
744- tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
745- if job_res == Failed || job_res == Canceled || job_res == Abandoned {
746- tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + res .Job .GetId ()+ "!" )
747- revertChanges (d , changedKeys )
748- updateFailure = true
749- failureEvents = append (failureEvents , job_err )
750- // return diag.Errorf("[NOT OK] Job %s %s with error %s", *res.Job.Id, job_res, job_err)
747+ // if the above api call fails, no point in polling as res will be nil
748+ if res != nil {
749+ job_res , job_err := PollJobStatus (res .Job .GetId (), ctx , client )
750+ if job_err != "" {
751+ tflog .Warn (ctx , DLPX + WARN + "Env Host Update Job Polling failed but continuing with update. Error: " + job_err )
752+ }
753+ tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
754+ if job_res == Failed || job_res == Canceled || job_res == Abandoned {
755+ tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + res .Job .GetId ()+ "!" )
756+ revertChanges (d , changedKeys )
757+ updateFailure = true
758+ failureEvents = append (failureEvents , job_err )
759+ // return diag.Errorf("[NOT OK] Job %s %s with error %s", *res.Job.Id, job_res, job_err)
760+ }
751761 }
752762 }
753763 if d .HasChanges (
@@ -798,21 +808,28 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
798808 if diags := apiErrorResponseHelper (ctx , resEnvUser , httpResEnvUser , errEnvUser ); diags != nil {
799809 revertChanges (d , changedKeys )
800810 updateFailure = true
801- failureEvents = append (failureEvents , httpResEnvUser .Body .Close ().Error ())
811+ if len (diags ) > 0 {
812+ failureEvents = append (failureEvents , diags [0 ].Summary )
813+ } else {
814+ tflog .Warn (ctx , "UpdateEnvironmentUser Diagnostics is empty or nil; skipping appending to failureEvents" )
815+ }
802816 }
803817
804- job_res , job_err := PollJobStatus (resEnvUser .Job .GetId (), ctx , client )
805- if job_err != "" {
806- tflog .Warn (ctx , DLPX + WARN + "Env User Update Job Polling failed but continuing with update. Error: " + job_err )
807- }
808- tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
809- if job_res == Failed || job_res == Canceled || job_res == Abandoned {
810- tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + resEnvUser .Job .GetId ()+ "!" )
811- revertChanges (d , changedKeys )
812- updateFailure = true
813- failureEvents = append (failureEvents , job_err )
814- // return diag.Errorf("[NOT OK] Job %s %s with error %s", *resEnvUser.Job.Id, job_res, job_err)
818+ if resEnvUser != nil {
819+ job_res , job_err := PollJobStatus (resEnvUser .Job .GetId (), ctx , client )
820+ if job_err != "" {
821+ tflog .Warn (ctx , DLPX + WARN + "Env User Update Job Polling failed but continuing with update. Error: " + job_err )
822+ }
823+ tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
824+ if job_res == Failed || job_res == Canceled || job_res == Abandoned {
825+ tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + resEnvUser .Job .GetId ()+ "!" )
826+ revertChanges (d , changedKeys )
827+ updateFailure = true
828+ failureEvents = append (failureEvents , job_err )
829+ // return diag.Errorf("[NOT OK] Job %s %s with error %s", *resEnvUser.Job.Id, job_res, job_err)
830+ }
815831 }
832+
816833 }
817834 if d .HasChanges (
818835 "hosts" ,
@@ -888,20 +905,26 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
888905 if diags := apiErrorResponseHelper (ctx , hostUpdateRes , hostHttpRes , hostUpdateErr ); diags != nil {
889906 revertChanges (d , changedKeys )
890907 updateFailure = true
891- failureEvents = append (failureEvents , hostHttpRes .Body .Close ().Error ())
908+ if len (diags ) > 0 {
909+ failureEvents = append (failureEvents , diags [0 ].Summary )
910+ } else {
911+ tflog .Warn (ctx , "UpdateHost Diagnostics is empty or nil; skipping appending to failureEvents" )
912+ }
892913 }
893914
894- job_res , job_err := PollJobStatus (hostUpdateRes .Job .GetId (), ctx , client )
895- if job_err != "" {
896- tflog .Warn (ctx , DLPX + WARN + "Env Host Update Job Polling failed but continuing with update. Error: " + job_err )
897- }
898- tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
899- if job_res == Failed || job_res == Canceled || job_res == Abandoned {
900- tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + hostUpdateRes .Job .GetId ()+ "!" )
901- revertChanges (d , changedKeys )
902- updateFailure = true
903- failureEvents = append (failureEvents , job_err )
904- // return diag.Errorf("[NOT OK] Job %s %s with error %s", *hostUpdateRes.Job.Id, job_res, job_err)
915+ if hostUpdateRes != nil {
916+ job_res , job_err := PollJobStatus (hostUpdateRes .Job .GetId (), ctx , client )
917+ if job_err != "" {
918+ tflog .Warn (ctx , DLPX + WARN + "Env Host Update Job Polling failed but continuing with update. Error: " + job_err )
919+ }
920+ tflog .Info (ctx , DLPX + INFO + "Job result is " + job_res )
921+ if job_res == Failed || job_res == Canceled || job_res == Abandoned {
922+ tflog .Error (ctx , DLPX + ERROR + "Job " + job_res + " " + hostUpdateRes .Job .GetId ()+ "!" )
923+ revertChanges (d , changedKeys )
924+ updateFailure = true
925+ failureEvents = append (failureEvents , job_err )
926+ // return diag.Errorf("[NOT OK] Job %s %s with error %s", *hostUpdateRes.Job.Id, job_res, job_err)
927+ }
905928 }
906929 }
907930
@@ -922,7 +945,11 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
922945 if diags := apiErrorResponseHelper (ctx , nil , tagDelResp , tagDelErr ); diags != nil {
923946 revertChanges (d , changedKeys )
924947 updateFailure = true
925- failureEvents = append (failureEvents , tagDelResp .Body .Close ().Error ())
948+ if len (diags ) > 0 {
949+ failureEvents = append (failureEvents , diags [0 ].Summary )
950+ } else {
951+ tflog .Warn (ctx , "DeleteEnvironmentTags Diagnostics is empty or nil; skipping appending to failureEvents" )
952+ }
926953 }
927954 }
928955 // create tag
0 commit comments