-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a6bbfd
commit 2491702
Showing
2 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package terraform | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
// EvalDataResourceInit is an EvalNode implementation that initializes | ||
// a data resource's state from its configuration, once it's complete. | ||
type EvalDataResourceInit struct { | ||
State **InstanceState | ||
Config **ResourceConfig | ||
Info *InstanceInfo | ||
} | ||
|
||
func (n *EvalDataResourceInit) Eval(ctx EvalContext) (interface{}, error) { | ||
// TODO: test | ||
|
||
// If we already have a state then we don't need to do anything. | ||
if *n.State != nil { | ||
log.Printf("[TRACE] %s: skipping init: state already present", n.Info.Id) | ||
return nil, nil | ||
} | ||
|
||
config := *n.Config | ||
if config == nil { | ||
// Should never happen | ||
panic(fmt.Errorf("EvalDataResourceInit for %s given nil ResourceConfig", n.Info.HumanId())) | ||
} | ||
|
||
// We can't initialize until our config has been completely interpolated. | ||
// If a data resource depends on a not-yet-created managed resource then | ||
// we'll exit here during Refresh and then visit again during Apply, | ||
// at which point the dependencies should all be ready. | ||
if config.ComputedKeys != nil && len(config.ComputedKeys) > 0 { | ||
log.Printf("[TRACE] %s: skipping init: config has computed attributes", n.Info.Id) | ||
return nil, nil | ||
} | ||
|
||
state := &InstanceState{ | ||
Attributes: map[string]string{}, | ||
} | ||
|
||
for k, _ := range config.Raw { | ||
v, _ := config.GetRaw(k) | ||
log.Printf("config %#v = %#v\n", k, v) | ||
} | ||
|
||
*n.State = state | ||
|
||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters