aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go41
1 files changed, 31 insertions, 10 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go b/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go
index 537a11c..033f126 100644
--- a/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go
+++ b/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go
@@ -1,10 +1,12 @@
1package resource 1package resource
2 2
3import ( 3import (
4 "errors"
4 "fmt" 5 "fmt"
5 "log" 6 "log"
6 "strings" 7 "strings"
7 8
9 "github.com/hashicorp/errwrap"
8 "github.com/hashicorp/terraform/terraform" 10 "github.com/hashicorp/terraform/terraform"
9) 11)
10 12
@@ -20,6 +22,14 @@ func testStep(
20 opts terraform.ContextOpts, 22 opts terraform.ContextOpts,
21 state *terraform.State, 23 state *terraform.State,
22 step TestStep) (*terraform.State, error) { 24 step TestStep) (*terraform.State, error) {
25 // Pre-taint any resources that have been defined in Taint, as long as this
26 // is not a destroy step.
27 if !step.Destroy {
28 if err := testStepTaint(state, step); err != nil {
29 return state, err
30 }
31 }
32
23 mod, err := testModule(opts, step) 33 mod, err := testModule(opts, step)
24 if err != nil { 34 if err != nil {
25 return state, err 35 return state, err
@@ -33,17 +43,12 @@ func testStep(
33 if err != nil { 43 if err != nil {
34 return state, fmt.Errorf("Error initializing context: %s", err) 44 return state, fmt.Errorf("Error initializing context: %s", err)
35 } 45 }
36 if ws, es := ctx.Validate(); len(ws) > 0 || len(es) > 0 { 46 if diags := ctx.Validate(); len(diags) > 0 {
37 if len(es) > 0 { 47 if diags.HasErrors() {
38 estrs := make([]string, len(es)) 48 return nil, errwrap.Wrapf("config is invalid: {{err}}", diags.Err())
39 for i, e := range es {
40 estrs[i] = e.Error()
41 }
42 return state, fmt.Errorf(
43 "Configuration is invalid.\n\nWarnings: %#v\n\nErrors: %#v",
44 ws, estrs)
45 } 49 }
46 log.Printf("[WARN] Config warnings: %#v", ws) 50
51 log.Printf("[WARN] Config warnings:\n%s", diags)
47 } 52 }
48 53
49 // Refresh! 54 // Refresh!
@@ -158,3 +163,19 @@ func testStep(
158 // Made it here? Good job test step! 163 // Made it here? Good job test step!
159 return state, nil 164 return state, nil
160} 165}
166
167func testStepTaint(state *terraform.State, step TestStep) error {
168 for _, p := range step.Taint {
169 m := state.RootModule()
170 if m == nil {
171 return errors.New("no state")
172 }
173 rs, ok := m.Resources[p]
174 if !ok {
175 return fmt.Errorf("resource %q not found in state", p)
176 }
177 log.Printf("[WARN] Test: Explicitly tainting resource %q", p)
178 rs.Taint()
179 }
180 return nil
181}