github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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  }
    47  
    48  resource "aws_subnet" "foo" {
    49      vpc_id = "${aws_vpc.foo.id}"
    50      cidr_block = "172.16.10.0/24"
    51      availability_zone = "us-west-2a"
    52  }
    53  
    54  resource "aws_security_group" "foo" {
    55    vpc_id = "${aws_vpc.foo.id}"
    56    description = "foo"
    57    name = "foo-%d"
    58  
    59          egress {
    60                  from_port = 0
    61                  to_port = 0
    62                  protocol = "tcp"
    63                  cidr_blocks = ["10.0.0.0/16"]
    64          }
    65  }
    66  
    67  resource "aws_network_interface" "bar" {
    68      subnet_id = "${aws_subnet.foo.id}"
    69      private_ips = ["172.16.10.100"]
    70      security_groups = ["${aws_security_group.foo.id}"]
    71      description = "Managed by Terraform"
    72      tags {
    73          Name = "bar_interface"
    74      }
    75  }
    76  
    77  resource "aws_instance" "foo" {
    78      ami = "ami-c5eabbf5"
    79      instance_type = "t2.micro"
    80      subnet_id = "${aws_subnet.foo.id}"
    81      tags {
    82          Name = "foo-%d"
    83      }
    84  }
    85  
    86  resource "aws_network_interface_attachment" "test" {
    87    device_index = 1
    88    instance_id = "${aws_instance.foo.id}"
    89    network_interface_id = "${aws_network_interface.bar.id}"
    90  }
    91  `, rInt, rInt)
    92  }