mirror of https://github.com/hashicorp/terraform
parent
ec6e14c4d0
commit
ec0ef95c6f
@ -0,0 +1,7 @@
|
||||
provider "aws" {
|
||||
foo = "${aws_instance.foo.bar}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
bar = "value"
|
||||
}
|
||||
@ -0,0 +1,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
|
||||
}
|
||||
Loading…
Reference in new issue