10 "github.com/zclconf/go-cty/cty"
12 "github.com/hashicorp/terraform/configs"
16 gob.Register(make([]interface{}, 0))
17 gob.Register(make([]map[string]interface{}, 0))
18 gob.Register(make(map[string]interface{}))
19 gob.Register(make(map[string]string))
22 // Plan represents a single Terraform execution plan, which contains
23 // all the information necessary to make an infrastructure change.
25 // A plan has to contain basically the entire state of the world
26 // necessary to make a change: the state, diff, config, backend config, etc.
27 // This is so that it can run alone without any other data.
29 // Diff describes the resource actions that must be taken when this
33 // Config represents the entire configuration that was present when this
35 Config *configs.Config
37 // State is the Terraform state that was current when this plan was
40 // It is not allowed to apply a plan that has a stale state, since its
41 // diff could be outdated.
44 // Vars retains the variables that were set when creating the plan, so
45 // that the same variables can be applied during apply.
46 Vars map[string]cty.Value
48 // Targets, if non-empty, contains a set of resource address strings that
49 // identify graph nodes that were selected as targets for plan.
51 // When targets are set, any graph node that is not directly targeted or
52 // indirectly targeted via dependencies is excluded from the graph.
55 // TerraformVersion is the version of Terraform that was used to create
58 // It is not allowed to apply a plan created with a different version of
59 // Terraform, since the other fields of this structure may be interpreted
60 // in different ways between versions.
61 TerraformVersion string
63 // ProviderSHA256s is a map giving the SHA256 hashes of the exact binaries
64 // used as plugins for each provider during plan.
66 // These must match between plan and apply to ensure that the diff is
67 // correctly interpreted, since different provider versions may have
68 // different attributes or attribute value constraints.
69 ProviderSHA256s map[string][]byte
71 // Backend is the backend that this plan should use and store data with.
74 // Destroy indicates that this plan was created for a full destroy operation
80 func (p *Plan) String() string {
81 buf := new(bytes.Buffer)
82 buf.WriteString("DIFF:\n\n")
83 buf.WriteString(p.Diff.String())
84 buf.WriteString("\n\nSTATE:\n\n")
85 buf.WriteString(p.State.String())
89 func (p *Plan) init() {
102 p.Vars = make(map[string]cty.Value)
107 // The format byte is prefixed into the plan file format so that we have
108 // the ability in the future to change the file format if we want for any
110 const planFormatMagic = "tfplan"
111 const planFormatVersion byte = 2
113 // ReadPlan reads a plan structure out of a reader in the format that
114 // was written by WritePlan.
115 func ReadPlan(src io.Reader) (*Plan, error) {
116 return nil, fmt.Errorf("terraform.ReadPlan is no longer in use; use planfile.Open instead")
119 // WritePlan writes a plan somewhere in a binary format.
120 func WritePlan(d *Plan, dst io.Writer) error {
121 return fmt.Errorf("terraform.WritePlan is no longer in use; use planfile.Create instead")