Skip to content

Commit

Permalink
terraform: Don't panic when visiting ephemeral resource nodes
Browse files Browse the repository at this point in the history
We don't yet do anything useful when we get there, but we do at least fail
in a vaguely-graceful way.
  • Loading branch information
apparentlymart committed May 1, 2024
1 parent 64b9d7a commit f186d9a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/terraform/node_resource_plan_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (n *NodePlannableResourceInstance) Execute(ctx EvalContext, op walkOperatio
return n.managedResourceExecute(ctx)
case addrs.DataResourceMode:
return n.dataResourceExecute(ctx)
case addrs.EphemeralResourceMode:
return n.ephemeralResourceExecute(ctx)
default:
panic(fmt.Errorf("unsupported resource mode %s", n.Config.Mode))
}
Expand Down Expand Up @@ -443,6 +445,23 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
return diags
}

func (n *NodePlannableResourceInstance) ephemeralResourceExecute(ctx EvalContext) (diags tfdiags.Diagnostics) {
config := n.Config
addr := n.ResourceInstanceAddr()
var diagRng *hcl.Range
if config != nil {
diagRng = config.DeclRange.Ptr()
}

diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Ephemeral resources not yet supported",
Detail: fmt.Sprintf("There is not yet any implementation of planning for %s.", addr),
Subject: diagRng,
})
return diags
}

// replaceTriggered checks if this instance needs to be replace due to a change
// in a replace_triggered_by reference. If replacement is required, the
// instance address is added to forceReplace
Expand Down
29 changes: 29 additions & 0 deletions internal/terraform/transform_attach_config_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ func (t *AttachResourceConfigTransformer) Transform(g *Graph) error {
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
}
gnapmc.AttachProviderMetaConfigs(config.Module.ProviderMetas)
}
}
for _, r := range config.Module.EphemeralResources {
rAddr := r.Addr()

if rAddr != addr.Resource {
// Not the same resource
continue
}

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))
Expand Down

0 comments on commit f186d9a

Please sign in to comment.