6 "github.com/hashicorp/hcl2/hcl"
7 "github.com/hashicorp/terraform/addrs"
8 "github.com/hashicorp/terraform/tfdiags"
11 // ImportProviderValidateTransformer is a GraphTransformer that goes through
12 // the providers in the graph and validates that they only depend on variables.
13 type ImportProviderValidateTransformer struct{}
15 func (t *ImportProviderValidateTransformer) Transform(g *Graph) error {
16 var diags tfdiags.Diagnostics
18 for _, v := range g.Vertices() {
19 // We only care about providers
20 pv, ok := v.(GraphNodeProvider)
25 // We only care about providers that reference things
26 rn, ok := pv.(GraphNodeReferencer)
31 for _, ref := range rn.References() {
32 if _, ok := ref.Subject.(addrs.InputVariable); !ok {
33 diags = diags.Append(&hcl.Diagnostic{
34 Severity: hcl.DiagError,
35 Summary: "Invalid provider dependency for import",
36 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()),
37 Subject: ref.SourceRange.ToHCL().Ptr(),