Skip to content

Commit

Permalink
data-source/aws_launch_template: Prevent type error with network_inte…
Browse files Browse the repository at this point in the history
…rfaces associate_public_ip_address (#12936)

This ports the changes from #10157 to the launch_template data source.

Output from acceptance testing:

```
--- PASS: TestAccAWSLaunchTemplateDataSource_basic (9.56s)
--- PASS: TestAccAWSLaunchTemplateDataSource_filter_tags (10.47s)
--- PASS: TestAccAWSLaunchTemplateDataSource_metadataOptions (10.52s)
--- PASS: TestAccAWSLaunchTemplateDataSource_filter_basic (10.51s)
--- PASS: TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress (21.20s)
```
  • Loading branch information
jalaziz committed Apr 23, 2020
1 parent dc7d88e commit 06ace78
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/data_source_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
51 changes: 51 additions & 0 deletions aws/data_source_aws_launch_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}

0 comments on commit 06ace78

Please sign in to comment.