provisioner/remote-exec: Enforce XOR of command and inline

This commit is contained in:
Armon Dadgar 2014-07-11 16:02:51 -07:00
parent 0110640946
commit 5023b896ab
1 changed files with 19 additions and 8 deletions

View File

@ -1,7 +1,8 @@
package remoteexec
import (
"github.com/hashicorp/terraform/helper/config"
"fmt"
"github.com/hashicorp/terraform/terraform"
)
@ -14,12 +15,22 @@ func (p *ResourceProvisioner) Apply(
return s, nil
}
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, []error) {
validator := config.Validator{
Optional: []string{
"command",
"inline",
},
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) {
var hasCommand, hasInline bool
for name := range c.Raw {
switch name {
case "command":
hasCommand = true
case "inline":
hasInline = true
default:
es = append(es, fmt.Errorf("Unknown configuration '%s'", name))
}
}
return validator.Validate(c)
if hasInline && hasCommand {
es = append(es, fmt.Errorf("Cannot provide both 'command' and 'inline' to remote-exec"))
} else if !hasInline && !hasCommand {
es = append(es, fmt.Errorf("Must provide 'command' or 'inline' to remote-exec"))
}
return
}