github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/aws/resource_aws_network_interface_attacment_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/service/ec2"
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  )
    11  
    12  func TestAccAWSNetworkInterfaceAttachment_basic(t *testing.T) {
    13  	var conf ec2.NetworkInterface
    14  	rInt := acctest.RandInt()
    15  
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck:      func() { testAccPreCheck(t) },
    18  		IDRefreshName: "aws_network_interface.bar",
    19  		Providers:     testAccProviders,
    20  		CheckDestroy:  testAccCheckAWSENIDestroy,
    21  		Steps: []resource.TestStep{
    22  			{
    23  				Config: testAccAWSNetworkInterfaceAttachmentConfig_basic(rInt),
    24  				Check: resource.ComposeTestCheckFunc(
    25  					testAccCheckAWSENIExists("aws_network_interface.bar", &conf),
    26  					resource.TestCheckResourceAttr(
    27  						"aws_network_interface_attachment.test", "device_index", "1"),
    28  					resource.TestCheckResourceAttrSet(
    29  						"aws_network_interface_attachment.test", "instance_id"),
    30  					resource.TestCheckResourceAttrSet(
    31  						"aws_network_interface_attachment.test", "network_interface_id"),
    32  					resource.TestCheckResourceAttrSet(
    33  						"aws_network_interface_attachment.test", "attachment_id"),
    34  					resource.TestCheckResourceAttrSet(
    35  						"aws_network_interface_attachment.test", "status"),
    36  				),
    37  			},
    38  		},
    39  	})
    40  }
    41  
    42  func testAccAWSNetworkInterfaceAttachmentConfig_basic(rInt int) string {
    43  	return fmt.Sprintf(`
    44  resource "aws_vpc" "foo" {
    45      cidr_block = "172.16.0.0/16"
    46  		tags {
    47  			Name = "testAccAWSNetworkInterfaceAttachmentConfig_basic"
    48  		}
    49  }
    50  
    51  resource "aws_subnet" "foo" {
    52      vpc_id = "${aws_vpc.foo.id}"
    53      cidr_block = "172.16.10.0/24"
    54      availability_zone = "us-west-2a"
    55  }
    56  
    57  resource "aws_security_group" "foo" {
    58    vpc_id = "${aws_vpc.foo.id}"
    59    description = "foo"
    60    name = "foo-%d"
    61  
    62          egress {
    63                  from_port = 0
    64                  to_port = 0
    65                  protocol = "tcp"
    66                  cidr_blocks = ["10.0.0.0/16"]
    67          }
    68  }
    69  
    70  resource "aws_network_interface" "bar" {
    71      subnet_id = "${aws_subnet.foo.id}"
    72      private_ips = ["172.16.10.100"]
    73      security_groups = ["${aws_security_group.foo.id}"]
    74      description = "Managed by Terraform"
    75      tags {
    76          Name = "bar_interface"
    77      }
    78  }
    79  
    80  resource "aws_instance" "foo" {
    81      ami = "ami-c5eabbf5"
    82      instance_type = "t2.micro"
    83      subnet_id = "${aws_subnet.foo.id}"
    84      tags {
    85          Name = "foo-%d"
    86      }
    87  }
    88  
    89  resource "aws_network_interface_attachment" "test" {
    90    device_index = 1
    91    instance_id = "${aws_instance.foo.id}"
    92    network_interface_id = "${aws_network_interface.bar.id}"
    93  }
    94  `, rInt, rInt)
    95  }