github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_image_list_entry_test.go (about) 1 package opc 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/go-oracle-terraform/compute" 8 "github.com/hashicorp/terraform/helper/acctest" 9 "github.com/hashicorp/terraform/helper/resource" 10 "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func TestAccOPCImageListEntry_Basic(t *testing.T) { 14 ri := acctest.RandInt() 15 config := fmt.Sprintf(testAccImageListEntry_basic, ri) 16 17 resource.Test(t, resource.TestCase{ 18 PreCheck: func() { testAccPreCheck(t) }, 19 Providers: testAccProviders, 20 CheckDestroy: testAccCheckImageListEntryDestroy, 21 Steps: []resource.TestStep{ 22 { 23 Config: config, 24 Check: testAccCheckImageListEntryExists, 25 }, 26 }, 27 }) 28 } 29 30 func TestAccOPCImageListEntry_Complete(t *testing.T) { 31 ri := acctest.RandInt() 32 config := fmt.Sprintf(testAccImageListEntry_Complete, ri) 33 34 resource.Test(t, resource.TestCase{ 35 PreCheck: func() { testAccPreCheck(t) }, 36 Providers: testAccProviders, 37 CheckDestroy: testAccCheckImageListEntryDestroy, 38 Steps: []resource.TestStep{ 39 { 40 Config: config, 41 Check: testAccCheckImageListEntryExists, 42 }, 43 }, 44 }) 45 } 46 47 func TestAccOPCImageListEntry_CompleteExpanded(t *testing.T) { 48 ri := acctest.RandInt() 49 config := fmt.Sprintf(testAccImageListEntry_CompleteExpanded, ri) 50 51 resource.Test(t, resource.TestCase{ 52 PreCheck: func() { testAccPreCheck(t) }, 53 Providers: testAccProviders, 54 CheckDestroy: testAccCheckImageListEntryDestroy, 55 Steps: []resource.TestStep{ 56 { 57 Config: config, 58 Check: testAccCheckImageListEntryExists, 59 }, 60 }, 61 }) 62 } 63 64 func testAccCheckImageListEntryExists(s *terraform.State) error { 65 client := testAccProvider.Meta().(*compute.Client).ImageListEntries() 66 67 for _, rs := range s.RootModule().Resources { 68 if rs.Type != "opc_compute_image_list_entry" { 69 continue 70 } 71 72 name, version, err := parseOPCImageListEntryID(rs.Primary.ID) 73 if err != nil { 74 return fmt.Errorf("Error parsing the Image List ID: '%s': %+v", rs.Primary.ID, err) 75 } 76 77 input := compute.GetImageListEntryInput{ 78 Name: *name, 79 Version: *version, 80 } 81 82 if _, err := client.GetImageListEntry(&input); err != nil { 83 return fmt.Errorf("Error retrieving state of Image List Entry %s: %s", input.Name, err) 84 } 85 } 86 87 return nil 88 } 89 90 func testAccCheckImageListEntryDestroy(s *terraform.State) error { 91 client := testAccProvider.Meta().(*compute.Client).ImageListEntries() 92 93 for _, rs := range s.RootModule().Resources { 94 if rs.Type != "opc_compute_image_list_entry" { 95 continue 96 } 97 98 name, version, err := parseOPCImageListEntryID(rs.Primary.ID) 99 if err != nil { 100 return fmt.Errorf("Error parsing the Image List ID: %+v", err) 101 } 102 103 input := compute.GetImageListEntryInput{ 104 Name: *name, 105 Version: *version, 106 } 107 if info, err := client.GetImageListEntry(&input); err == nil { 108 return fmt.Errorf("Image List Entry %s still exists: %#v", input.Name, info) 109 } 110 } 111 112 return nil 113 } 114 115 var testAccImageListEntry_basic = ` 116 resource "opc_compute_image_list" "test" { 117 name = "test-acc-image-list-entry-basic-%d" 118 description = "Acceptance Test TestAccOPCImageListEntry_Basic" 119 default = 1 120 } 121 122 resource "opc_compute_image_list_entry" "test" { 123 name = "${opc_compute_image_list.test.name}" 124 machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ] 125 version = 1 126 } 127 ` 128 129 var testAccImageListEntry_Complete = ` 130 resource "opc_compute_image_list" "test" { 131 name = "test-acc-image-list-entry-basic-%d" 132 description = "Acceptance Test TestAccOPCImageListEntry_Basic" 133 default = 1 134 } 135 136 resource "opc_compute_image_list_entry" "test" { 137 name = "${opc_compute_image_list.test.name}" 138 machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ] 139 attributes = "{\"hello\":\"world\"}" 140 version = 1 141 } 142 ` 143 144 var testAccImageListEntry_CompleteExpanded = ` 145 resource "opc_compute_image_list" "test" { 146 name = "test-acc-image-list-entry-basic-%d" 147 description = "Acceptance Test TestAccOPCImageListEntry_Basic" 148 default = 1 149 } 150 151 resource "opc_compute_image_list_entry" "test" { 152 name = "${opc_compute_image_list.test.name}" 153 machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ] 154 attributes = <<JSON 155 { 156 "hello": "world" 157 } 158 JSON 159 version = 1 160 } 161 `