]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/terraform/transform_import_provider.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / transform_import_provider.go
CommitLineData
bae9f6d2
JC
1package terraform
2
3import (
4 "fmt"
107c1cdb
ND
5
6 "github.com/hashicorp/hcl2/hcl"
7 "github.com/hashicorp/terraform/addrs"
8 "github.com/hashicorp/terraform/tfdiags"
bae9f6d2
JC
9)
10
11// ImportProviderValidateTransformer is a GraphTransformer that goes through
12// the providers in the graph and validates that they only depend on variables.
13type ImportProviderValidateTransformer struct{}
14
15func (t *ImportProviderValidateTransformer) Transform(g *Graph) error {
107c1cdb
ND
16 var diags tfdiags.Diagnostics
17
bae9f6d2
JC
18 for _, v := range g.Vertices() {
19 // We only care about providers
20 pv, ok := v.(GraphNodeProvider)
21 if !ok {
22 continue
23 }
24
25 // We only care about providers that reference things
26 rn, ok := pv.(GraphNodeReferencer)
27 if !ok {
28 continue
29 }
30
31 for _, ref := range rn.References() {
107c1cdb
ND
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(),
38 })
bae9f6d2
JC
39 }
40 }
41 }
42
107c1cdb 43 return diags.Err()
bae9f6d2 44}