Browse Source

Merge pull request #3 from heetch/feat/add_fail_on_change

Add fail on change for terraform plan
pull/110/head
Loïc PORTE 5 years ago
committed by GitHub
parent
commit
214b9ade56
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      README.md
  2. 2
      go.mod
  3. 14
      plugin.go

21
README.md

@ -16,27 +16,10 @@ go test
go build
```
## Docker
Build the docker image with the following commands:
```
docker build --rm=true \
-t jmccann/drone-terraform \
--build-arg terraform_version=0.12.0 .
```
## Usage
Execute from the working directory:
```bash
$ PLUGIN_ACTIONS=plan-fail-on-modification ./drone-terraform
```
docker run --rm \
-v $(pwd):$(pwd) \
-w $(pwd) \
jmccann/drone-terraform:latest --plan
```
## Drone 0.4
Legacy `drone-terraform` plugin exists @ `jmccann/drone-terraform:0.4`

2
go.mod

@ -10,3 +10,5 @@ require (
github.com/urfave/cli v0.0.0-20161006035353-55f715e28c46
golang.org/x/sys v0.0.0-20161006025142-8d1157a43547
)
go 1.13

14
plugin.go

@ -115,15 +115,17 @@ func (p Plugin) Exec() error {
case "validate":
commands = append(commands, tfValidate())
case "plan":
commands = append(commands, tfPlan(p.Config, false))
commands = append(commands, tfPlan(p.Config, false, false))
case "plan-destroy":
commands = append(commands, tfPlan(p.Config, true))
commands = append(commands, tfPlan(p.Config, true, false))
case "plan-fail-on-modification":
commands = append(commands, tfPlan(p.Config, false, true))
case "apply":
commands = append(commands, tfApply(p.Config))
case "destroy":
commands = append(commands, tfDestroy(p.Config))
default:
return fmt.Errorf("valid actions are: fmt, validate, plan, apply, plan-destroy, destroy. You provided %s", action)
return fmt.Errorf("valid actions are: fmt, validate, plan, apply, plan-destroy, plan-fail-on-modification destroy. You provided %s", action)
}
}
@ -293,7 +295,7 @@ func tfDestroy(config Config) *exec.Cmd {
)
}
func tfPlan(config Config, destroy bool) *exec.Cmd {
func tfPlan(config Config, destroy bool, detailedExitCode bool) *exec.Cmd {
args := []string{
"plan",
}
@ -304,6 +306,10 @@ func tfPlan(config Config, destroy bool) *exec.Cmd {
args = append(args, fmt.Sprintf("-out=%s", getTfoutPath()))
}
if detailedExitCode {
args = append(args, "-detailed-exitcode")
}
for _, v := range config.Targets {
args = append(args, "--target", fmt.Sprintf("%s", v))
}

Loading…
Cancel
Save