@@ -31,6 +31,7 @@ import (
31
31
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
32
32
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
33
33
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
34
+ "github.com/hashicorp/terraform-provider-aws/internal/backoff"
34
35
"github.com/hashicorp/terraform-provider-aws/internal/conns"
35
36
"github.com/hashicorp/terraform-provider-aws/internal/create"
36
37
"github.com/hashicorp/terraform-provider-aws/internal/enum"
@@ -1049,34 +1050,30 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta an
1049
1050
input .DisableApiStop = instanceOpts .DisableAPIStop
1050
1051
}
1051
1052
1052
- log .Printf ("[DEBUG] Creating EC2 Instance: %s" , d .Id ())
1053
- outputRaw , err := tfresource .RetryWhen (ctx , iamPropagationTimeout ,
1054
- func () (any , error ) {
1055
- return conn .RunInstances (ctx , & input )
1056
- },
1057
- func (err error ) (bool , error ) {
1058
- // IAM instance profiles can take ~10 seconds to propagate in AWS:
1059
- // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
1060
- if tfawserr .ErrMessageContains (err , errCodeInvalidParameterValue , "Invalid IAM Instance Profile" ) {
1061
- return true , err
1062
- }
1053
+ var output * ec2.RunInstancesOutput
1054
+ for r := backoff .NewRetryLoop (iamPropagationTimeout ); r .Continue (ctx ); {
1055
+ output , err = conn .RunInstances (ctx , & input )
1063
1056
1064
- // IAM roles can also take time to propagate in AWS:
1065
- if tfawserr .ErrMessageContains (err , errCodeInvalidParameterValue , " has no associated IAM Roles" ) {
1066
- return true , err
1067
- }
1057
+ // IAM instance profiles can take ~10 seconds to propagate in AWS:
1058
+ // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
1059
+ if tfawserr .ErrMessageContains (err , errCodeInvalidParameterValue , "Invalid IAM Instance Profile" ) {
1060
+ continue
1061
+ }
1068
1062
1069
- return false , err
1070
- },
1071
- )
1063
+ // IAM roles can also take time to propagate in AWS:
1064
+ if tfawserr .ErrMessageContains (err , errCodeInvalidParameterValue , " has no associated IAM Roles" ) {
1065
+ continue
1066
+ }
1067
+
1068
+ break
1069
+ }
1072
1070
1073
1071
if err != nil {
1074
1072
return sdkdiag .AppendErrorf (diags , "creating EC2 Instance: %s" , err )
1075
1073
}
1076
1074
1077
- instanceId := outputRaw .(* ec2.RunInstancesOutput ).Instances [0 ].InstanceId
1078
-
1079
- d .SetId (aws .ToString (instanceId ))
1075
+ instanceID := output .Instances [0 ].InstanceId
1076
+ d .SetId (aws .ToString (instanceID ))
1080
1077
1081
1078
instance , err := waitInstanceCreated (ctx , conn , d .Id (), d .Timeout (schema .TimeoutCreate ))
1082
1079
0 commit comments