Browse Source

setup show

pull/78/head
Chris Mague 6 years ago
parent
commit
098a917a0b
  1. 5
      DOCS.md
  2. 8
      main.go
  3. 19
      plugin.go
  4. 28
      plugin_test.go

5
DOCS.md

@ -8,7 +8,7 @@ logo: terraform.svg
image: quay.io/agari/agari-drone-terraform image: quay.io/agari/agari-drone-terraform
--- ---
The Terraform plugin applies the infrastructure configuration contained within the repository. The below pipeline configuration demonstrates simple usage which will run a `validate`, `plan` and `apply`: The Terraform plugin applies the infrastructure configuration contained within the repository. The below pipeline configuration demonstrates simple usage which will run a `validate`, `show`, `plan` and `apply`:
```yaml ```yaml
pipeline: pipeline:
@ -33,9 +33,12 @@ Example of explicitly specifying `actions` to perform a dry run.
pipeline: pipeline:
terraform: terraform:
image: quay.io/agari/agari-drone-terraform:5 image: quay.io/agari/agari-drone-terraform:5
planfile: "../planshare.out"
difffile: "../diff.out"
+ actions: + actions:
+ - validate + - validate
+ - plan + - plan
+ - show
``` ```
Example configuration passing secrets to terraform. Please read Example configuration passing secrets to terraform. Please read

8
main.go

@ -27,7 +27,7 @@ func main() {
Name: "actions", Name: "actions",
Usage: "a list of actions to have terraform perform", Usage: "a list of actions to have terraform perform",
EnvVar: "PLUGIN_ACTIONS", EnvVar: "PLUGIN_ACTIONS",
Value: &cli.StringSlice{"validate", "plan", "apply"}, Value: &cli.StringSlice{"validate", "plan", "show", "apply"},
}, },
cli.StringFlag{ cli.StringFlag{
Name: "ca_cert", Name: "ca_cert",
@ -43,6 +43,11 @@ func main() {
Usage: "The absolute path to save the outfile eg: /tmp/myplan.tfout", Usage: "The absolute path to save the outfile eg: /tmp/myplan.tfout",
EnvVar: "PLUGIN_PLANFILE", EnvVar: "PLUGIN_PLANFILE",
}, },
cli.StringFlag{
Name: "difffile",
Usage: "The absolute path to save the diff file to eg: /tmp/myplan.diff",
EnvVar: "PLUGIN_DIFFFILE",
},
cli.StringFlag{ cli.StringFlag{
Name: "init_options", Name: "init_options",
Usage: "options for the init command. See https://www.terraform.io/docs/commands/init.html", Usage: "options for the init command. See https://www.terraform.io/docs/commands/init.html",
@ -152,6 +157,7 @@ func run(c *cli.Context) error {
RootDir: c.String("root_dir"), RootDir: c.String("root_dir"),
Parallelism: c.Int("parallelism"), Parallelism: c.Int("parallelism"),
Planfile: c.String("planfile"), Planfile: c.String("planfile"),
Difffile: c.String("difffile"),
Targets: c.StringSlice("targets"), Targets: c.StringSlice("targets"),
VarFiles: c.StringSlice("var_files"), VarFiles: c.StringSlice("var_files"),
}, },

19
plugin.go

@ -29,6 +29,7 @@ type (
Sensitive bool Sensitive bool
RoleARN string RoleARN string
Planfile string Planfile string
Difffile string
RootDir string RootDir string
Parallelism int Parallelism int
Targets []string Targets []string
@ -135,10 +136,12 @@ func (p Plugin) Exec() error {
commands = append(commands, tfPlan(p.Config, true)) commands = append(commands, tfPlan(p.Config, true))
case "apply": case "apply":
commands = append(commands, tfApply(p.Config)) commands = append(commands, tfApply(p.Config))
case "show":
commands = append(commands, tfShow(p.Config))
case "destroy": case "destroy":
commands = append(commands, tfDestroy(p.Config)) commands = append(commands, tfDestroy(p.Config))
default: default:
return fmt.Errorf("valid actions are: validate, plan, apply, plan-destroy, destroy. You provided %s", action) return fmt.Errorf("valid actions are: validate, plan, show, apply, plan-destroy, destroy. You provided %s", action)
} }
} }
@ -259,6 +262,20 @@ func trace(cmd *exec.Cmd) {
fmt.Println("$", strings.Join(cmd.Args, " ")) fmt.Println("$", strings.Join(cmd.Args, " "))
} }
func tfShow(config Config) *exec.Cmd {
args := []string{
"show",
"-no-color",
}
if config.Difffile != "" {
args = append(args, config.Difffile)
}
return exec.Command(
"terraform",
args...,
)
}
func tfApply(config Config) *exec.Cmd { func tfApply(config Config) *exec.Cmd {
args := []string{ args := []string{
"apply", "apply",

28
plugin_test.go

@ -27,6 +27,34 @@ func TestPlugin(t *testing.T) {
}) })
}) })
g.Describe("tfShow", func() {
g.It("Should return correct apply commands given the arguments", func() {
type args struct {
config Config
}
tests := []struct {
name string
args args
want *exec.Cmd
}{
{
"default",
args{config: Config{}},
exec.Command("terraform", "show", "-no-color"),
},
{
"with planfile",
args{config: Config{Difffile: "/tmp/plan.tfout"}},
exec.Command("terraform", "show", "-no-color", "/tmp/plan.tfout"),
},
}
for _, tt := range tests {
g.Assert(tfShow(tt.args.config)).Equal(tt.want)
}
})
})
g.Describe("tfApply", func() { g.Describe("tfApply", func() {
g.It("Should return correct apply commands given the arguments", func() { g.It("Should return correct apply commands given the arguments", func() {
type args struct { type args struct {

Loading…
Cancel
Save