diff --git a/aws/resource_aws_launch_template.go b/aws/resource_aws_launch_template.go index ca1fb2d662b..5be358d0b58 100644 --- a/aws/resource_aws_launch_template.go +++ b/aws/resource_aws_launch_template.go @@ -341,7 +341,7 @@ func resourceAwsLaunchTemplate() *schema.Resource { }, "ipv4_address_count": { Type: schema.TypeInt, - Computed: true, + Optional: true, }, "subnet_id": { Type: schema.TypeString, @@ -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 diff --git a/aws/resource_aws_launch_template_test.go b/aws/resource_aws_launch_template_test.go index c151c15e709..e53c527d20b 100644 --- a/aws/resource_aws_launch_template_test.go +++ b/aws/resource_aws_launch_template_test.go @@ -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"), ), }, }, @@ -525,6 +526,7 @@ resource "aws_launch_template" "test" { network_interfaces { network_interface_id = "${aws_network_interface.test.id}" + ipv4_address_count = 2 } } ` diff --git a/website/docs/r/launch_template.html.markdown b/website/docs/r/launch_template.html.markdown index bf2d63f6da4..b3287cde57a 100644 --- a/website/docs/r/launch_template.html.markdown +++ b/website/docs/r/launch_template.html.markdown @@ -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.