Skip to content

Commit

Permalink
terraform: Relax provider config ref constraints
Browse files Browse the repository at this point in the history
Work in progress, needs tests and the eyes of someone who knows what
they're doing.
  • Loading branch information
alisdair committed Jun 26, 2020
1 parent 65ddf2c commit 62bfcc0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 65 deletions.
17 changes: 14 additions & 3 deletions terraform/eval_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ func buildProviderConfig(ctx EvalContext, addr addrs.AbsProviderConfig, config *
// EvalConfigProvider is an EvalNode implementation that configures
// a provider that is already initialized and retrieved.
type EvalConfigProvider struct {
Addr addrs.AbsProviderConfig
Provider *providers.Interface
Config *configs.Provider
Addr addrs.AbsProviderConfig
Provider *providers.Interface
Config *configs.Provider
VerifyConfigIsKnown bool
}

func (n *EvalConfigProvider) Eval(ctx EvalContext) (interface{}, error) {
Expand All @@ -78,6 +79,16 @@ func (n *EvalConfigProvider) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.NonFatalErr()
}

if n.VerifyConfigIsKnown && !configVal.IsWhollyKnown() {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid provider configuration",
Detail: fmt.Sprintf("The configuration for %s is not wholly known. FIXME bad diag.", n.Addr),
Subject: &config.DeclRange,
})
return nil, diags.NonFatalErr()
}

configDiags := ctx.ConfigureProvider(n.Addr, configVal)
configDiags = configDiags.InConfigBody(configBody)

Expand Down
29 changes: 14 additions & 15 deletions terraform/evaltree_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNo
Addr: addr,
})

// Input stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkImport},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalGetProvider{
Addr: addr,
Output: &provider,
},
},
},
})

seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkValidate},
Node: &EvalSequence{
Expand All @@ -48,7 +35,6 @@ func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNo
},
})

// Apply stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
Node: &EvalSequence{
Expand All @@ -64,7 +50,7 @@ func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNo
// We configure on everything but validate, since validate may
// not have access to all the variables.
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalConfigProvider{
Expand All @@ -75,6 +61,19 @@ func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNo
},
},
})
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkImport},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalConfigProvider{
Addr: addr,
Provider: &provider,
Config: config,
VerifyConfigIsKnown: true,
},
},
},
})

return &EvalSequence{Nodes: seq}
}
Expand Down
3 changes: 0 additions & 3 deletions terraform/graph_builder_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// configuration
&attachDataResourceDependenciesTransformer{},

// This validates that the providers only depend on variables
&ImportProviderValidateTransformer{},

// Close opened plugin connections
&CloseProviderTransformer{},

Expand Down
44 changes: 0 additions & 44 deletions terraform/transform_import_provider.go

This file was deleted.

0 comments on commit 62bfcc0

Please sign in to comment.