@@ -10,7 +10,6 @@ import (
10
10
"encoding/hex"
11
11
"errors"
12
12
"fmt"
13
- "iter"
14
13
"log"
15
14
"maps"
16
15
"slices"
@@ -33,7 +32,6 @@ import (
33
32
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
34
33
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
35
34
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
36
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
37
35
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
38
36
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
39
37
"github.com/hashicorp/terraform-provider-aws/internal/backoff"
@@ -2930,77 +2928,6 @@ func buildInstanceOpts(ctx context.Context, d *schema.ResourceData, meta any) (*
2930
2928
return opts , nil
2931
2929
}
2932
2930
2933
- func findInstanceByID (ctx context.Context , conn * ec2.Client , id string ) (* awstypes.Instance , error ) {
2934
- input := ec2.DescribeInstancesInput {
2935
- InstanceIds : []string {id },
2936
- }
2937
-
2938
- output , err := findInstance (ctx , conn , & input )
2939
-
2940
- if err != nil {
2941
- return nil , err
2942
- }
2943
-
2944
- if state := output .State .Name ; state == awstypes .InstanceStateNameTerminated {
2945
- return nil , & retry.NotFoundError {
2946
- Message : string (state ),
2947
- LastRequest : & input ,
2948
- }
2949
- }
2950
-
2951
- // Eventual consistency check.
2952
- if aws .ToString (output .InstanceId ) != id {
2953
- return nil , & retry.NotFoundError {
2954
- LastRequest : & input ,
2955
- }
2956
- }
2957
-
2958
- return output , nil
2959
- }
2960
-
2961
- func findInstance (ctx context.Context , conn * ec2.Client , input * ec2.DescribeInstancesInput ) (* awstypes.Instance , error ) {
2962
- var output []awstypes.Instance
2963
- for v , err := range listInstances (ctx , conn , input ) {
2964
- if err != nil {
2965
- return nil , err
2966
- }
2967
- output = append (output , v )
2968
- }
2969
-
2970
- return tfresource .AssertSingleValueResult (output , func (v * awstypes.Instance ) bool { return v .State != nil })
2971
- }
2972
-
2973
- // DescribeInstances is an "All-Or-Some" call.
2974
- func listInstances (ctx context.Context , conn * ec2.Client , input * ec2.DescribeInstancesInput ) iter.Seq2 [awstypes.Instance , error ] {
2975
- return func (yield func (awstypes.Instance , error ) bool ) {
2976
- pages := ec2 .NewDescribeInstancesPaginator (conn , input )
2977
- for pages .HasMorePages () {
2978
- page , err := pages .NextPage (ctx )
2979
-
2980
- if tfawserr .ErrCodeEquals (err , errCodeInvalidInstanceIDNotFound ) {
2981
- yield (awstypes.Instance {}, & retry.NotFoundError {
2982
- LastError : err ,
2983
- LastRequest : & input ,
2984
- })
2985
- return
2986
- }
2987
-
2988
- if err != nil {
2989
- yield (awstypes.Instance {}, err )
2990
- return
2991
- }
2992
-
2993
- for _ , v := range page .Reservations {
2994
- for _ , instance := range v .Instances {
2995
- if ! yield (instance , nil ) {
2996
- return
2997
- }
2998
- }
2999
- }
3000
- }
3001
- }
3002
- }
3003
-
3004
2931
// startInstance starts an EC2 instance and waits for the instance to start.
3005
2932
func startInstance (ctx context.Context , conn * ec2.Client , id string , retry bool , timeout time.Duration ) error {
3006
2933
var err error
@@ -4036,43 +3963,6 @@ func findInstanceLaunchTemplateVersion(ctx context.Context, conn *ec2.Client, id
4036
3963
return launchTemplateVersion , nil
4037
3964
}
4038
3965
4039
- func findLaunchTemplateData (ctx context.Context , conn * ec2.Client , launchTemplateSpecification * awstypes.LaunchTemplateSpecification ) (* awstypes.ResponseLaunchTemplateData , error ) {
4040
- input := ec2.DescribeLaunchTemplateVersionsInput {}
4041
-
4042
- if v := aws .ToString (launchTemplateSpecification .LaunchTemplateId ); v != "" {
4043
- input .LaunchTemplateId = aws .String (v )
4044
- } else if v := aws .ToString (launchTemplateSpecification .LaunchTemplateName ); v != "" {
4045
- input .LaunchTemplateName = aws .String (v )
4046
- }
4047
-
4048
- var latestVersion bool
4049
-
4050
- if v := aws .ToString (launchTemplateSpecification .Version ); v != "" {
4051
- switch v {
4052
- case launchTemplateVersionDefault :
4053
- input .Filters = newAttributeFilterList (map [string ]string {
4054
- "is-default-version" : "true" ,
4055
- })
4056
- case launchTemplateVersionLatest :
4057
- latestVersion = true
4058
- default :
4059
- input .Versions = []string {v }
4060
- }
4061
- }
4062
-
4063
- output , err := findLaunchTemplateVersions (ctx , conn , & input )
4064
-
4065
- if err != nil {
4066
- return nil , fmt .Errorf ("reading EC2 Launch Template versions: %w" , err )
4067
- }
4068
-
4069
- if latestVersion {
4070
- return output [len (output )- 1 ].LaunchTemplateData , nil
4071
- }
4072
-
4073
- return output [0 ].LaunchTemplateData , nil
4074
- }
4075
-
4076
3966
// findLaunchTemplateNameAndVersions returns the specified launch template's name, default version and latest version.
4077
3967
func findLaunchTemplateNameAndVersions (ctx context.Context , conn * ec2.Client , id string ) (string , string , string , error ) {
4078
3968
lt , err := findLaunchTemplateByID (ctx , conn , id )
@@ -4081,31 +3971,7 @@ func findLaunchTemplateNameAndVersions(ctx context.Context, conn *ec2.Client, id
4081
3971
return "" , "" , "" , err
4082
3972
}
4083
3973
4084
- return aws .ToString (lt .LaunchTemplateName ), strconv .FormatInt (aws .ToInt64 (lt .DefaultVersionNumber ), 10 ), strconv .FormatInt (aws .ToInt64 (lt .LatestVersionNumber ), 10 ), nil
4085
- }
4086
-
4087
- func findInstanceTagValue (ctx context.Context , conn * ec2.Client , instanceID , tagKey string ) (string , error ) {
4088
- input := ec2.DescribeTagsInput {
4089
- Filters : newAttributeFilterList (map [string ]string {
4090
- "resource-id" : instanceID ,
4091
- names .AttrKey : tagKey ,
4092
- }),
4093
- }
4094
-
4095
- output , err := conn .DescribeTags (ctx , & input )
4096
-
4097
- if err != nil {
4098
- return "" , err
4099
- }
4100
-
4101
- switch count := len (output .Tags ); count {
4102
- case 0 :
4103
- return "" , nil
4104
- case 1 :
4105
- return aws .ToString (output .Tags [0 ].Value ), nil
4106
- default :
4107
- return "" , tfresource .NewTooManyResultsError (count , input )
4108
- }
3974
+ return aws .ToString (lt .LaunchTemplateName ), flex .Int64ToStringValue (lt .DefaultVersionNumber ), flex .Int64ToStringValue (lt .LatestVersionNumber ), nil
4109
3975
}
4110
3976
4111
3977
// isSnowballEdgeInstance returns whether or not the specified instance ID indicates an SBE instance.
0 commit comments