first steps to add network interface

This commit is contained in:
Peter Beams 2015-03-03 01:33:42 +00:00
parent 23d90c0c02
commit 590a912cc9
4 changed files with 124 additions and 1 deletions

View File

@ -38,7 +38,7 @@ updatedeps:
| xargs go list -f '{{join .Deps "\n"}}' \ | xargs go list -f '{{join .Deps "\n"}}' \
| grep -v github.com/hashicorp/terraform \ | grep -v github.com/hashicorp/terraform \
| sort -u \ | sort -u \
| xargs go get -f -u -v | xargs go get -u -v
cover: cover:
@go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \ @go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \

View File

@ -11,6 +11,7 @@ import (
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
awsGo "github.com/hashicorp/aws-sdk-go/aws" awsGo "github.com/hashicorp/aws-sdk-go/aws"
awsec2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/aws-sdk-go/gen/autoscaling" "github.com/hashicorp/aws-sdk-go/gen/autoscaling"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/hashicorp/aws-sdk-go/gen/rds" "github.com/hashicorp/aws-sdk-go/gen/rds"
@ -27,6 +28,7 @@ type Config struct {
type AWSClient struct { type AWSClient struct {
ec2conn *ec2.EC2 ec2conn *ec2.EC2
ec2conn2 *awsec2.EC2
elbconn *elb.ELB elbconn *elb.ELB
autoscalingconn *autoscaling.AutoScaling autoscalingconn *autoscaling.AutoScaling
s3conn *s3.S3 s3conn *s3.S3
@ -63,6 +65,7 @@ func (c *Config) Client() (interface{}, error) {
log.Println("[INFO] Initializing EC2 connection") log.Println("[INFO] Initializing EC2 connection")
client.ec2conn = ec2.New(auth, region) client.ec2conn = ec2.New(auth, region)
client.ec2conn2 = awsec2.New(creds, c.Region, nil)
log.Println("[INFO] Initializing ELB connection") log.Println("[INFO] Initializing ELB connection")
client.elbconn = elb.New(creds, c.Region, nil) client.elbconn = elb.New(creds, c.Region, nil)
log.Println("[INFO] Initializing AutoScaling connection") log.Println("[INFO] Initializing AutoScaling connection")

View File

@ -58,6 +58,7 @@ func Provider() terraform.ResourceProvider {
"aws_launch_configuration": resourceAwsLaunchConfiguration(), "aws_launch_configuration": resourceAwsLaunchConfiguration(),
"aws_main_route_table_association": resourceAwsMainRouteTableAssociation(), "aws_main_route_table_association": resourceAwsMainRouteTableAssociation(),
"aws_network_acl": resourceAwsNetworkAcl(), "aws_network_acl": resourceAwsNetworkAcl(),
"aws_network_interface": resourceAwsNetworkInterface(),
"aws_route53_record": resourceAwsRoute53Record(), "aws_route53_record": resourceAwsRoute53Record(),
"aws_route53_zone": resourceAwsRoute53Zone(), "aws_route53_zone": resourceAwsRoute53Zone(),
"aws_route_table": resourceAwsRouteTable(), "aws_route_table": resourceAwsRouteTable(),

View File

@ -0,0 +1,119 @@
package aws
import (
//"bytes"
//"crypto/sha1"
//"encoding/hex"
"fmt"
"log"
//"strconv"
//"strings"
//"time"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/aws-sdk-go/gen/ec2"
)
func resourceAwsNetworkInterface() *schema.Resource {
return &schema.Resource{
Create: resourceAwsNetworkInterfaceCreate,
Read: resourceAwsNetworkInterfaceRead,
Update: resourceAwsNetworkInterfaceUpdate,
Delete: resourceAwsNetworkInterfaceDelete,
Schema: map[string]*schema.Schema{
"subnet_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"private_ips": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int {
return hashcode.String(v.(string))
},
},
"source_dest_check": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"security_groups": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int {
return hashcode.String(v.(string))
},
},
"tags": tagsSchema(),
},
}
}
func resourceAwsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn2
request := &ec2.CreateNetworkInterfaceRequest{
Description: aws.String("xxx"),
Groups: expandStringList(d.Get("security_groups").(*schema.Set).List()),
SubnetID: aws.String(d.Get("subnet_id").(string)),
}
log.Printf("[DEBUG] Creating network interface")
resp, err := ec2conn.CreateNetworkInterface(request)
if err != nil {
return fmt.Errorf("Error creating ENI: %s", err)
}
new_interface_id := *resp.NetworkInterface.NetworkInterfaceID
d.SetId(new_interface_id)
// chain to update here
return nil
}
func resourceAwsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn2
describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesRequest{
}
describeResp, err := ec2conn.DescribeNetworkInterfaces(describe_network_interfaces_request)
if err != nil {
return nil
}
if describeResp != nil {
return nil
}
return nil
}
func resourceAwsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}
func resourceAwsNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}
// InstanceStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// an EC2 instance.
func NetworkInterfaceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRefreshFunc {
return nil
}