Skip to content

Commit

Permalink
Merge pull request #5830 from kl4w/launch-template-network-address-count
Browse files Browse the repository at this point in the history
allow ipv4_address_count to be modifiable
  • Loading branch information
bflad authored Sep 12, 2018
2 parents 0d5d89f + adad955 commit ab70575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
21 changes: 10 additions & 11 deletions aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func resourceAwsLaunchTemplate() *schema.Resource {
},
"ipv4_address_count": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
},
"subnet_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -1107,18 +1107,17 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) *ec2.LaunchTempl
networkInterface.Ipv6AddressCount = aws.Int64(int64(v))
}

ipv4AddressList := ni["ipv4_addresses"].(*schema.Set).List()
for _, address := range ipv4AddressList {
privateIp := &ec2.PrivateIpAddressSpecification{
Primary: aws.Bool(address.(string) == privateIpAddress),
PrivateIpAddress: aws.String(address.(string)),
}
ipv4Addresses = append(ipv4Addresses, privateIp)
}
networkInterface.PrivateIpAddresses = ipv4Addresses

if v := ni["ipv4_address_count"].(int); v > 0 {
networkInterface.SecondaryPrivateIpAddressCount = aws.Int64(int64(v))
} else if v := ni["ipv4_addresses"].(*schema.Set); v.Len() > 0 {
for _, address := range v.List() {
privateIp := &ec2.PrivateIpAddressSpecification{
Primary: aws.Bool(address.(string) == privateIpAddress),
PrivateIpAddress: aws.String(address.(string)),
}
ipv4Addresses = append(ipv4Addresses, privateIp)
}
networkInterface.PrivateIpAddresses = ipv4Addresses
}

return networkInterface
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 @@ -243,6 +243,7 @@ func TestAccAWSLaunchTemplate_networkInterface(t *testing.T) {
resource.TestCheckResourceAttr(resName, "network_interfaces.#", "1"),
resource.TestCheckResourceAttrSet(resName, "network_interfaces.0.network_interface_id"),
resource.TestCheckResourceAttr(resName, "network_interfaces.0.associate_public_ip_address", "false"),
resource.TestCheckResourceAttr(resName, "network_interfaces.0.ipv4_address_count", "2"),
),
},
},
Expand Down Expand Up @@ -525,6 +526,7 @@ resource "aws_launch_template" "test" {
network_interfaces {
network_interface_id = "${aws_network_interface.test.id}"
ipv4_address_count = 2
}
}
`
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/launch_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ Each `network_interfaces` block supports the following:
* `delete_on_termination` - Whether the network interface should be destroyed on instance termination.
* `description` - Description of the network interface.
* `device_index` - The integer index of the network interface attachment.
* `ipv6_addresses` - One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet.
* `ipv6_addresses` - One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet. Conflicts with `ipv6_address_count`
* `ipv6_address_count` - The number of IPv6 addresses to assign to a network interface. Conflicts with `ipv6_addresses`
* `network_interface_id` - The ID of the network interface to attach.
* `private_ip_address` - The primary private IPv4 address.
* `ipv4_address_count` - The number of secondary private IPv4 addresses to assign to a network interface.
* `ipv4_addresses` - One or more private IPv4 addresses to associate.
* `ipv4_address_count` - The number of secondary private IPv4 addresses to assign to a network interface. Conflicts with `ipv4_address_count`
* `ipv4_addresses` - One or more private IPv4 addresses to associate. Conflicts with `ipv4_addresses`
* `security_groups` - A list of security group IDs to associate.
* `subnet_id` - The VPC Subnet ID to associate.

Expand Down

0 comments on commit ab70575

Please sign in to comment.