cleanup from resource state mods

This commit is contained in:
James Bardin 2020-03-13 16:09:28 -04:00
parent ea51b790bc
commit a7de3d07b8
5 changed files with 10 additions and 13 deletions

View File

@ -1422,7 +1422,7 @@ func TestContext2Refresh_vars(t *testing.T) {
}
for _, r := range mod.Resources {
if r.Addr.Type == "" {
if r.Addr.Resource.Type == "" {
t.Fatalf("no type: %#v", r)
}
}

View File

@ -113,7 +113,7 @@ func evaluateResourceCountExpressionKnown(expr hcl.Expression, ctx EvalContext)
// or this function will block forever awaiting the lock.
func fixResourceCountSetTransition(ctx EvalContext, addr addrs.AbsResource, countEnabled bool) {
state := ctx.State()
changed := state.MaybeFixUpResourceInstanceAddressForCount(addr, countEnabled)
changed := state.MaybeFixUpResourceInstanceAddressForCount(addr.Config(), countEnabled)
if changed {
log.Printf("[TRACE] renamed first %s instance in transient state due to count argument change", addr)
}

View File

@ -63,14 +63,13 @@ func (n *EvalCountFixZeroOneBoundaryGlobal) fixModule(ctx EvalContext, moduleAdd
}
for _, r := range ms.Resources {
addr := r.Addr.Absolute(moduleAddr)
rCfg := cfg.Module.ResourceByAddr(r.Addr)
rCfg := cfg.Module.ResourceByAddr(r.Addr.Resource)
if rCfg == nil {
log.Printf("[WARN] Not fixing up EachModes for %s because it has no config", addr)
log.Printf("[WARN] Not fixing up EachModes for %s because it has no config", r.Addr)
continue
}
hasCount := rCfg.Count != nil
fixResourceCountSetTransition(ctx, addr, hasCount)
fixResourceCountSetTransition(ctx, r.Addr, hasCount)
}
return nil

View File

@ -74,13 +74,13 @@ func (t *OrphanResourceInstanceTransformer) transform(g *Graph, ms *states.Modul
// pseudo-arguments here. They are handled by OrphanResourceCountTransformer.
for _, rs := range ms.Resources {
if m != nil {
if r := m.ResourceByAddr(rs.Addr); r != nil {
if r := m.ResourceByAddr(rs.Addr.Resource); r != nil {
continue
}
}
for key := range rs.Instances {
addr := rs.Addr.Instance(key).Absolute(moduleAddr)
addr := rs.Addr.Instance(key)
abstract := NewNodeAbstractResourceInstance(addr)
var node dag.Vertex = abstract
if f := t.Concrete; f != nil {
@ -153,13 +153,13 @@ func (t *OrphanResourceTransformer) Transform(g *Graph) error {
for _, rs := range ms.Resources {
if mc != nil {
if r := mc.Module.ResourceByAddr(rs.Addr); r != nil {
if r := mc.Module.ResourceByAddr(rs.Addr.Resource); r != nil {
// It's in the config, so nothing to do for this one.
continue
}
}
addr := rs.Addr.Absolute(moduleAddr)
addr := rs.Addr
abstract := NewNodeAbstractResource(addr)
var node dag.Vertex = abstract
if f := t.Concrete; f != nil {

View File

@ -43,10 +43,8 @@ func (t *StateTransformer) Transform(g *Graph) error {
}
for _, ms := range t.State.Modules {
moduleAddr := ms.Addr
for _, rs := range ms.Resources {
resourceAddr := rs.Addr.Absolute(moduleAddr)
resourceAddr := rs.Addr
for key, is := range rs.Instances {
addr := resourceAddr.Instance(key)