]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - 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
1 package terraform
2
3 import (
4 "fmt"
5
6 "github.com/hashicorp/hcl2/hcl"
7 "github.com/hashicorp/terraform/addrs"
8 "github.com/hashicorp/terraform/tfdiags"
9 )
10
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{}
14
15 func (t *ImportProviderValidateTransformer) Transform(g *Graph) error {
16 var diags tfdiags.Diagnostics
17
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() {
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 })
39 }
40 }
41 }
42
43 return diags.Err()
44 }