config: test that resources reference good providers

This commit is contained in:
Mitchell Hashimoto 2015-04-20 14:47:31 -07:00
parent 8ee18e2e14
commit d0a6d78b97
4 changed files with 37 additions and 0 deletions

View File

@ -430,6 +430,15 @@ func (c *Config) Validate() error {
}
}
// Verify provider points to a provider that is configured
if r.Provider != "" {
if _, ok := providerSet[r.Provider]; !ok {
errs = append(errs, fmt.Errorf(
"%s: resource depends on non-configured provider '%s'",
n, r.Provider))
}
}
// Verify provisioners don't contain any splats
for _, p := range r.Provisioners {
// This validation checks that there are now splat variables

View File

@ -217,6 +217,20 @@ func TestConfigValidate_providerMultiGood(t *testing.T) {
}
}
func TestConfigValidate_providerMultiRefGood(t *testing.T) {
c := testConfig(t, "validate-provider-multi-ref-good")
if err := c.Validate(); err != nil {
t.Fatalf("should be valid: %s", err)
}
}
func TestConfigValidate_providerMultiRefBad(t *testing.T) {
c := testConfig(t, "validate-provider-multi-ref-bad")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_provConnSplatOther(t *testing.T) {
c := testConfig(t, "validate-prov-conn-splat-other")
if err := c.Validate(); err != nil {

View File

@ -0,0 +1,7 @@
provider "aws" {
alias = "bar"
}
resource "aws_instance" "foo" {
provider = "aws.baz"
}

View File

@ -0,0 +1,7 @@
provider "aws" {
alias = "bar"
}
resource "aws_instance" "foo" {
provider = "aws.bar"
}