github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_image_list.go (about) 1 package opc 2 3 import ( 4 "github.com/hashicorp/go-oracle-terraform/compute" 5 "github.com/hashicorp/terraform/helper/schema" 6 ) 7 8 func resourceOPCImageList() *schema.Resource { 9 return &schema.Resource{ 10 Create: resourceOPCImageListCreate, 11 Read: resourceOPCImageListRead, 12 Update: resourceOPCImageListUpdate, 13 Delete: resourceOPCImageListDelete, 14 Importer: &schema.ResourceImporter{ 15 State: schema.ImportStatePassthrough, 16 }, 17 18 Schema: map[string]*schema.Schema{ 19 "name": { 20 Type: schema.TypeString, 21 Required: true, 22 ForceNew: true, 23 }, 24 "description": { 25 Type: schema.TypeString, 26 Required: true, 27 }, 28 "default": { 29 Type: schema.TypeInt, 30 Optional: true, 31 Default: 1, 32 }, 33 }, 34 } 35 } 36 37 func resourceOPCImageListCreate(d *schema.ResourceData, meta interface{}) error { 38 client := meta.(*compute.Client).ImageList() 39 40 name := d.Get("name").(string) 41 42 createInput := &compute.CreateImageListInput{ 43 Name: name, 44 Description: d.Get("description").(string), 45 Default: d.Get("default").(int), 46 } 47 48 createResult, err := client.CreateImageList(createInput) 49 if err != nil { 50 return err 51 } 52 53 d.SetId(createResult.Name) 54 55 return resourceOPCImageListRead(d, meta) 56 } 57 58 func resourceOPCImageListUpdate(d *schema.ResourceData, meta interface{}) error { 59 client := meta.(*compute.Client).ImageList() 60 61 name := d.Id() 62 63 updateInput := &compute.UpdateImageListInput{ 64 Name: name, 65 Description: d.Get("description").(string), 66 Default: d.Get("default").(int), 67 } 68 69 _, err := client.UpdateImageList(updateInput) 70 if err != nil { 71 return err 72 } 73 74 return resourceOPCImageListRead(d, meta) 75 } 76 77 func resourceOPCImageListRead(d *schema.ResourceData, meta interface{}) error { 78 client := meta.(*compute.Client).ImageList() 79 80 getInput := &compute.GetImageListInput{ 81 Name: d.Id(), 82 } 83 getResult, err := client.GetImageList(getInput) 84 if err != nil { 85 return err 86 } 87 88 d.Set("name", getResult.Name) 89 d.Set("description", getResult.Description) 90 d.Set("default", getResult.Default) 91 92 return nil 93 } 94 95 func resourceOPCImageListDelete(d *schema.ResourceData, meta interface{}) error { 96 client := meta.(*compute.Client).ImageList() 97 98 deleteInput := &compute.DeleteImageListInput{ 99 Name: d.Id(), 100 } 101 err := client.DeleteImageList(deleteInput) 102 if err != nil { 103 return err 104 } 105 106 return nil 107 }