From ef51311dd0e64c4f5c43e652e7d92613523543a6 Mon Sep 17 00:00:00 2001 From: Jameel Al-Aziz Date: Wed, 22 Apr 2020 00:02:08 -0700 Subject: [PATCH] Support empty associate_public_ip_address in launch_template data sources This ports the changes from #10157 to the launch_template data source. --- aws/data_source_aws_launch_template.go | 2 +- aws/data_source_aws_launch_template_test.go | 51 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/aws/data_source_aws_launch_template.go b/aws/data_source_aws_launch_template.go index 648585382db..01234573c48 100644 --- a/aws/data_source_aws_launch_template.go +++ b/aws/data_source_aws_launch_template.go @@ -240,7 +240,7 @@ func dataSourceAwsLaunchTemplate() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "associate_public_ip_address": { - Type: schema.TypeBool, + Type: schema.TypeString, Computed: true, }, "delete_on_termination": { diff --git a/aws/data_source_aws_launch_template_test.go b/aws/data_source_aws_launch_template_test.go index c17f1502eb4..68a91c71103 100644 --- a/aws/data_source_aws_launch_template_test.go +++ b/aws/data_source_aws_launch_template_test.go @@ -103,6 +103,41 @@ func TestAccAWSLaunchTemplateDataSource_metadataOptions(t *testing.T) { }) } +func TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress(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: testAccAWSLaunchTemplateDataSourceConfig_associatePublicIpAddress(rName, "true"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.associate_public_ip_address", resourceName, "network_interfaces.0.associate_public_ip_address"), + ), + }, + { + Config: testAccAWSLaunchTemplateDataSourceConfig_associatePublicIpAddress(rName, "false"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.associate_public_ip_address", resourceName, "network_interfaces.0.associate_public_ip_address"), + ), + }, + { + Config: testAccAWSLaunchTemplateDataSourceConfig_associatePublicIpAddress(rName, "null"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.#", resourceName, "network_interfaces.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "network_interfaces.0.associate_public_ip_address", resourceName, "network_interfaces.0.associate_public_ip_address"), + ), + }, + }, + }) +} + func testAccAWSLaunchTemplateDataSourceConfig_Basic(rName string) string { return fmt.Sprintf(` resource "aws_launch_template" "test" { @@ -166,3 +201,19 @@ data "aws_launch_template" "test" { } `, rName) } + +func testAccAWSLaunchTemplateDataSourceConfig_associatePublicIpAddress(rName, associatePublicIPAddress string) string { + return fmt.Sprintf(` +resource "aws_launch_template" "test" { + name = %[1]q + + network_interfaces { + associate_public_ip_address = %[2]s + } +} + +data "aws_launch_template" "test" { + name = aws_launch_template.test.name +} +`, rName, associatePublicIPAddress) +}