Browse Source

allow the outpath to be a variable passed in

pull/78/head
Chris Mague 6 years ago
parent
commit
b8842bf4ba
  1. 12
      DOCS.md
  2. 6
      main.go
  3. 9
      plugin.go
  4. 11
      plugin_test.go

12
DOCS.md

@ -171,6 +171,18 @@ pipeline:
+ parallelism: 2
```
You may want to specify the out directory of the plan file so you can pass it to builds further down the pipeline
If you want to change Terraform's default outfile (currently plan.tfout in the cwd) then set the `plan_path` parameter.
```diff
pipeline:
terraform:
image: quay.io/agari/agari-drone-terraform:5
+ plan_path: /tmp/a.out
```
Destroying the service can be done by specifying `plan-destroy` and `destroy` actions. Keep in mind that Fastly won't allow a service with active version be destroyed. Use `force_destroy` option in the service definition for terraform to handle it.
Destroying the service can be done by specifying `plan-destroy` and `destroy` actions. Keep in mind that Fastly won't allow a service with active version be destroyed. Use `force_destroy` option in the service definition for terraform to handle it.
```yaml

6
main.go

@ -48,6 +48,11 @@ func main() {
Usage: "The number of concurrent operations as Terraform walks its graph",
EnvVar: "PLUGIN_PARALLELISM",
},
cli.StringFlag{
Name: "plan_path",
Usage: "The absolute path to save the outfile eg: /tmp/myplan.tfout",
EnvVar: "PLAN_PATH",
},
cli.StringFlag{
Name: "netrc.machine",
Usage: "netrc machine",
@ -146,6 +151,7 @@ func run(c *cli.Context) error {
RoleARN: c.String("role_arn_to_assume"),
RootDir: c.String("root_dir"),
Parallelism: c.Int("parallelism"),
PlanPath: c.String("plan_path"),
Targets: c.StringSlice("targets"),
VarFiles: c.StringSlice("var_files"),
},

9
plugin.go

@ -28,6 +28,7 @@ type (
Cacert string
Sensitive bool
RoleARN string
PlanPath string
RootDir string
Parallelism int
Targets []string
@ -277,7 +278,11 @@ func tfApply(config Config) *exec.Cmd {
if config.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
args = append(args, "plan.tfout")
if config.PlanPath != "" {
args = append(args, config.PlanPath)
} else {
args = append(args, "plan.tfout")
}
return exec.Command(
"terraform",
args...,
@ -316,6 +321,8 @@ func tfPlan(config Config, destroy bool) *exec.Cmd {
if destroy {
args = append(args, "-destroy")
} else if config.PlanPath != "" {
args = append(args, fmt.Sprintf("-out=%s", config.PlanPath))
} else {
args = append(args, "-out=plan.tfout")
}

11
plugin_test.go

@ -43,6 +43,11 @@ func TestPlugin(t *testing.T) {
args{config: Config{}},
exec.Command("terraform", "apply", "plan.tfout"),
},
{
"with path",
args{config: Config{PlanPath: "/tmp/a.tfout"}},
exec.Command("terraform", "apply", "/tmp/a.tfout"),
},
{
"with parallelism",
args{config: Config{Parallelism: 5}},
@ -123,6 +128,12 @@ func TestPlugin(t *testing.T) {
false,
exec.Command("terraform", "plan", "-out=plan.tfout"),
},
{
"with path",
args{config: Config{PlanPath: "/tmp/a.tfout"}},
false,
exec.Command("terraform", "plan", "-out=/tmp/a.tfout"),
},
{
"destroy",
args{config: Config{}},

Loading…
Cancel
Save