From 6c2b5111524fffdde9312884d22f492f185e2106 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Fri, 25 Mar 2016 13:07:47 -0500 Subject: [PATCH] provider/aws: Fix launch_config waiting for IAM instance profile AWS changed their error message, which was being used for detection of the specific error that indicates we need to wait for IAM propagation. Behavior is covered by a test now. Fixes #5862 --- .../aws/resource_aws_launch_configuration.go | 3 +- .../resource_aws_launch_configuration_test.go | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index bbcf7a91d6..9607446ddd 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "fmt" "log" + "strings" "time" "github.com/aws/aws-sdk-go/aws" @@ -432,7 +433,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface _, err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts) if err != nil { if awsErr, ok := err.(awserr.Error); ok { - if awsErr.Message() == "Invalid IamInstanceProfile" { + if strings.Contains(awsErr.Message(), "Invalid IamInstanceProfile") { return resource.RetryableError(err) } } diff --git a/builtin/providers/aws/resource_aws_launch_configuration_test.go b/builtin/providers/aws/resource_aws_launch_configuration_test.go index 3cb5e50f4a..9fcab65a8b 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration_test.go +++ b/builtin/providers/aws/resource_aws_launch_configuration_test.go @@ -89,6 +89,24 @@ func TestAccAWSLaunchConfiguration_withSpotPrice(t *testing.T) { }) } +func TestAccAWSLaunchConfiguration_withIAMProfile(t *testing.T) { + var conf autoscaling.LaunchConfiguration + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSLaunchConfigurationConfig_withIAMProfile, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf), + ), + }, + }, + }) +} + func testAccCheckAWSLaunchConfigurationWithEncryption(conf *autoscaling.LaunchConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { // Map out the block devices by name, which should be unique. @@ -337,3 +355,35 @@ resource "aws_launch_configuration" "baz" { } } ` + +const testAccAWSLaunchConfigurationConfig_withIAMProfile = ` +resource "aws_iam_role" "role" { + name = "TestAccAWSLaunchConfiguration-withIAMProfile" + assume_role_policy = <