@@ -652,6 +652,132 @@ func waitImageDeleted(ctx context.Context, conn *ec2.Client, id string, timeout
652
652
return nil , err
653
653
}
654
654
655
+ func waitInstanceCreated (ctx context.Context , conn * ec2.Client , id string , timeout time.Duration ) (* awstypes.Instance , error ) {
656
+ stateConf := & retry.StateChangeConf {
657
+ Pending : enum .Slice (awstypes .InstanceStateNamePending ),
658
+ Target : enum .Slice (awstypes .InstanceStateNameRunning ),
659
+ Refresh : statusInstance (ctx , conn , id ),
660
+ Timeout : timeout ,
661
+ Delay : 10 * time .Second ,
662
+ MinTimeout : 3 * time .Second ,
663
+ }
664
+
665
+ outputRaw , err := stateConf .WaitForStateContext (ctx )
666
+
667
+ if output , ok := outputRaw .(* awstypes.Instance ); ok {
668
+ if stateReason := output .StateReason ; stateReason != nil {
669
+ tfresource .SetLastError (err , errors .New (aws .ToString (stateReason .Message )))
670
+ }
671
+
672
+ return output , err
673
+ }
674
+
675
+ return nil , err
676
+ }
677
+
678
+ func waitInstanceDeleted (ctx context.Context , conn * ec2.Client , id string , timeout time.Duration ) (* awstypes.Instance , error ) {
679
+ stateConf := & retry.StateChangeConf {
680
+ Pending : enum .Slice (
681
+ awstypes .InstanceStateNamePending ,
682
+ awstypes .InstanceStateNameRunning ,
683
+ awstypes .InstanceStateNameShuttingDown ,
684
+ awstypes .InstanceStateNameStopping ,
685
+ awstypes .InstanceStateNameStopped ,
686
+ ),
687
+ Target : enum .Slice (awstypes .InstanceStateNameTerminated ),
688
+ Refresh : statusInstance (ctx , conn , id ),
689
+ Timeout : timeout ,
690
+ Delay : 10 * time .Second ,
691
+ MinTimeout : 3 * time .Second ,
692
+ }
693
+
694
+ outputRaw , err := stateConf .WaitForStateContext (ctx )
695
+
696
+ if output , ok := outputRaw .(* awstypes.Instance ); ok {
697
+ if stateReason := output .StateReason ; stateReason != nil {
698
+ tfresource .SetLastError (err , errors .New (aws .ToString (stateReason .Message )))
699
+ }
700
+
701
+ return output , err
702
+ }
703
+
704
+ return nil , err
705
+ }
706
+
707
+ func waitInstanceReady (ctx context.Context , conn * ec2.Client , id string , timeout time.Duration ) (* awstypes.Instance , error ) {
708
+ stateConf := & retry.StateChangeConf {
709
+ Pending : enum .Slice (awstypes .InstanceStateNamePending , awstypes .InstanceStateNameStopping ),
710
+ Target : enum .Slice (awstypes .InstanceStateNameRunning , awstypes .InstanceStateNameStopped ),
711
+ Refresh : statusInstance (ctx , conn , id ),
712
+ Timeout : timeout ,
713
+ Delay : 10 * time .Second ,
714
+ MinTimeout : 3 * time .Second ,
715
+ }
716
+
717
+ outputRaw , err := stateConf .WaitForStateContext (ctx )
718
+
719
+ if output , ok := outputRaw .(* awstypes.Instance ); ok {
720
+ if stateReason := output .StateReason ; stateReason != nil {
721
+ tfresource .SetLastError (err , errors .New (aws .ToString (stateReason .Message )))
722
+ }
723
+
724
+ return output , err
725
+ }
726
+
727
+ return nil , err
728
+ }
729
+
730
+ func waitInstanceStarted (ctx context.Context , conn * ec2.Client , id string , timeout time.Duration ) (* awstypes.Instance , error ) {
731
+ stateConf := & retry.StateChangeConf {
732
+ Pending : enum .Slice (awstypes .InstanceStateNamePending , awstypes .InstanceStateNameStopped ),
733
+ Target : enum .Slice (awstypes .InstanceStateNameRunning ),
734
+ Refresh : statusInstance (ctx , conn , id ),
735
+ Timeout : timeout ,
736
+ Delay : 10 * time .Second ,
737
+ MinTimeout : 3 * time .Second ,
738
+ }
739
+
740
+ outputRaw , err := stateConf .WaitForStateContext (ctx )
741
+
742
+ if output , ok := outputRaw .(* awstypes.Instance ); ok {
743
+ if stateReason := output .StateReason ; stateReason != nil {
744
+ tfresource .SetLastError (err , errors .New (aws .ToString (stateReason .Message )))
745
+ }
746
+
747
+ return output , err
748
+ }
749
+
750
+ return nil , err
751
+ }
752
+
753
+ func waitInstanceStopped (ctx context.Context , conn * ec2.Client , id string , timeout time.Duration ) (* awstypes.Instance , error ) {
754
+ stateConf := & retry.StateChangeConf {
755
+ Pending : enum .Slice (
756
+ awstypes .InstanceStateNamePending ,
757
+ awstypes .InstanceStateNameRunning ,
758
+ awstypes .InstanceStateNameShuttingDown ,
759
+ awstypes .InstanceStateNameStopping ,
760
+ ),
761
+ Target : enum .Slice (awstypes .InstanceStateNameStopped ),
762
+ Refresh : statusInstance (ctx , conn , id ),
763
+ Timeout : timeout ,
764
+ Delay : 10 * time .Second ,
765
+ MinTimeout : 3 * time .Second ,
766
+ }
767
+
768
+ outputRaw , err := stateConf .WaitForStateContext (ctx )
769
+
770
+ if output , ok := outputRaw .(* awstypes.Instance ); ok {
771
+ if stateReason := output .StateReason ; stateReason != nil {
772
+ tfresource .SetLastError (err , errors .New (aws .ToString (stateReason .Message )))
773
+ }
774
+
775
+ return output , err
776
+ }
777
+
778
+ return nil , err
779
+ }
780
+
655
781
func waitInstanceCapacityReservationSpecificationUpdated (ctx context.Context , conn * ec2.Client , instanceID string , expectedValue * awstypes.CapacityReservationSpecification ) (* awstypes.Instance , error ) {
656
782
stateConf := & retry.StateChangeConf {
657
783
Target : enum .Slice (strconv .FormatBool (true )),
0 commit comments