mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
39e609d5fd
Previously we were using the experimental HCL 2 repository, but now we'll shift over to the v2 import path within the main HCL repository as part of actually releasing HCL 2.0 as stable. This is a mechanical search/replace to the new import paths. It also switches to the v2.0.0 release of HCL, which includes some new code that Terraform didn't previously have but should not change any behavior that matters for Terraform's purposes. For the moment the experimental HCL2 repository is still an indirect dependency via terraform-config-inspect, so it remains in our go.sum and vendor directories for the moment. Because terraform-config-inspect uses a much smaller subset of the HCL2 functionality, this does still manage to prune the vendor directory a little. A subsequent release of terraform-config-inspect should allow us to completely remove that old repository in a future commit.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package terraform
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
)
|
|
|
|
// ImportProviderValidateTransformer is a GraphTransformer that goes through
|
|
// the providers in the graph and validates that they only depend on variables.
|
|
type ImportProviderValidateTransformer struct{}
|
|
|
|
func (t *ImportProviderValidateTransformer) Transform(g *Graph) error {
|
|
var diags tfdiags.Diagnostics
|
|
|
|
for _, v := range g.Vertices() {
|
|
// We only care about providers
|
|
pv, ok := v.(GraphNodeProvider)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
// We only care about providers that reference things
|
|
rn, ok := pv.(GraphNodeReferencer)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
for _, ref := range rn.References() {
|
|
if _, ok := ref.Subject.(addrs.InputVariable); !ok {
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
Severity: hcl.DiagError,
|
|
Summary: "Invalid provider dependency for import",
|
|
Detail: fmt.Sprintf("The configuration for %s depends on %s. Providers used with import must either have literal configuration or refer only to input variables.", pv.ProviderAddr(), ref.Subject.String()),
|
|
Subject: ref.SourceRange.ToHCL().Ptr(),
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return diags.Err()
|
|
}
|