github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/opc/data_source_network_interface_test.go (about)

     1  package opc
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/acctest"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccOPCDataSourceNetworkInterface_basic(t *testing.T) {
    12  	rInt := acctest.RandInt()
    13  	resName := "data.opc_compute_network_interface.test"
    14  
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck:  func() { testAccPreCheck(t) },
    17  		Providers: testAccProviders,
    18  		Steps: []resource.TestStep{
    19  			{
    20  				Config: testAccDataSourceNetworkInterfaceBasic(rInt),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr(resName, "ip_network", fmt.Sprintf("testing-ip-network-%d", rInt)),
    23  					resource.TestCheckResourceAttr(resName, "vnic", fmt.Sprintf("ip-network-test-%d", rInt)),
    24  					resource.TestCheckResourceAttr(resName, "shared_network", "false"),
    25  				),
    26  			},
    27  		},
    28  	})
    29  }
    30  
    31  func TestAccOPCDataSourceNetworkInterface_sharedNetwork(t *testing.T) {
    32  	rInt := acctest.RandInt()
    33  	resName := "data.opc_compute_network_interface.test"
    34  
    35  	resource.Test(t, resource.TestCase{
    36  		PreCheck:  func() { testAccPreCheck(t) },
    37  		Providers: testAccProviders,
    38  		Steps: []resource.TestStep{
    39  			{
    40  				Config: testAccDataSourceNetworkInterfaceShared(rInt),
    41  				Check: resource.ComposeTestCheckFunc(
    42  					resource.TestCheckResourceAttr(resName, "nat.#", "1"),
    43  					resource.TestCheckResourceAttr(resName, "shared_network", "true"),
    44  					resource.TestCheckResourceAttr(resName, "sec_lists.#", "1"),
    45  					resource.TestCheckResourceAttr(resName, "name_servers.#", "0"),
    46  					resource.TestCheckResourceAttr(resName, "vnic_sets.#", "0"),
    47  				),
    48  			},
    49  		},
    50  	})
    51  }
    52  
    53  func testAccDataSourceNetworkInterfaceBasic(rInt int) string {
    54  	return fmt.Sprintf(`
    55  resource "opc_compute_ip_network" "foo" {
    56    name = "testing-ip-network-%d"
    57    description = "testing-ip-network-instance"
    58    ip_address_prefix = "10.1.12.0/24"
    59  }
    60  
    61  resource "opc_compute_instance" "test" {
    62    name = "test-%d"
    63    label = "test"
    64    shape = "oc3"
    65    image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
    66    networking_info {
    67      index = 0
    68      ip_network = "${opc_compute_ip_network.foo.id}"
    69      vnic = "ip-network-test-%d"
    70      shared_network = false
    71    }
    72  }
    73  
    74  data "opc_compute_network_interface" "test" {
    75    instance_name = "${opc_compute_instance.test.name}"
    76    instance_id = "${opc_compute_instance.test.id}"
    77    interface = "eth0"
    78  }`, rInt, rInt, rInt)
    79  }
    80  
    81  func testAccDataSourceNetworkInterfaceShared(rInt int) string {
    82  	return fmt.Sprintf(`
    83  resource "opc_compute_instance" "test" {
    84    name = "test-%d"
    85    label = "test"
    86    shape = "oc3"
    87    image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
    88    tags = ["tag1", "tag2"]
    89    networking_info {
    90      index = 0
    91      nat = ["ippool:/oracle/public/ippool"]
    92      shared_network = true
    93    }
    94  }
    95  
    96  data "opc_compute_network_interface" "test" {
    97    instance_name = "${opc_compute_instance.test.name}"
    98    instance_id = "${opc_compute_instance.test.id}"
    99    interface = "eth0"
   100  }`, rInt)
   101  }