config: test that resources reference good providers
This commit is contained in:
parent
8ee18e2e14
commit
d0a6d78b97
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
provider "aws" {
|
||||
alias = "bar"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
provider = "aws.baz"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
provider "aws" {
|
||||
alias = "bar"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
provider = "aws.bar"
|
||||
}
|
Loading…
Reference in New Issue