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 package remoteexec
import ( import (
"github.com/hashicorp/terraform/helper/config" "fmt"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -14,12 +15,22 @@ func (p *ResourceProvisioner) Apply(
return s, nil return s, nil
} }
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, []error) { func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) {
validator := config.Validator{ var hasCommand, hasInline bool
Optional: []string{ for name := range c.Raw {
"command", switch name {
"inline", 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
} }