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

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform-plugin-sdk/internal/addrs"
     5  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs"
     6  	"github.com/hashicorp/terraform-plugin-sdk/internal/providers"
     7  )
     8  
     9  // ProviderEvalTree returns the evaluation tree for initializing and
    10  // configuring providers.
    11  func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNode {
    12  	var provider providers.Interface
    13  
    14  	addr := n.Addr
    15  	relAddr := addr.ProviderConfig
    16  
    17  	seq := make([]EvalNode, 0, 5)
    18  	seq = append(seq, &EvalInitProvider{
    19  		TypeName: relAddr.Type,
    20  		Addr:     addr.ProviderConfig,
    21  	})
    22  
    23  	// Input stuff
    24  	seq = append(seq, &EvalOpFilter{
    25  		Ops: []walkOperation{walkImport},
    26  		Node: &EvalSequence{
    27  			Nodes: []EvalNode{
    28  				&EvalGetProvider{
    29  					Addr:   addr,
    30  					Output: &provider,
    31  				},
    32  			},
    33  		},
    34  	})
    35  
    36  	seq = append(seq, &EvalOpFilter{
    37  		Ops: []walkOperation{walkValidate},
    38  		Node: &EvalSequence{
    39  			Nodes: []EvalNode{
    40  				&EvalGetProvider{
    41  					Addr:   addr,
    42  					Output: &provider,
    43  				},
    44  				&EvalValidateProvider{
    45  					Addr:     relAddr,
    46  					Provider: &provider,
    47  					Config:   config,
    48  				},
    49  			},
    50  		},
    51  	})
    52  
    53  	// Apply stuff
    54  	seq = append(seq, &EvalOpFilter{
    55  		Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
    56  		Node: &EvalSequence{
    57  			Nodes: []EvalNode{
    58  				&EvalGetProvider{
    59  					Addr:   addr,
    60  					Output: &provider,
    61  				},
    62  			},
    63  		},
    64  	})
    65  
    66  	// We configure on everything but validate, since validate may
    67  	// not have access to all the variables.
    68  	seq = append(seq, &EvalOpFilter{
    69  		Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
    70  		Node: &EvalSequence{
    71  			Nodes: []EvalNode{
    72  				&EvalConfigProvider{
    73  					Addr:     relAddr,
    74  					Provider: &provider,
    75  					Config:   config,
    76  				},
    77  			},
    78  		},
    79  	})
    80  
    81  	return &EvalSequence{Nodes: seq}
    82  }
    83  
    84  // CloseProviderEvalTree returns the evaluation tree for closing
    85  // provider connections that aren't needed anymore.
    86  func CloseProviderEvalTree(addr addrs.AbsProviderConfig) EvalNode {
    87  	return &EvalCloseProvider{Addr: addr.ProviderConfig}
    88  }