diff --git a/aws/data_source_aws_launch_configuration.go b/aws/data_source_aws_launch_configuration.go index 94822f5c444..e02cbd2a06a 100644 --- a/aws/data_source_aws_launch_configuration.go +++ b/aws/data_source_aws_launch_configuration.go @@ -222,11 +222,19 @@ func dataSourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface d.Set("enable_monitoring", lc.InstanceMonitoring.Enabled) } - if err := d.Set("security_groups", lc.SecurityGroups); err != nil { + vpcSGs := make([]string, 0, len(lc.SecurityGroups)) + for _, sg := range lc.SecurityGroups { + vpcSGs = append(vpcSGs, *sg) + } + if err := d.Set("security_groups", vpcSGs); err != nil { return fmt.Errorf("error setting security_groups: %s", err) } - if err := d.Set("vpc_classic_link_security_groups", lc.ClassicLinkVPCSecurityGroups); err != nil { + classicSGs := make([]string, 0, len(lc.ClassicLinkVPCSecurityGroups)) + for _, sg := range lc.ClassicLinkVPCSecurityGroups { + classicSGs = append(classicSGs, *sg) + } + if err := d.Set("vpc_classic_link_security_groups", classicSGs); err != nil { return fmt.Errorf("error setting vpc_classic_link_security_groups: %s", err) } diff --git a/aws/data_source_aws_launch_configuration_test.go b/aws/data_source_aws_launch_configuration_test.go index 7722c6134c0..880e842e134 100644 --- a/aws/data_source_aws_launch_configuration_test.go +++ b/aws/data_source_aws_launch_configuration_test.go @@ -17,7 +17,7 @@ func TestAccAWSLaunchConfigurationDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccLaunchConfigurationDataSourceConfig(rInt), + Config: testAccLaunchConfigurationDataSourceConfig_basic(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(rName, "image_id"), resource.TestCheckResourceAttrSet(rName, "instance_type"), @@ -31,8 +31,25 @@ func TestAccAWSLaunchConfigurationDataSource_basic(t *testing.T) { }, }) } +func TestAccAWSLaunchConfigurationDataSource_securityGroups(t *testing.T) { + rInt := acctest.RandInt() + rName := "data.aws_launch_configuration.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLaunchConfigurationDataSourceConfig_securityGroups(rInt), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(rName, "security_groups.#", "1"), + ), + }, + }, + }) +} -func testAccLaunchConfigurationDataSourceConfig(rInt int) string { +func testAccLaunchConfigurationDataSourceConfig_basic(rInt int) string { return fmt.Sprintf(` resource "aws_launch_configuration" "foo" { name = "terraform-test-%d" @@ -66,3 +83,27 @@ data "aws_launch_configuration" "foo" { } `, rInt) } + +func testAccLaunchConfigurationDataSourceConfig_securityGroups(rInt int) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_security_group" "test" { + name = "terraform-test_%d" + vpc_id = "${aws_vpc.test.id}" +} + +resource "aws_launch_configuration" "test" { + name = "terraform-test-%d" + image_id = "ami-21f78e11" + instance_type = "m1.small" + security_groups = ["${aws_security_group.test.id}"] +} + +data "aws_launch_configuration" "foo" { + name = "${aws_launch_configuration.test.name}" +} +`, rInt, rInt) +}