aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/terraform/plan.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/plan.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/terraform/plan.go51
1 files changed, 47 insertions, 4 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/plan.go b/vendor/github.com/hashicorp/terraform/terraform/plan.go
index ea08845..51d6652 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/plan.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/plan.go
@@ -6,6 +6,7 @@ import (
6 "errors" 6 "errors"
7 "fmt" 7 "fmt"
8 "io" 8 "io"
9 "log"
9 "sync" 10 "sync"
10 11
11 "github.com/hashicorp/terraform/config/module" 12 "github.com/hashicorp/terraform/config/module"
@@ -31,6 +32,9 @@ type Plan struct {
31 Vars map[string]interface{} 32 Vars map[string]interface{}
32 Targets []string 33 Targets []string
33 34
35 TerraformVersion string
36 ProviderSHA256s map[string][]byte
37
34 // Backend is the backend that this plan should use and store data with. 38 // Backend is the backend that this plan should use and store data with.
35 Backend *BackendState 39 Backend *BackendState
36 40
@@ -40,19 +44,58 @@ type Plan struct {
40// Context returns a Context with the data encapsulated in this plan. 44// Context returns a Context with the data encapsulated in this plan.
41// 45//
42// The following fields in opts are overridden by the plan: Config, 46// The following fields in opts are overridden by the plan: Config,
43// Diff, State, Variables. 47// Diff, Variables.
48//
49// If State is not provided, it is set from the plan. If it _is_ provided,
50// it must be Equal to the state stored in plan, but may have a newer
51// serial.
44func (p *Plan) Context(opts *ContextOpts) (*Context, error) { 52func (p *Plan) Context(opts *ContextOpts) (*Context, error) {
53 var err error
54 opts, err = p.contextOpts(opts)
55 if err != nil {
56 return nil, err
57 }
58 return NewContext(opts)
59}
60
61// contextOpts mutates the given base ContextOpts in place to use input
62// objects obtained from the receiving plan.
63func (p *Plan) contextOpts(base *ContextOpts) (*ContextOpts, error) {
64 opts := base
65
45 opts.Diff = p.Diff 66 opts.Diff = p.Diff
46 opts.Module = p.Module 67 opts.Module = p.Module
47 opts.State = p.State
48 opts.Targets = p.Targets 68 opts.Targets = p.Targets
69 opts.ProviderSHA256s = p.ProviderSHA256s
70
71 if opts.State == nil {
72 opts.State = p.State
73 } else if !opts.State.Equal(p.State) {
74 // Even if we're overriding the state, it should be logically equal
75 // to what's in plan. The only valid change to have made by the time
76 // we get here is to have incremented the serial.
77 //
78 // Due to the fact that serialization may change the representation of
79 // the state, there is little chance that these aren't actually equal.
80 // Log the error condition for reference, but continue with the state
81 // we have.
82 log.Println("[WARNING] Plan state and ContextOpts state are not equal")
83 }
84
85 thisVersion := VersionString()
86 if p.TerraformVersion != "" && p.TerraformVersion != thisVersion {
87 return nil, fmt.Errorf(
88 "plan was created with a different version of Terraform (created with %s, but running %s)",
89 p.TerraformVersion, thisVersion,
90 )
91 }
49 92
50 opts.Variables = make(map[string]interface{}) 93 opts.Variables = make(map[string]interface{})
51 for k, v := range p.Vars { 94 for k, v := range p.Vars {
52 opts.Variables[k] = v 95 opts.Variables[k] = v
53 } 96 }
54 97
55 return NewContext(opts) 98 return opts, nil
56} 99}
57 100
58func (p *Plan) String() string { 101func (p *Plan) String() string {
@@ -86,7 +129,7 @@ func (p *Plan) init() {
86// the ability in the future to change the file format if we want for any 129// the ability in the future to change the file format if we want for any
87// reason. 130// reason.
88const planFormatMagic = "tfplan" 131const planFormatMagic = "tfplan"
89const planFormatVersion byte = 1 132const planFormatVersion byte = 2
90 133
91// ReadPlan reads a plan structure out of a reader in the format that 134// ReadPlan reads a plan structure out of a reader in the format that
92// was written by WritePlan. 135// was written by WritePlan.