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

resource/aws_network_interface: add support for interface_type argument for EFA #18841

Merged
7 changes: 7 additions & 0 deletions .changelog/18841.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_network_interface: Add `interface_type` argument
```

```release-note:enhancement
resource/aws_launch_template: Add `interface_type` argument to `network_interfaces` configuration block
```
11 changes: 11 additions & 0 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ func testAccCheckResourceAttrHostnameWithPort(resourceName, attributeName, servi
}
}

// testAccCheckResourceAttrPrivateDnsName ensures the Terraform state exactly matches a private DNS name
//
// For example: ip-172-16-10-100.us-west-2.compute.internal
func testAccCheckResourceAttrPrivateDnsName(resourceName, attributeName string, privateIpAddress **string) resource.TestCheckFunc {
return func(s *terraform.State) error {
privateDnsName := fmt.Sprintf("ip-%s.%s", resourceAwsEc2DashIP(**privateIpAddress), resourceAwsEc2RegionalPrivateDnsSuffix(testAccGetRegion()))

return resource.TestCheckResourceAttr(resourceName, attributeName, privateDnsName)(s)
}
}

// testAccMatchResourceAttrAccountID ensures the Terraform state regexp matches an account ID
func testAccMatchResourceAttrAccountID(resourceName, attributeName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down
22 changes: 14 additions & 8 deletions aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/naming"
)

func resourceAwsLaunchTemplate() *schema.Resource {
Expand All @@ -41,6 +42,7 @@ func resourceAwsLaunchTemplate() *schema.Resource {
"name_prefix": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"name"},
ValidateFunc: validateLaunchTemplateName,
Expand Down Expand Up @@ -510,6 +512,11 @@ func resourceAwsLaunchTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"interface_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"efa", "interface"}, false),
},
},
},
},
Expand Down Expand Up @@ -658,14 +665,7 @@ func resourceAwsLaunchTemplateCreate(d *schema.ResourceData, meta interface{}) e
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

var ltName string
if v, ok := d.GetOk("name"); ok {
ltName = v.(string)
} else if v, ok := d.GetOk("name_prefix"); ok {
ltName = resource.PrefixedUniqueId(v.(string))
} else {
ltName = resource.UniqueId()
}
ltName := naming.Generate(d.Get("name").(string), d.Get("name_prefix").(string))

launchTemplateData, err := buildLaunchTemplateData(d)
if err != nil {
Expand Down Expand Up @@ -739,6 +739,7 @@ func resourceAwsLaunchTemplateRead(d *schema.ResourceData, meta interface{}) err

lt := dlt.LaunchTemplates[0]
d.Set("name", lt.LaunchTemplateName)
d.Set("name_prefix", naming.NamePrefixFromName(aws.StringValue(lt.LaunchTemplateName)))
d.Set("latest_version", lt.LatestVersionNumber)
d.Set("default_version", lt.DefaultVersionNumber)
tags := keyvaluetags.Ec2KeyValueTags(lt.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig)
Expand Down Expand Up @@ -1185,6 +1186,7 @@ func getNetworkInterfaces(n []*ec2.LaunchTemplateInstanceNetworkInterfaceSpecifi
networkInterface := map[string]interface{}{
"description": aws.StringValue(v.Description),
"device_index": aws.Int64Value(v.DeviceIndex),
"interface_type": aws.StringValue(v.InterfaceType),
"ipv4_address_count": aws.Int64Value(v.SecondaryPrivateIpAddressCount),
"ipv6_address_count": aws.Int64Value(v.Ipv6AddressCount),
"network_interface_id": aws.StringValue(v.NetworkInterfaceId),
Expand Down Expand Up @@ -1615,6 +1617,10 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) (*ec2.LaunchTemp
networkInterface.NetworkInterfaceId = aws.String(v)
}

if v, ok := ni["interface_type"].(string); ok && v != "" {
networkInterface.InterfaceType = aws.String(v)
}

if v, ok := ni["associate_carrier_ip_address"]; ok && v.(string) != "" {
vBool, err := strconv.ParseBool(v.(string))
if err != nil {
Expand Down
Loading