github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/builtin/providers/test/resource_test.go (about) 1 package test 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestResource_basic(t *testing.T) { 12 resource.UnitTest(t, resource.TestCase{ 13 Providers: testAccProviders, 14 CheckDestroy: testAccCheckResourceDestroy, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: strings.TrimSpace(` 18 resource "test_resource" "foo" { 19 required = "yep" 20 } 21 `), 22 Check: func(s *terraform.State) error { 23 return nil 24 }, 25 }, 26 }, 27 }) 28 } 29 30 // Targeted test in TestContext2Apply_ignoreChangesCreate 31 func TestResource_ignoreChangesRequired(t *testing.T) { 32 resource.UnitTest(t, resource.TestCase{ 33 Providers: testAccProviders, 34 CheckDestroy: testAccCheckResourceDestroy, 35 Steps: []resource.TestStep{ 36 resource.TestStep{ 37 Config: strings.TrimSpace(` 38 resource "test_resource" "foo" { 39 required = "yep" 40 lifecycle { 41 ignore_changes = ["required"] 42 } 43 } 44 `), 45 Check: func(s *terraform.State) error { 46 return nil 47 }, 48 }, 49 }, 50 }) 51 } 52 53 func TestResource_ignoreChangesEmpty(t *testing.T) { 54 resource.UnitTest(t, resource.TestCase{ 55 Providers: testAccProviders, 56 CheckDestroy: testAccCheckResourceDestroy, 57 Steps: []resource.TestStep{ 58 resource.TestStep{ 59 Config: strings.TrimSpace(` 60 resource "test_resource" "foo" { 61 required = "yep" 62 optional_force_new = "one" 63 lifecycle { 64 ignore_changes = [] 65 } 66 } 67 `), 68 Check: func(s *terraform.State) error { 69 return nil 70 }, 71 }, 72 resource.TestStep{ 73 Config: strings.TrimSpace(` 74 resource "test_resource" "foo" { 75 required = "yep" 76 optional_force_new = "two" 77 lifecycle { 78 ignore_changes = [] 79 } 80 } 81 `), 82 Check: func(s *terraform.State) error { 83 return nil 84 }, 85 }, 86 }, 87 }) 88 } 89 90 func TestResource_ignoreChangesForceNew(t *testing.T) { 91 resource.UnitTest(t, resource.TestCase{ 92 Providers: testAccProviders, 93 CheckDestroy: testAccCheckResourceDestroy, 94 Steps: []resource.TestStep{ 95 resource.TestStep{ 96 Config: strings.TrimSpace(` 97 resource "test_resource" "foo" { 98 required = "yep" 99 optional_force_new = "one" 100 lifecycle { 101 ignore_changes = ["optional_force_new"] 102 } 103 } 104 `), 105 Check: func(s *terraform.State) error { 106 return nil 107 }, 108 }, 109 resource.TestStep{ 110 Config: strings.TrimSpace(` 111 resource "test_resource" "foo" { 112 required = "yep" 113 optional_force_new = "two" 114 lifecycle { 115 ignore_changes = ["optional_force_new"] 116 } 117 } 118 `), 119 Check: func(s *terraform.State) error { 120 return nil 121 }, 122 }, 123 }, 124 }) 125 } 126 127 func TestResource_ignoreChangesMap(t *testing.T) { 128 resource.UnitTest(t, resource.TestCase{ 129 Providers: testAccProviders, 130 CheckDestroy: testAccCheckResourceDestroy, 131 Steps: []resource.TestStep{ 132 resource.TestStep{ 133 Config: strings.TrimSpace(` 134 resource "test_resource" "foo" { 135 required = "yep" 136 optional_computed_map { 137 foo = "bar" 138 } 139 lifecycle { 140 ignore_changes = ["optional_computed_map"] 141 } 142 } 143 `), 144 Check: func(s *terraform.State) error { 145 return nil 146 }, 147 }, 148 resource.TestStep{ 149 Config: strings.TrimSpace(` 150 resource "test_resource" "foo" { 151 required = "yep" 152 optional_computed_map { 153 foo = "bar" 154 no = "update" 155 } 156 lifecycle { 157 ignore_changes = ["optional_computed_map"] 158 } 159 } 160 `), 161 Check: func(s *terraform.State) error { 162 return nil 163 }, 164 }, 165 }, 166 }) 167 } 168 169 func testAccCheckResourceDestroy(s *terraform.State) error { 170 return nil 171 }