@@ -248,6 +248,9 @@ func (r *expressGatewayServiceResource) Create(ctx context.Context, req resource
248248 return
249249 }
250250
251+ // Set a state value to trigger replacement on error
252+ resp .State .SetAttribute (ctx , path .Root ("service_arn" ), out .Service .ServiceArn )
253+
251254 serviceARN := aws .ToString (out .Service .ServiceArn )
252255 createTimeout := r .CreateTimeout (ctx , plan .Timeouts )
253256 var waitOut * awstypes.ECSExpressGatewayService
@@ -376,8 +379,7 @@ func (r *expressGatewayServiceResource) Update(ctx context.Context, req resource
376379 conn := r .Meta ().ECSClient (ctx )
377380
378381 diff , d := fwflex .Diff (ctx , plan , state , fwflex .WithIgnoredField ("active_configurations" ), fwflex .WithIgnoredField ("current_deployment" ),
379- fwflex .WithIgnoredField ("scaling_target" ), fwflex .WithIgnoredField (names .AttrTags ), fwflex .WithIgnoredField (names .AttrTags ),
380- fwflex .WithIgnoredField (names .AttrTagsAll ))
382+ fwflex .WithIgnoredField ("scaling_target" ), fwflex .WithIgnoredField (names .AttrTags ), fwflex .WithIgnoredField (names .AttrTagsAll ))
381383 smerr .AddEnrich (ctx , & resp .Diagnostics , d )
382384 if resp .Diagnostics .HasError () {
383385 return
@@ -487,12 +489,12 @@ func (r *expressGatewayServiceResource) Delete(ctx context.Context, req resource
487489 _ , err := conn .DeleteExpressGatewayService (ctx , & input )
488490 if err != nil {
489491 if errs .IsAErrorMessageContains [* awstypes.InvalidParameterException ](err , "Resource not found" ) ||
490- errs .IsAErrorMessageContains [* awstypes.ServiceNotActiveException ](err , "Cannot perform this operation on a service in INACTIVE status" ) ||
491- errs .IsAErrorMessageContains [* awstypes.ServiceNotActiveException ](err , "Service is in DRAINING status" ) {
492+ errs .IsAErrorMessageContains [* awstypes.ServiceNotActiveException ](err , "Cannot perform this operation on a service in INACTIVE status" ) {
492493 // Service was already deleted/inactive/draining - deletion is already in progress or complete
493494 return
494- } else {
495- // Real error occurred
495+ } else if ! errs .IsAErrorMessageContains [* awstypes.ServiceNotActiveException ](err , "Service is in DRAINING status" ) {
496+ // Real error occurred.
497+ // If service is in DRAINING status, fall-through to wait for it to become INACTIVE
496498 smerr .AddError (ctx , & resp .Diagnostics , err , smerr .ID , serviceARN )
497499 return
498500 }
@@ -553,8 +555,8 @@ func waitExpressGatewayServiceStable(ctx context.Context, conn *ecs.Client, gate
553555
554556func waitExpressGatewayServiceInactive (ctx context.Context , conn * ecs.Client , id string , timeout time.Duration ) (* awstypes.ECSExpressGatewayService , error ) {
555557 stateConf := & sdkretry.StateChangeConf {
556- Pending : []string {gatewayServiceStatusActive },
557- Target : []string {gatewayServiceStatusInactive , gatewayServiceStatusDraining },
558+ Pending : []string {gatewayServiceStatusActive , gatewayServiceStatusDraining },
559+ Target : []string {gatewayServiceStatusInactive },
558560 Refresh : statusExpressGatewayServiceForDeletion (ctx , conn , id ),
559561 Timeout : timeout ,
560562 MinTimeout : 1 * time .Second ,
@@ -587,15 +589,8 @@ func statusExpressGatewayServiceForDeletion(ctx context.Context, conn *ecs.Clien
587589 return func () (any , string , error ) {
588590 output , err := findExpressGatewayServiceNoTagsByARN (ctx , conn , gatewayServiceARN )
589591 if err != nil {
590- if retry .NotFound (err ) || errs .IsAErrorMessageContains [* awstypes.InvalidParameterException ](err , "Resource not found" ) ||
591- errs .IsAErrorMessageContains [* awstypes.ServiceNotActiveException ](err , "Cannot perform this operation on a service in INACTIVE status" ) {
592- mockService := & awstypes.ECSExpressGatewayService {
593- ServiceArn : aws .String (gatewayServiceARN ),
594- Status : & awstypes.ExpressGatewayServiceStatus {
595- StatusCode : awstypes .ExpressGatewayServiceStatusCodeInactive ,
596- },
597- }
598- return mockService , gatewayServiceStatusInactive , nil
592+ if retry .NotFound (err ) || errs .IsAErrorMessageContains [* awstypes.InvalidParameterException ](err , "Resource not found" ) {
593+ return nil , "" , nil
599594 }
600595 return nil , "" , smarterr .NewError (err )
601596 }
@@ -950,14 +945,7 @@ func retryExpressGatewayServiceCreate(ctx context.Context, conn *ecs.Client, inp
950945 func (ctx context.Context ) (any , error ) {
951946 return conn .CreateExpressGatewayService (ctx , input )
952947 },
953- func (err error ) (bool , error ) {
954- if errs .IsAErrorMessageContains [* awstypes.AccessDeniedException ](err , "Cannot assume role" ) ||
955- errs .IsAErrorMessageContains [* awstypes.ClientException ](err , "AWS was not able to validate the provided access credentials" ) ||
956- errs .IsAErrorMessageContains [* awstypes.AccessDeniedException ](err , "is not authorized to perform: sts:AssumeRole" ) {
957- return true , err
958- }
959- return false , err
960- },
948+ expressGatewayRetryable ,
961949 )
962950 if err != nil {
963951 return nil , err
@@ -974,17 +962,29 @@ func retryExpressGatewayServiceUpdate(ctx context.Context, conn *ecs.Client, inp
974962 func (ctx context.Context ) (any , error ) {
975963 return conn .UpdateExpressGatewayService (ctx , input )
976964 },
977- func (err error ) (bool , error ) {
978- if errs .IsAErrorMessageContains [* awstypes.AccessDeniedException ](err , "Cannot assume role" ) ||
979- errs .IsAErrorMessageContains [* awstypes.ClientException ](err , "AWS was not able to validate the provided access credentials" ) ||
980- errs .IsAErrorMessageContains [* awstypes.AccessDeniedException ](err , "is not authorized to perform: sts:AssumeRole" ) {
981- return true , err
982- }
983- return false , err
984- },
965+ expressGatewayRetryable ,
985966 )
986967 if err != nil {
987968 return nil , err
988969 }
989970 return outputRaw .(* ecs.UpdateExpressGatewayServiceOutput ), nil
990971}
972+
973+ func expressGatewayRetryable (err error ) (bool , error ) {
974+ if errs .Contains (err , "is not authorized to perform" ) || // This message can occur with at least AccessDeniedException, ClientException, and InvalidParameterException
975+ errs .Contains (err , "AWS was not able to validate the provided access credentials" ) || // This message can occur with at least ClientException and InvalidParameterException
976+ errs .IsAErrorMessageContains [* awstypes.AccessDeniedException ](err , "Cannot assume role" ) ||
977+ errs .IsAErrorMessageContains [* awstypes.ClientException ](err , "The security token included in the request is invalid" ) {
978+ return true , err
979+ }
980+ return false , err
981+ }
982+
983+ // newListExpressGatewayServicesPaginator returns a new paginator for ListServices that only returns Customer-managed Services.
984+ func newListExpressGatewayServicesPaginator (conn * ecs.Client , input * ecs.ListServicesInput ) * ecs.ListServicesPaginator {
985+ return ecs .NewListServicesPaginator (conn , & ecs.ListServicesInput {
986+ Cluster : input .Cluster ,
987+ LaunchType : input .LaunchType ,
988+ ResourceManagementType : awstypes .ResourceManagementTypeEcs ,
989+ })
990+ }
0 commit comments