Skip to content

Commit

Permalink
data-source/aws_launch_configuration: Add 'ebs_block_device.no_device…
Browse files Browse the repository at this point in the history
…' attribute (#14583)

* d/aws_launch_configuration: Add 'TestAccAWSLaunchConfigurationDataSource_ebsNoDevice'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSLaunchConfigurationDataSource_ebsNoDevice'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLaunchConfigurationDataSource_ebsNoDevice -timeout 120m
=== RUN   TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
=== PAUSE TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
=== CONT  TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
panic: Invalid address to set: []string{"ebs_block_device", "0", "no_device"}

goroutine 281 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).Set(0xc001aa1280, 0x669198b, 0x10, 0x527fee0, 0xc000d65f80, 0x0, 0xc001aa1280)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource_data.go:188 +0x388
github.com/terraform-providers/terraform-provider-aws/aws.readLCBlockDevices(0xc001aa1280, 0xc001b19ba0, 0xc0016c6518, 0x52814e0, 0xc000e65820)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_configuration.go:617 +0xc3
github.com/terraform-providers/terraform-provider-aws/aws.dataSourceAwsLaunchConfigurationRead(0xc001aa1280, 0x5ab98c0, 0xc00080c000, 0xb0afa40, 0x6a9c1b0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/aws/data_source_aws_launch_configuration.go:251 +0xa1d
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000378e70, 0x75c4920, 0xc00007b500, 0xc001aa1280, 0x5ab98c0, 0xc00080c000, 0x0, 0x0, 0x0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:281 +0x88
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc000378e70, 0x75c4920, 0xc00007b500, 0xc000e52720, 0x5ab98c0, 0xc00080c000, 0xc00080c000, 0xc000e52720, 0x0, 0x0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:489 +0xff
github.com/hashicorp/terraform-plugin-sdk/v2/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc0008e8080, 0x75c4920, 0xc00007b500, 0xc00007b4c0, 0xc0008e8080, 0xc0008e8090, 0x6a9c1a0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/helper/plugin/grpc_provider.go:1102 +0x4c5
github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5._Provider_ReadDataSource_Handler.func1(0x75c4920, 0xc00007b500, 0x6401a40, 0xc00007b4c0, 0xc00007b500, 0x5c2fce0, 0xc00094e701, 0xc000e52400)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5/tfplugin5.pb.go:3348 +0x86
github.com/hashicorp/terraform-plugin-sdk/v2/plugin.Serve.func3.1(0x75c49e0, 0xc001638570, 0x6401a40, 0xc00007b4c0, 0xc000e523e0, 0xc000e52400, 0xc00172cba0, 0x5094d8, 0x62bf4e0, 0xc001638570)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/plugin/serve.go:76 +0x87
github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5._Provider_ReadDataSource_Handler(0x6531980, 0xc0008e8080, 0x75c49e0, 0xc001638570, 0xc00094e7e0, 0xc0008e83a0, 0x75c49e0, 0xc001638570, 0xc000dd4780, 0x179)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5/tfplugin5.pb.go:3350 +0x14b
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000dba1c0, 0x75eb560, 0xc00140c000, 0xc001c01600, 0xc001c225d0, 0xb05c0b0, 0x0, 0x0, 0x0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:1171 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc000dba1c0, 0x75eb560, 0xc00140c000, 0xc001c01600, 0x0)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:1494 +0xccd
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000eddec0, 0xc000dba1c0, 0x75eb560, 0xc00140c000, 0xc001c01600)
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:834 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:832 +0x204
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	9.129s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

* d/aws_launch_configuration: Add 'ebs_block_device.no_device'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSLaunchConfigurationDataSource_ebsNoDevice'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLaunchConfigurationDataSource_ebsNoDevice -timeout 120m
=== RUN   TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
=== PAUSE TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
=== CONT  TestAccAWSLaunchConfigurationDataSource_ebsNoDevice
--- PASS: TestAccAWSLaunchConfigurationDataSource_ebsNoDevice (19.54s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	19.590s

* Add documentation.

* d/aws_launch_configuration: Fix 'TestAccAWSLaunchConfigurationDataSource_basic'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSLaunchConfigurationDataSource_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLaunchConfigurationDataSource_basic -timeout 120m
=== RUN   TestAccAWSLaunchConfigurationDataSource_basic
=== PAUSE TestAccAWSLaunchConfigurationDataSource_basic
=== CONT  TestAccAWSLaunchConfigurationDataSource_basic
--- PASS: TestAccAWSLaunchConfigurationDataSource_basic (19.27s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	19.317s
  • Loading branch information
ewbankkit authored Aug 13, 2020
1 parent 9850bc6 commit 8468412
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
5 changes: 5 additions & 0 deletions aws/data_source_aws_launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource {
Computed: true,
},

"no_device": {
Type: schema.TypeBool,
Computed: true,
},

"iops": {
Type: schema.TypeInt,
Computed: true,
Expand Down
83 changes: 65 additions & 18 deletions aws/data_source_aws_launch_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
1 change: 1 addition & 0 deletions website/docs/d/launch_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/launch_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 8468412

Please sign in to comment.