forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_import_provider.go
38 lines (32 loc) · 962 Bytes
/
transform_import_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package terraform
import (
"fmt"
"strings"
)
// 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 {
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 !strings.HasPrefix(ref, "var.") {
return fmt.Errorf(
"Provider %q depends on non-var %q. Providers for import can currently\n"+
"only depend on variables or must be hardcoded. You can stop import\n"+
"from loading configurations by specifying `-config=\"\"`.",
pv.ProviderName(), ref)
}
}
}
return nil
}