From b66ecf50f1beca9d896c02794c3d747c1b3b2143 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Aug 2020 07:49:33 -0400 Subject: [PATCH 1/2] d/aws_launch_template: Add 'TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination'. Acceptance test output: $ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination -timeout 120m === RUN TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination === PAUSE TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination === CONT TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination panic: network_interfaces.0.delete_on_termination: '' expected type 'bool', got unconvertible type 'string' goroutine 240 [running]: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).Set(0xc0015c9b80, 0x669fe8d, 0x12, 0x52807e0, 0xc000f72b20, 0x1, 0x0) /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.dataSourceAwsLaunchTemplateRead(0xc0015c9b80, 0x5aba8c0, 0xc0005d1900, 0xb0afa40, 0x6a9c0c0) /home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/aws/data_source_aws_launch_template.go:505 +0x1d7b github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0002578c0, 0x75c4980, 0xc00123b440, 0xc0015c9b80, 0x5aba8c0, 0xc0005d1900, 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(0xc0002578c0, 0x75c4980, 0xc00123b440, 0xc001277920, 0x5aba8c0, 0xc0005d1900, 0xc0005d1900, 0xc001277920, 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(0xc000e512c0, 0x75c4980, 0xc00123b440, 0xc00123b3c0, 0xc000e512c0, 0xc000e512d0, 0x6a9c0b0) /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(0x75c4980, 0xc00123b440, 0x6402b40, 0xc00123b3c0, 0xc00123b440, 0x5c30d40, 0xc000c35401, 0xc001277420) /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(0x75c4a40, 0xc001168570, 0x6402b40, 0xc00123b3c0, 0xc001277400, 0xc001277420, 0xc001507ba0, 0x5094d8, 0x62c05e0, 0xc001168570) /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(0x6532a80, 0xc000e512c0, 0x75c4a40, 0xc001168570, 0xc000c354a0, 0xc000e51460, 0x75c4a40, 0xc001168570, 0xc00151e900, 0x229) /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(0xc001264000, 0x75eb5c0, 0xc00104e600, 0xc00137b300, 0xc00181cc90, 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(0xc001264000, 0x75eb5c0, 0xc00104e600, 0xc00137b300, 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(0xc000f7e300, 0xc001264000, 0x75eb5c0, 0xc00104e600, 0xc00137b300) /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 8.065s FAIL GNUmakefile:26: recipe for target 'testacc' failed make: *** [testacc] Error 1 --- aws/data_source_aws_launch_template_test.go | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/aws/data_source_aws_launch_template_test.go b/aws/data_source_aws_launch_template_test.go index d9cfdeb54bc..596695bbc6e 100644 --- a/aws/data_source_aws_launch_template_test.go +++ b/aws/data_source_aws_launch_template_test.go @@ -160,6 +160,41 @@ func TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress(t *testing.T) { }) } +func TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + dataSourceName := "data.aws_launch_template.test" + resourceName := "aws_launch_template.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSLaunchTemplateDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSLaunchTemplateDataSourceConfigNetworkInterfacesDeleteOnTermination(rName, "true"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.delete_on_termination", resourceName, "network_interfaces.0.delete_on_termination"), + ), + }, + { + Config: testAccAWSLaunchTemplateDataSourceConfigNetworkInterfacesDeleteOnTermination(rName, "false"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.delete_on_termination", resourceName, "network_interfaces.0.delete_on_termination"), + ), + }, + { + Config: testAccAWSLaunchTemplateDataSourceConfigNetworkInterfacesDeleteOnTermination(rName, "null"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.delete_on_termination", resourceName, "network_interfaces.0.delete_on_termination"), + ), + }, + }, + }) +} + func TestAccAWSLaunchTemplateDataSource_NonExistent(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -255,6 +290,22 @@ data "aws_launch_template" "test" { `, rName, associatePublicIPAddress) } +func testAccAWSLaunchTemplateDataSourceConfigNetworkInterfacesDeleteOnTermination(rName, deleteOnTermination string) string { + return fmt.Sprintf(` +resource "aws_launch_template" "test" { + name = %[1]q + + network_interfaces { + delete_on_termination = %[2]s + } +} + +data "aws_launch_template" "test" { + name = aws_launch_template.test.name +} +`, rName, deleteOnTermination) +} + const testAccAWSLaunchTemplateDataSourceConfig_NonExistent = ` data "aws_launch_template" "test" { name = "tf-acc-test-nonexistent" From 57c52d219ff2bfa79f064516592d73ddd7f3d97a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Aug 2020 07:56:40 -0400 Subject: [PATCH 2/2] d/aws_launch_template: Change 'network_interfaces.delete_on_termination' to TypeString, matching associated resource. Acceptance test output: $ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination -timeout 120m === RUN TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination === PAUSE TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination === CONT TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination --- PASS: TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination (44.91s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 44.948s --- aws/data_source_aws_launch_template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/data_source_aws_launch_template.go b/aws/data_source_aws_launch_template.go index 344c6849454..3c4f27dad4e 100644 --- a/aws/data_source_aws_launch_template.go +++ b/aws/data_source_aws_launch_template.go @@ -244,7 +244,7 @@ func dataSourceAwsLaunchTemplate() *schema.Resource { Computed: true, }, "delete_on_termination": { - Type: schema.TypeBool, + Type: schema.TypeString, Computed: true, }, "description": {