Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ipv4_address_count to be modifiable #5830

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably split these out into their own acceptance tests and test configurations to make them more maintainable in the future. 👍

}
}
`
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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snuck in, but I think its fine to leave in as it'll be handled shortly.

* `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