github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/data_source_virtual_nic.go (about) 1 package opc 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/go-oracle-terraform/compute" 7 "github.com/hashicorp/terraform/helper/schema" 8 ) 9 10 func dataSourceVNIC() *schema.Resource { 11 return &schema.Resource{ 12 Read: dataSourceVNICRead, 13 14 Schema: map[string]*schema.Schema{ 15 "name": { 16 Type: schema.TypeString, 17 Required: true, 18 }, 19 20 "description": { 21 Type: schema.TypeString, 22 Computed: true, 23 }, 24 25 "mac_address": { 26 Type: schema.TypeString, 27 Computed: true, 28 }, 29 30 "tags": tagsComputedSchema(), 31 32 "transit_flag": { 33 Type: schema.TypeBool, 34 Computed: true, 35 }, 36 37 "uri": { 38 Type: schema.TypeString, 39 Computed: true, 40 }, 41 }, 42 } 43 } 44 45 func dataSourceVNICRead(d *schema.ResourceData, meta interface{}) error { 46 client := meta.(*compute.Client).VirtNICs() 47 48 name := d.Get("name").(string) 49 50 input := &compute.GetVirtualNICInput{ 51 Name: name, 52 } 53 54 vnic, err := client.GetVirtualNIC(input) 55 if err != nil { 56 if compute.WasNotFoundError(err) { 57 d.SetId("") 58 return nil 59 } 60 return fmt.Errorf("Error reading vnic %s: %s", name, err) 61 } 62 63 d.SetId(name) 64 d.Set("description", vnic.Description) 65 d.Set("mac_address", vnic.MACAddress) 66 d.Set("transit_flag", vnic.TransitFlag) 67 d.Set("uri", vnic.Uri) 68 if err := setStringList(d, "tags", vnic.Tags); err != nil { 69 return err 70 } 71 return nil 72 }