github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/plan.go (about)

     1  package terraform
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/gob"
     6  	"fmt"
     7  	"io"
     8  
     9  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs"
    10  	"github.com/zclconf/go-cty/cty"
    11  )
    12  
    13  func init() {
    14  	gob.Register(make([]interface{}, 0))
    15  	gob.Register(make([]map[string]interface{}, 0))
    16  	gob.Register(make(map[string]interface{}))
    17  	gob.Register(make(map[string]string))
    18  }
    19  
    20  // Plan represents a single Terraform execution plan, which contains
    21  // all the information necessary to make an infrastructure change.
    22  //
    23  // A plan has to contain basically the entire state of the world
    24  // necessary to make a change: the state, diff, config, backend config, etc.
    25  // This is so that it can run alone without any other data.
    26  type Plan struct {
    27  	// Diff describes the resource actions that must be taken when this
    28  	// plan is applied.
    29  	Diff *Diff
    30  
    31  	// Config represents the entire configuration that was present when this
    32  	// plan was created.
    33  	Config *configs.Config
    34  
    35  	// State is the Terraform state that was current when this plan was
    36  	// created.
    37  	//
    38  	// It is not allowed to apply a plan that has a stale state, since its
    39  	// diff could be outdated.
    40  	State *State
    41  
    42  	// Vars retains the variables that were set when creating the plan, so
    43  	// that the same variables can be applied during apply.
    44  	Vars map[string]cty.Value
    45  
    46  	// Targets, if non-empty, contains a set of resource address strings that
    47  	// identify graph nodes that were selected as targets for plan.
    48  	//
    49  	// When targets are set, any graph node that is not directly targeted or
    50  	// indirectly targeted via dependencies is excluded from the graph.
    51  	Targets []string
    52  
    53  	// TerraformVersion is the version of Terraform that was used to create
    54  	// this plan.
    55  	//
    56  	// It is not allowed to apply a plan created with a different version of
    57  	// Terraform, since the other fields of this structure may be interpreted
    58  	// in different ways between versions.
    59  	TerraformVersion string
    60  
    61  	// ProviderSHA256s is a map giving the SHA256 hashes of the exact binaries
    62  	// used as plugins for each provider during plan.
    63  	//
    64  	// These must match between plan and apply to ensure that the diff is
    65  	// correctly interpreted, since different provider versions may have
    66  	// different attributes or attribute value constraints.
    67  	ProviderSHA256s map[string][]byte
    68  
    69  	// Backend is the backend that this plan should use and store data with.
    70  	Backend *BackendState
    71  
    72  	// Destroy indicates that this plan was created for a full destroy operation
    73  	Destroy bool
    74  }
    75  
    76  func (p *Plan) String() string {
    77  	buf := new(bytes.Buffer)
    78  	buf.WriteString("DIFF:\n\n")
    79  	buf.WriteString(p.Diff.String())
    80  	buf.WriteString("\n\nSTATE:\n\n")
    81  	buf.WriteString(p.State.String())
    82  	return buf.String()
    83  }
    84  
    85  // ReadPlan reads a plan structure out of a reader in the format that
    86  // was written by WritePlan.
    87  func ReadPlan(src io.Reader) (*Plan, error) {
    88  	return nil, fmt.Errorf("terraform.ReadPlan is no longer in use; use planfile.Open instead")
    89  }
    90  
    91  // WritePlan writes a plan somewhere in a binary format.
    92  func WritePlan(d *Plan, dst io.Writer) error {
    93  	return fmt.Errorf("terraform.WritePlan is no longer in use; use planfile.Create instead")
    94  }