github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/builtin/providers/test/resource_timeout_test.go (about) 1 package test 2 3 import ( 4 "regexp" 5 "strings" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 ) 10 11 func TestResourceTimeout_create(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_timeout" "foo" { 19 create_delay = "2s" 20 timeouts { 21 create = "1s" 22 } 23 } 24 `), 25 ExpectError: regexp.MustCompile("timeout while creating resource"), 26 }, 27 }, 28 }) 29 } 30 31 // start with the default, then modify it 32 func TestResourceTimeout_defaults(t *testing.T) { 33 resource.UnitTest(t, resource.TestCase{ 34 Providers: testAccProviders, 35 CheckDestroy: testAccCheckResourceDestroy, 36 Steps: []resource.TestStep{ 37 resource.TestStep{ 38 Config: strings.TrimSpace(` 39 resource "test_resource_timeout" "foo" { 40 update_delay = "1ms" 41 } 42 `), 43 }, 44 resource.TestStep{ 45 Config: strings.TrimSpace(` 46 resource "test_resource_timeout" "foo" { 47 update_delay = "2ms" 48 timeouts { 49 update = "3s" 50 } 51 } 52 `), 53 }, 54 resource.TestStep{ 55 Config: strings.TrimSpace(` 56 resource "test_resource_timeout" "foo" { 57 update_delay = "2s" 58 delete_delay = "2s" 59 timeouts { 60 delete = "3s" 61 update = "3s" 62 } 63 } 64 `), 65 }, 66 // delete "foo" 67 resource.TestStep{ 68 Config: strings.TrimSpace(` 69 resource "test_resource_timeout" "bar" { 70 } 71 `), 72 }, 73 }, 74 }) 75 } 76 77 func TestResourceTimeout_delete(t *testing.T) { 78 // If the delete timeout isn't saved until destroy, the cleanup here will 79 // fail because the default is only 20m. 80 resource.UnitTest(t, resource.TestCase{ 81 Providers: testAccProviders, 82 CheckDestroy: testAccCheckResourceDestroy, 83 Steps: []resource.TestStep{ 84 resource.TestStep{ 85 Config: strings.TrimSpace(` 86 resource "test_resource_timeout" "foo" { 87 delete_delay = "25m" 88 timeouts { 89 delete = "30m" 90 } 91 } 92 `), 93 }, 94 }, 95 }) 96 } 97 func TestResourceTimeout_update(t *testing.T) { 98 resource.UnitTest(t, resource.TestCase{ 99 Providers: testAccProviders, 100 CheckDestroy: testAccCheckResourceDestroy, 101 Steps: []resource.TestStep{ 102 resource.TestStep{ 103 Config: strings.TrimSpace(` 104 resource "test_resource_timeout" "foo" { 105 update_delay = "1s" 106 timeouts { 107 update = "1s" 108 } 109 } 110 `), 111 }, 112 resource.TestStep{ 113 Config: strings.TrimSpace(` 114 resource "test_resource_timeout" "foo" { 115 update_delay = "2s" 116 timeouts { 117 update = "1s" 118 } 119 } 120 `), 121 ExpectError: regexp.MustCompile("timeout while updating resource"), 122 }, 123 }, 124 }) 125 } 126 127 func TestResourceTimeout_read(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_timeout" "foo" { 135 } 136 `), 137 }, 138 resource.TestStep{ 139 Config: strings.TrimSpace(` 140 resource "test_resource_timeout" "foo" { 141 read_delay = "30m" 142 } 143 `), 144 ExpectError: regexp.MustCompile("timeout while reading resource"), 145 }, 146 // we need to remove the read_delay so that the resource can be 147 // destroyed in the final step, but expect an error here from the 148 // pre-existing delay. 149 resource.TestStep{ 150 Config: strings.TrimSpace(` 151 resource "test_resource_timeout" "foo" { 152 } 153 `), 154 ExpectError: regexp.MustCompile("timeout while reading resource"), 155 }, 156 }, 157 }) 158 }