diff --git a/aws/resource_aws_launch_template.go b/aws/resource_aws_launch_template.go index 8f802a45b1f..fa9ae291a05 100644 --- a/aws/resource_aws_launch_template.go +++ b/aws/resource_aws_launch_template.go @@ -89,11 +89,13 @@ func resourceAwsLaunchTemplate() *schema.Resource { }, "iops": { Type: schema.TypeInt, + Computed: true, Optional: true, }, "kms_key_id": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "snapshot_id": { Type: schema.TypeString, @@ -102,10 +104,12 @@ func resourceAwsLaunchTemplate() *schema.Resource { "volume_size": { Type: schema.TypeInt, Optional: true, + Computed: true, }, "volume_type": { Type: schema.TypeString, Optional: true, + Computed: true, }, }, }, @@ -158,8 +162,10 @@ func resourceAwsLaunchTemplate() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"iam_instance_profile.0.name"}, + ValidateFunc: validateArn, }, "name": { Type: schema.TypeString, @@ -362,9 +368,10 @@ func resourceAwsLaunchTemplate() *schema.Resource { }, "security_group_names": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + ConflictsWith: []string{"vpc_security_group_ids"}, }, "vpc_security_group_ids": { @@ -926,8 +933,8 @@ func readEbsBlockDeviceFromConfig(ebs map[string]interface{}) *ec2.LaunchTemplat ebsDevice.Encrypted = aws.Bool(v.(bool)) } - if v := ebs["iops"]; v != nil { - ebsDevice.Iops = aws.Int64(int64(v.(int))) + if v := ebs["iops"].(int); v > 0 { + ebsDevice.Iops = aws.Int64(int64(v)) } if v := ebs["kms_key_id"].(string); v != "" { @@ -991,9 +998,12 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) *ec2.LaunchTempl Ipv6Address: aws.String(address.(string)), }) } - networkInterface.Ipv6AddressCount = aws.Int64(int64(len(ipv6AddressList))) networkInterface.Ipv6Addresses = ipv6Addresses + if v := ni["ipv6_address_count"].(int); v > 0 { + networkInterface.Ipv6AddressCount = aws.Int64(int64(v)) + } + ipv4AddressList := ni["ipv4_addresses"].(*schema.Set).List() for _, address := range ipv4AddressList { privateIp := &ec2.PrivateIpAddressSpecification{ @@ -1002,9 +1012,12 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) *ec2.LaunchTempl } ipv4Addresses = append(ipv4Addresses, privateIp) } - networkInterface.SecondaryPrivateIpAddressCount = aws.Int64(int64(len(ipv4AddressList))) networkInterface.PrivateIpAddresses = ipv4Addresses + if v := ni["ipv4_address_count"].(int); v > 0 { + networkInterface.SecondaryPrivateIpAddressCount = aws.Int64(int64(v)) + } + return networkInterface } diff --git a/website/docs/r/launch_template.html.markdown b/website/docs/r/launch_template.html.markdown index d5a55beea3f..f858a487836 100644 --- a/website/docs/r/launch_template.html.markdown +++ b/website/docs/r/launch_template.html.markdown @@ -113,7 +113,7 @@ The following arguments are supported: `vpc_security_group_ids` instead. * `vpc_security_group_ids` - A list of security group IDs to associate with. * `tag_specifications` - The tags to apply to the resources during launch. See [Tags](#tags) below for more details. -* `user_data` - The user data to provide when launching the instance. +* `user_data` - The Base64-encoded user data to provide when launching the instance. ### Block devices @@ -200,6 +200,8 @@ The `monitoring` block supports the following: Attaches one or more [Network Interfaces](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html) to the instance. +Check limitations for autoscaling group in [Creating an Auto Scaling Group Using a Launch Template Guide](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-launch-template.html#limitations) + Each `network_interfaces` block supports the following: * `associate_public_ip_address` - Associate a public ip address with the network interface. Boolean value. @@ -207,8 +209,10 @@ Each `network_interfaces` block supports the following: * `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_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. * `security_groups` - A list of security group IDs to associate. * `subnet_id` - The VPC Subnet ID to associate.