provisioner/remote-exec: Enforce XOR of command and inline
This commit is contained in:
parent
0110640946
commit
5023b896ab
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue