From aed17f865864baa7ff7f3cf10a51f54e8cc148dc Mon Sep 17 00:00:00 2001 From: justnom Date: Thu, 4 Jun 2015 11:44:33 -0400 Subject: [PATCH] Fixing bugs with `aws_network_interface` and added docs. When a user tried to create an `aws_network_interface` resource without specifying the `private_ips` or `security_groups` attributes the API call to AWS would fail with a 500 HTTP error. Length checks have been put in place for both of these attributes before they are added to the `ec2.CreateNetworkInterfaceInput` struct. Documentation was also added for the `aws_network_interface` resource. --- .../aws/resource_aws_network_interface.go | 14 +++-- .../aws/r/network_interface.markdown | 51 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 website/source/docs/providers/aws/r/network_interface.markdown diff --git a/builtin/providers/aws/resource_aws_network_interface.go b/builtin/providers/aws/resource_aws_network_interface.go index 430c5b992f..aee50f0aa5 100644 --- a/builtin/providers/aws/resource_aws_network_interface.go +++ b/builtin/providers/aws/resource_aws_network_interface.go @@ -78,9 +78,17 @@ func resourceAwsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) conn := meta.(*AWSClient).ec2conn request := &ec2.CreateNetworkInterfaceInput{ - Groups: expandStringList(d.Get("security_groups").(*schema.Set).List()), - SubnetID: aws.String(d.Get("subnet_id").(string)), - PrivateIPAddresses: expandPrivateIPAddesses(d.Get("private_ips").(*schema.Set).List()), + SubnetID: aws.String(d.Get("subnet_id").(string)), + } + + security_groups := d.Get("security_groups").(*schema.Set).List() + if len(security_groups) != 0 { + request.Groups = expandStringList(security_groups) + } + + private_ips := d.Get("private_ips").(*schema.Set).List() + if len(private_ips) != 0 { + request.PrivateIPAddresses = expandPrivateIPAddesses(private_ips) } log.Printf("[DEBUG] Creating network interface") diff --git a/website/source/docs/providers/aws/r/network_interface.markdown b/website/source/docs/providers/aws/r/network_interface.markdown new file mode 100644 index 0000000000..8144d8f0f5 --- /dev/null +++ b/website/source/docs/providers/aws/r/network_interface.markdown @@ -0,0 +1,51 @@ +--- +layout: "aws" +page_title: "AWS: aws_network_interface" +sidebar_current: "docs-aws-resource-network-interface" +description: |- + Provides an Elastic network interface (ENI) resource. +--- + +# aws\_network\_interface + +Provides an Elastic network interface (ENI) resource. + +## Example Usage + +``` +resource "aws_network_interface" "test" { + subnet_id = "${aws_subnet.public_a.id}" + private_ips = ["10.0.0.50"] + security_groups = ["${aws_security_group.web.name}"] + attachment { + instance = "${aws_instance.test.id}" + device_index = 1 + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `subnet_id` - (Required) Subnet ID to create the ENI in. +* `private_ips` - (Optional) List of private IPs to assign to the ENI. +* `security_groups` - (Optional) List of security group IDs to assign to the ENI. +* `attachment` - (Required) Block to define the attachment of the ENI. Documented below. +* `tags` - (Optional) A mapping of tags to assign to the resource. + +The `attachment` block supports: + +* `instance` - (Required) ID of the instance to attach to. +* `device_index` - (Required) Integer to define the devices index. + +## Attributes Reference + +The following attributes are exported: + +* `subnet_id` - Subnet ID the ENI is in. +* `private_ips` - List of private IPs assigned to the ENI. +* `security_groups` - List of security groups attached to the ENI. +* `attachment` - Block defining the attachment of the ENI. +* `tags` - Tags assigned to the ENI. +