Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9775 launch config with instance store #9810

Merged
merged 2 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ func fetchRootDeviceName(ami string, conn *ec2.EC2) (*string, error) {

// Instance store backed AMIs do not provide a root device name.
if *image.RootDeviceType == ec2.DeviceTypeInstanceStore {
return nil, fmt.Errorf("Instance store backed AMIs do not provide a root device name - Use an EBS AMI")
return nil, nil
}

// Some AMIs have a RootDeviceName like "/dev/sda1" that does not appear as a
Expand Down Expand Up @@ -1611,15 +1611,20 @@ func readBlockDeviceMappingsFromConfig(
log.Print("[WARN] IOPs is only valid for storate type io1 for EBS Volumes")
}

dn, err := fetchRootDeviceName(d.Get("ami").(string), conn)
if err != nil {
return nil, fmt.Errorf("Expected 1 AMI for ID: %s (%s)", d.Get("ami").(string), err)
}
if dn, err := fetchRootDeviceName(d.Get("ami").(string), conn); err == nil {
if dn == nil {
return nil, fmt.Errorf(
"Expected 1 AMI for ID: %s, got none",
d.Get("ami").(string))
}

blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
DeviceName: dn,
Ebs: ebs,
})
blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
DeviceName: dn,
Ebs: ebs,
})
} else {
return nil, err
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions aws/resource_aws_launch_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ func TestAccAWSLaunchConfiguration_withBlockDevices(t *testing.T) {
})
}

func TestAccAWSLaunchConfiguration_withInstanceStoreAMI(t *testing.T) {
var conf autoscaling.LaunchConfiguration
rInt := acctest.RandInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLaunchConfigurationConfigWithInstanceStoreAMI(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
),
},
},
})
}

func TestAccAWSLaunchConfiguration_updateRootBlockDevice(t *testing.T) {
var conf autoscaling.LaunchConfiguration
rInt := acctest.RandInt()
Expand Down Expand Up @@ -499,6 +518,35 @@ data "aws_ami" "ubuntu" {
`)
}

func testAccAWSLaunchConfigurationConfig_instanceStoreAMI() string {
return fmt.Sprintf(`
data "aws_ami" "ubuntu_instance_store" {
most_recent = true
owners = ["099720109477"] # Canonical

# Latest Ubuntu 18.04 LTS amd64 instance-store HVM AMI
filter {
name = "name"
values = ["ubuntu/images/hvm-instance/ubuntu-bionic-18.04-amd64-server*"]
}
}
`)
}

func testAccAWSLaunchConfigurationConfigWithInstanceStoreAMI(rInt int) string {
return testAccAWSLaunchConfigurationConfig_instanceStoreAMI() + fmt.Sprintf(`
resource "aws_launch_configuration" "bar" {
name_prefix = "tf-acc-test-%d"
image_id = "${data.aws_ami.ubuntu_instance_store.id}"

# When the instance type is updated, the new type must support ephemeral storage.
instance_type = "m1.small"
user_data = "foobar-user-data"
associate_public_ip_address = false
}
`, rInt)
}

func testAccAWSLaunchConfigurationConfigWithRootBlockDevice(rInt int) string {
return testAccAWSLaunchConfigurationConfig_ami() + fmt.Sprintf(`
resource "aws_launch_configuration" "bar" {
Expand Down