Merge pull request #35088 from alexott/attach-config-performance

Improve performance of AttachResourceConfigTransformer on big graphs
pull/35100/head
Nick Fagerlund 2 years ago committed by GitHub
commit f2906a1bfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,6 +6,7 @@ package terraform
import (
"log"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs"
"github.com/hashicorp/terraform/internal/dag"
)
@ -48,63 +49,25 @@ func (t *AttachResourceConfigTransformer) Transform(g *Graph) error {
log.Printf("[TRACE] AttachResourceConfigTransformer: %q (%T) has no configuration available", dag.VertexName(v), v)
continue
}
for _, r := range config.Module.ManagedResources {
rAddr := r.Addr()
if rAddr != addr.Resource {
// Not the same resource
continue
}
log.Printf("[TRACE] AttachResourceConfigTransformer: attaching to %q (%T) config from %s", dag.VertexName(v), v, r.DeclRange)
arn.AttachResourceConfig(r)
// attach the provider_meta info
if gnapmc, ok := v.(GraphNodeAttachProviderMetaConfigs); ok {
log.Printf("[TRACE] AttachResourceConfigTransformer: attaching provider meta configs to %s", dag.VertexName(v))
if config == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no config set on the transformer for %s", dag.VertexName(v))
continue
}
if config.Module == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no module in config for %s", dag.VertexName(v))
continue
}
if config.Module.ProviderMetas == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no provider metas defined for %s", dag.VertexName(v))
continue
}
gnapmc.AttachProviderMetaConfigs(config.Module.ProviderMetas)
}
var m map[string]*configs.Resource
if addr.Resource.Mode == addrs.ManagedResourceMode {
m = config.Module.ManagedResources
} else if addr.Resource.Mode == addrs.DataResourceMode {
m = config.Module.DataResources
} else {
panic("unknown resource mode: " + addr.Resource.Mode.String())
}
for _, r := range config.Module.DataResources {
rAddr := r.Addr()
if rAddr != addr.Resource {
// Not the same resource
continue
}
coord := addr.Resource.String()
if r, ok := m[coord]; ok && r.Addr() == addr.Resource {
log.Printf("[TRACE] AttachResourceConfigTransformer: attaching to %q (%T) config from %#v", dag.VertexName(v), v, r.DeclRange)
arn.AttachResourceConfig(r)
// attach the provider_meta info
if gnapmc, ok := v.(GraphNodeAttachProviderMetaConfigs); ok {
log.Printf("[TRACE] AttachResourceConfigTransformer: attaching provider meta configs to %s", dag.VertexName(v))
if config == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no config set on the transformer for %s", dag.VertexName(v))
continue
}
if config.Module == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no module in config for %s", dag.VertexName(v))
continue
}
if config.Module.ProviderMetas == nil {
log.Printf("[TRACE] AttachResourceConfigTransformer: no provider metas defined for %s", dag.VertexName(v))
continue
if config.Module.ProviderMetas != nil {
gnapmc.AttachProviderMetaConfigs(config.Module.ProviderMetas)
} else {
log.Printf("[TRACE] AttachResourceConfigTransformer: no provider meta configs available to attach to %s", dag.VertexName(v))
}
gnapmc.AttachProviderMetaConfigs(config.Module.ProviderMetas)
}
}
}

Loading…
Cancel
Save