diff --git a/Makefile b/Makefile index fdb9ab3d6..af89fc04f 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ updatedeps: | xargs go list -f '{{join .Deps "\n"}}' \ | grep -v github.com/hashicorp/terraform \ | sort -u \ - | xargs go get -f -u -v + | xargs go get -u -v cover: @go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \ diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index a357e5b1d..9ec79d18c 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -11,6 +11,7 @@ import ( "github.com/mitchellh/goamz/ec2" 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/elb" "github.com/hashicorp/aws-sdk-go/gen/rds" @@ -27,6 +28,7 @@ type Config struct { type AWSClient struct { ec2conn *ec2.EC2 + ec2conn2 *awsec2.EC2 elbconn *elb.ELB autoscalingconn *autoscaling.AutoScaling s3conn *s3.S3 @@ -63,6 +65,7 @@ func (c *Config) Client() (interface{}, error) { log.Println("[INFO] Initializing EC2 connection") client.ec2conn = ec2.New(auth, region) + client.ec2conn2 = awsec2.New(creds, c.Region, nil) log.Println("[INFO] Initializing ELB connection") client.elbconn = elb.New(creds, c.Region, nil) log.Println("[INFO] Initializing AutoScaling connection") diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go index 0ab2919fd..3e37a0308 100644 --- a/builtin/providers/aws/provider.go +++ b/builtin/providers/aws/provider.go @@ -58,6 +58,7 @@ func Provider() terraform.ResourceProvider { "aws_launch_configuration": resourceAwsLaunchConfiguration(), "aws_main_route_table_association": resourceAwsMainRouteTableAssociation(), "aws_network_acl": resourceAwsNetworkAcl(), + "aws_network_interface": resourceAwsNetworkInterface(), "aws_route53_record": resourceAwsRoute53Record(), "aws_route53_zone": resourceAwsRoute53Zone(), "aws_route_table": resourceAwsRouteTable(), diff --git a/builtin/providers/aws/resource_aws_network_interface.go b/builtin/providers/aws/resource_aws_network_interface.go new file mode 100644 index 000000000..b4d23cd43 --- /dev/null +++ b/builtin/providers/aws/resource_aws_network_interface.go @@ -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 +} \ No newline at end of file