Skip to content

Commit

Permalink
Merge pull request #4364 from kl4w/lt_set_security_groups
Browse files Browse the repository at this point in the history
r/launch_template: set security groups in network interfaces
  • Loading branch information
bflad authored Apr 26, 2018
2 parents bab0686 + 67c9538 commit 1e5bb07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,17 @@ func getNetworkInterfaces(n []*ec2.LaunchTemplateInstanceNetworkInterfaceSpecifi
}

if len(v.Groups) > 0 {
networkInterface["security_groups"] = aws.StringValueSlice(v.Groups)
raw, ok := networkInterface["security_groups"]
if !ok {
raw = schema.NewSet(schema.HashString, nil)
}
list := raw.(*schema.Set)

for _, group := range v.Groups {
list.Add(aws.StringValue(group))
}

networkInterface["security_groups"] = list
}

s = append(s, networkInterface)
Expand Down Expand Up @@ -969,6 +979,12 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) *ec2.LaunchTempl
networkInterface.SubnetId = aws.String(v)
}

if v := ni["security_groups"].(*schema.Set); v.Len() > 0 {
for _, v := range v.List() {
networkInterface.Groups = append(networkInterface.Groups, aws.String(v.(string)))
}
}

ipv6AddressList := ni["ipv6_addresses"].(*schema.Set).List()
for _, address := range ipv6AddressList {
ipv6Addresses = append(ipv6Addresses, &ec2.InstanceIpv6AddressRequest{
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_launch_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestAccAWSLaunchTemplate_data(t *testing.T) {
resource.TestCheckResourceAttrSet(resName, "key_name"),
resource.TestCheckResourceAttr(resName, "monitoring.#", "1"),
resource.TestCheckResourceAttr(resName, "network_interfaces.#", "1"),
resource.TestCheckResourceAttr(resName, "network_interfaces.0.security_groups.#", "1"),
resource.TestCheckResourceAttr(resName, "placement.#", "1"),
resource.TestCheckResourceAttrSet(resName, "ram_disk_id"),
resource.TestCheckResourceAttr(resName, "vpc_security_group_ids.#", "1"),
Expand Down Expand Up @@ -275,6 +276,7 @@ resource "aws_launch_template" "foo" {
network_interfaces {
associate_public_ip_address = true
network_interface_id = "eni-123456ab"
security_groups = ["sg-1a23bc45"]
}
placement {
Expand Down

0 comments on commit 1e5bb07

Please sign in to comment.