Merge pull request #5863 from hashicorp/phinze/aws-fix-lc-wait-for-iam-error
provider/aws: Fix launch_config waiting for IAM instance profile
This commit is contained in:
commit
5f94449197
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
@ -432,7 +433,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
_, err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
|
_, err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if awsErr, ok := err.(awserr.Error); ok {
|
if awsErr, ok := err.(awserr.Error); ok {
|
||||||
if awsErr.Message() == "Invalid IamInstanceProfile" {
|
if strings.Contains(awsErr.Message(), "Invalid IamInstanceProfile") {
|
||||||
return resource.RetryableError(err)
|
return resource.RetryableError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
func testAccCheckAWSLaunchConfigurationWithEncryption(conf *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// Map out the block devices by name, which should be unique.
|
// 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 = <<EOF
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Action": "sts:AssumeRole",
|
||||||
|
"Principal": {
|
||||||
|
"Service": "ec2.amazonaws.com"
|
||||||
|
},
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Sid": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_iam_instance_profile" "profile" {
|
||||||
|
name = "TestAccAWSLaunchConfiguration-withIAMProfile"
|
||||||
|
roles = ["${aws_iam_role.role.name}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_launch_configuration" "bar" {
|
||||||
|
image_id = "ami-5189a661"
|
||||||
|
instance_type = "t2.nano"
|
||||||
|
iam_instance_profile = "${aws_iam_instance_profile.profile.name}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue