Skip to content

Commit

Permalink
Merge pull request #4344 from gordonbondon/launch-template-fix
Browse files Browse the repository at this point in the history
r/aws_launch_template: Multiple fixes
  • Loading branch information
bflad authored May 7, 2018
2 parents fac71b8 + 7862f92 commit 4ee333a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
35 changes: 24 additions & 11 deletions aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
},
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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{
Expand All @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/launch_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -200,15 +200,19 @@ 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.
* `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_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.
Expand Down

0 comments on commit 4ee333a

Please sign in to comment.