package terraform
import (
+ "log"
+
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/dag"
}
}
- concreteResource := func(a *NodeAbstractResource) dag.Vertex {
- return &NodeRefreshableResource{
+ concreteManagedResource := func(a *NodeAbstractResource) dag.Vertex {
+ return &NodeRefreshableManagedResource{
+ NodeAbstractCountResource: &NodeAbstractCountResource{
+ NodeAbstractResource: a,
+ },
+ }
+ }
+
+ concreteManagedResourceInstance := func(a *NodeAbstractResource) dag.Vertex {
+ return &NodeRefreshableManagedResourceInstance{
NodeAbstractResource: a,
}
}
}
steps := []GraphTransformer{
- // Creates all the resources represented in the state
- &StateTransformer{
- Concrete: concreteResource,
- State: b.State,
- },
-
- // Creates all the data resources that aren't in the state
+ // Creates all the managed resources that aren't in the state, but only if
+ // we have a state already. No resources in state means there's not
+ // anything to refresh.
+ func() GraphTransformer {
+ if b.State.HasResources() {
+ return &ConfigTransformer{
+ Concrete: concreteManagedResource,
+ Module: b.Module,
+ Unique: true,
+ ModeFilter: true,
+ Mode: config.ManagedResourceMode,
+ }
+ }
+ log.Println("[TRACE] No managed resources in state during refresh, skipping managed resource transformer")
+ return nil
+ }(),
+
+ // Creates all the data resources that aren't in the state. This will also
+ // add any orphans from scaling in as destroy nodes.
&ConfigTransformer{
Concrete: concreteDataResource,
Module: b.Module,
Mode: config.DataResourceMode,
},
+ // Add any fully-orphaned resources from config (ones that have been
+ // removed completely, not ones that are just orphaned due to a scaled-in
+ // count.
+ &OrphanResourceTransformer{
+ Concrete: concreteManagedResourceInstance,
+ State: b.State,
+ Module: b.Module,
+ },
+
// Attach the state
&AttachStateTransformer{State: b.State},