diff --git a/aws/data_source_aws_launch_configuration.go b/aws/data_source_aws_launch_configuration.go index 2046a8daf7a..932cba6db92 100644 --- a/aws/data_source_aws_launch_configuration.go +++ b/aws/data_source_aws_launch_configuration.go @@ -105,6 +105,11 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource { Computed: true, }, + "no_device": { + Type: schema.TypeBool, + Computed: true, + }, + "iops": { Type: schema.TypeInt, Computed: true, diff --git a/aws/data_source_aws_launch_configuration_test.go b/aws/data_source_aws_launch_configuration_test.go index 5445893c8a4..05fa7b1415a 100644 --- a/aws/data_source_aws_launch_configuration_test.go +++ b/aws/data_source_aws_launch_configuration_test.go @@ -10,29 +10,33 @@ import ( ) func TestAccAWSLaunchConfigurationDataSource_basic(t *testing.T) { - rInt := acctest.RandInt() - rName := "data.aws_launch_configuration.foo" + resourceName := "aws_launch_configuration.test" + datasourceName := "data.aws_launch_configuration.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccLaunchConfigurationDataSourceConfig_basic(rInt), + Config: testAccLaunchConfigurationDataSourceConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(rName, "image_id"), - resource.TestCheckResourceAttrSet(rName, "instance_type"), - resource.TestCheckResourceAttrSet(rName, "associate_public_ip_address"), - resource.TestCheckResourceAttrSet(rName, "user_data"), - resource.TestCheckResourceAttr(rName, "root_block_device.#", "1"), - resource.TestCheckResourceAttr(rName, "ebs_block_device.#", "1"), - resource.TestCheckResourceAttr(rName, "ephemeral_block_device.#", "1"), - testAccMatchResourceAttrRegionalARN(rName, "arn", "autoscaling", regexp.MustCompile(`launchConfiguration:.+`)), + resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(datasourceName, "image_id", resourceName, "image_id"), + resource.TestCheckResourceAttrPair(datasourceName, "instance_type", resourceName, "instance_type"), + resource.TestCheckResourceAttrPair(datasourceName, "associate_public_ip_address", resourceName, "associate_public_ip_address"), + // Resource and data source user_data have differing representations in state. + resource.TestCheckResourceAttrSet(datasourceName, "user_data"), + resource.TestCheckResourceAttrPair(datasourceName, "root_block_device.#", resourceName, "root_block_device.#"), + resource.TestCheckResourceAttrPair(datasourceName, "ebs_block_device.#", resourceName, "ebs_block_device.#"), + resource.TestCheckResourceAttrPair(datasourceName, "ephemeral_block_device.#", resourceName, "ephemeral_block_device.#"), + testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "autoscaling", regexp.MustCompile(`launchConfiguration:.+`)), ), }, }, }) } + func TestAccAWSLaunchConfigurationDataSource_securityGroups(t *testing.T) { rInt := acctest.RandInt() rName := "data.aws_launch_configuration.foo" @@ -51,10 +55,32 @@ func TestAccAWSLaunchConfigurationDataSource_securityGroups(t *testing.T) { }) } -func testAccLaunchConfigurationDataSourceConfig_basic(rInt int) string { - return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` -resource "aws_launch_configuration" "foo" { - name = "terraform-test-%d" +func TestAccAWSLaunchConfigurationDataSource_ebsNoDevice(t *testing.T) { + resourceName := "aws_launch_configuration.test" + datasourceName := "data.aws_launch_configuration.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLaunchConfigurationDataSourceConfigEbsNoDevice(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(datasourceName, "image_id", resourceName, "image_id"), + resource.TestCheckResourceAttrPair(datasourceName, "instance_type", resourceName, "instance_type"), + resource.TestCheckResourceAttrPair(datasourceName, "ebs_block_device.#", resourceName, "ebs_block_device.#"), + ), + }, + }, + }) +} + +func testAccLaunchConfigurationDataSourceConfig_basic(rName string) string { + return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), fmt.Sprintf(` +resource "aws_launch_configuration" "test" { + name = %[1]q image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "m1.small" associate_public_ip_address = true @@ -83,10 +109,10 @@ resource "aws_launch_configuration" "foo" { } } -data "aws_launch_configuration" "foo" { - name = aws_launch_configuration.foo.name +data "aws_launch_configuration" "test" { + name = aws_launch_configuration.test.name } -`, rInt) +`, rName)) } func testAccLaunchConfigurationDataSourceConfig_securityGroups(rInt int) string { @@ -112,3 +138,24 @@ data "aws_launch_configuration" "foo" { } `, rInt, rInt) } + +func testAccLaunchConfigurationDataSourceConfigEbsNoDevice(rName string) string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), + fmt.Sprintf(` +resource "aws_launch_configuration" "test" { + name = %[1]q + image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id + instance_type = "m1.small" + + ebs_block_device { + device_name = "/dev/sda2" + no_device = true + } +} + +data "aws_launch_configuration" "test" { + name = aws_launch_configuration.test.name +} +`, rName)) +} diff --git a/website/docs/d/launch_configuration.html.markdown b/website/docs/d/launch_configuration.html.markdown index 82c24e1dbfe..7b1169294f5 100644 --- a/website/docs/d/launch_configuration.html.markdown +++ b/website/docs/d/launch_configuration.html.markdown @@ -60,6 +60,7 @@ In addition to all arguments above, the following attributes are exported: * `delete_on_termination` - Whether the EBS Volume will be deleted on instance termination. * `device_name` - The Name of the device. +* `no_device` - Whether the device in the block device mapping of the AMI is suppressed. * `iops` - The provisioned IOPs of the volume. * `snapshot_id` - The Snapshot ID of the mount. * `volume_size` - The Size of the volume. diff --git a/website/docs/r/launch_configuration.html.markdown b/website/docs/r/launch_configuration.html.markdown index d83cc038c20..d96ee73ea45 100644 --- a/website/docs/r/launch_configuration.html.markdown +++ b/website/docs/r/launch_configuration.html.markdown @@ -198,6 +198,7 @@ Each `ebs_block_device` supports the following: * `delete_on_termination` - (Optional) Whether the volume should be destroyed on instance termination (Default: `true`). * `encrypted` - (Optional) Whether the volume should be encrypted or not. Do not use this option if you are using `snapshot_id` as the encrypted flag will be determined by the snapshot. (Default: `false`). +* `no_device` - (Optional) Whether the device in the block device mapping of the AMI is suppressed. Modifying any `ebs_block_device` currently requires resource replacement.