From bb9a3976746abae1ce773b7084d6a7ae1e0d7b0f Mon Sep 17 00:00:00 2001 From: Paul Tittle Date: Fri, 3 Feb 2017 13:27:50 -0500 Subject: [PATCH] provider/aws: fix instance profile creation false negative fixes https://github.com/hashicorp/terraform/issues/9474 discussion of approach in https://github.com/hashicorp/terraform/pull/11634 --- .../aws/resource_aws_iam_instance_profile.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/providers/aws/resource_aws_iam_instance_profile.go b/builtin/providers/aws/resource_aws_iam_instance_profile.go index 00f2c363715e..16766d648971 100644 --- a/builtin/providers/aws/resource_aws_iam_instance_profile.go +++ b/builtin/providers/aws/resource_aws_iam_instance_profile.go @@ -121,6 +121,17 @@ func resourceAwsIamInstanceProfileCreate(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error creating IAM instance profile %s: %s", name, err) } + waiterRequest := &iam.GetInstanceProfileInput{ + InstanceProfileName: aws.String(name), + } + // don't return until the IAM service reports that the instance profile is ready. + // this ensures that terraform resources which rely on the instance profile will 'see' + // that the instance profile exists. + err = iamconn.WaitUntilInstanceProfileExists(waiterRequest) + if err != nil { + return fmt.Errorf("Timed out while waiting for instance profile %s: %s", name, err) + } + return instanceProfileSetRoles(d, iamconn) }