core: schema attach interfaces are not mutually-exclusive
It was incorrect to use a type switch to detect the optional schema attachment interfaces, because they are not mutually-exclusive: resource nodes implement both GraphNodeAttachResourceSchema and GraphNodeAttachProvisionerSchema. This fixes a number of test regressions around dependency analysis in "provisioner" blocks.
This commit is contained in:
parent
4b085c9cac
commit
1761faa29c
|
@ -7,13 +7,11 @@ import (
|
|||
"github.com/hashicorp/hcl2/hcl"
|
||||
"github.com/hashicorp/hcl2/hcl/hclsyntax"
|
||||
|
||||
"github.com/hashicorp/terraform/config/configschema"
|
||||
"github.com/hashicorp/terraform/lang"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
|
||||
"github.com/hashicorp/terraform/config/configschema"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
"github.com/hashicorp/terraform/lang"
|
||||
)
|
||||
|
||||
// ConcreteResourceNodeFunc is a callback type used to convert an
|
||||
|
@ -69,6 +67,7 @@ var (
|
|||
_ GraphNodeResource = (*NodeAbstractResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*NodeAbstractResource)(nil)
|
||||
_ GraphNodeAttachResourceSchema = (*NodeAbstractResource)(nil)
|
||||
_ GraphNodeAttachProvisionerSchema = (*NodeAbstractResource)(nil)
|
||||
_ GraphNodeTargetable = (*NodeAbstractResource)(nil)
|
||||
_ dag.GraphNodeDotter = (*NodeAbstractResource)(nil)
|
||||
)
|
||||
|
@ -108,6 +107,7 @@ var (
|
|||
_ GraphNodeAttachResourceState = (*NodeAbstractResourceInstance)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*NodeAbstractResourceInstance)(nil)
|
||||
_ GraphNodeAttachResourceSchema = (*NodeAbstractResourceInstance)(nil)
|
||||
_ GraphNodeAttachProvisionerSchema = (*NodeAbstractResourceInstance)(nil)
|
||||
_ GraphNodeTargetable = (*NodeAbstractResourceInstance)(nil)
|
||||
_ dag.GraphNodeDotter = (*NodeAbstractResourceInstance)(nil)
|
||||
)
|
||||
|
|
|
@ -54,8 +54,8 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error {
|
|||
}
|
||||
|
||||
for _, v := range g.Vertices() {
|
||||
switch tv := v.(type) {
|
||||
case GraphNodeAttachResourceSchema:
|
||||
|
||||
if tv, ok := v.(GraphNodeAttachResourceSchema); ok {
|
||||
addr := tv.ResourceAddr()
|
||||
mode := addr.Resource.Mode
|
||||
typeName := addr.Resource.Type
|
||||
|
@ -75,16 +75,20 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error {
|
|||
}
|
||||
log.Printf("[TRACE] AttachSchemaTransformer: attaching resource schema to %s", dag.VertexName(v))
|
||||
tv.AttachResourceSchema(schema)
|
||||
case GraphNodeAttachProviderConfigSchema:
|
||||
}
|
||||
|
||||
if tv, ok := v.(GraphNodeAttachProviderConfigSchema); ok {
|
||||
providerAddr := tv.ProviderAddr()
|
||||
schema := t.Schemas.ProviderConfig(providerAddr.ProviderConfig.Type)
|
||||
if schema == nil {
|
||||
log.Printf("[ERROR] AttachSchemaTransformer: No schema available for %s", providerAddr)
|
||||
log.Printf("[ERROR] AttachSchemaTransformer: No provider config schema available for %s", providerAddr)
|
||||
continue
|
||||
}
|
||||
log.Printf("[TRACE] AttachSchemaTransformer: attaching schema to %s", dag.VertexName(v))
|
||||
log.Printf("[TRACE] AttachSchemaTransformer: attaching provider config schema to %s", dag.VertexName(v))
|
||||
tv.AttachProviderConfigSchema(schema)
|
||||
case GraphNodeAttachProvisionerSchema:
|
||||
}
|
||||
|
||||
if tv, ok := v.(GraphNodeAttachProvisionerSchema); ok {
|
||||
names := tv.ProvisionedBy()
|
||||
for _, name := range names {
|
||||
schema := t.Schemas.ProvisionerConfig(name)
|
||||
|
@ -92,7 +96,7 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error {
|
|||
log.Printf("[ERROR] AttachSchemaTransformer: No schema available for provisioner %q on %q", name, dag.VertexName(v))
|
||||
continue
|
||||
}
|
||||
log.Printf("[TRACE] AttachSchemaTransformer: attaching provisioner %q schema to %s", name, dag.VertexName(v))
|
||||
log.Printf("[TRACE] AttachSchemaTransformer: attaching provisioner %q config schema to %s", name, dag.VertexName(v))
|
||||
tv.AttachProvisionerSchema(name, schema)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue