in workflow.go [764:803]
func New() *Workflow {
// We can't use context.WithCancel as we use the context even after cancel for cleanup.
w := &Workflow{Cancel: make(chan struct{})}
// Init nil'ed fields
w.Sources = map[string]string{}
w.Vars = map[string]Var{}
w.Steps = map[string]*Step{}
w.Dependencies = map[string][]string{}
w.DefaultTimeout = defaultTimeout
w.autovars = map[string]string{}
// Resource registries and cleanup.
w.disks = newDiskRegistry(w)
w.forwardingRules = newForwardingRuleRegistry(w)
w.firewallRules = newFirewallRuleRegistry(w)
w.images = newImageRegistry(w)
w.machineImages = newMachineImageRegistry(w)
w.instances = newInstanceRegistry(w)
w.networks = newNetworkRegistry(w)
w.subnetworks = newSubnetworkRegistry(w)
w.objects = newObjectRegistry(w)
w.targetInstances = newTargetInstanceRegistry(w)
w.snapshots = newSnapshotRegistry(w)
w.addCleanupHook(func() DError {
w.instances.cleanup() // instances need to be done before disks/networks
w.images.cleanup()
w.machineImages.cleanup()
w.disks.cleanup()
w.forwardingRules.cleanup()
w.targetInstances.cleanup()
w.firewallRules.cleanup()
w.subnetworks.cleanup()
w.networks.cleanup()
w.snapshots.cleanup()
return nil
})
w.id = randString(5)
return w
}