jmccann / drone-terraform

Drone plugin for triggering Terraform deployments
http://plugins.drone.io/jmccann/terraform/
Apache License 2.0
86 stars 93 forks source link

Plugin does not handle vars injected as numbers. #124

Open fussybeaver opened 4 years ago

fussybeaver commented 4 years ago

When using a legacy Drone YAML using this plugin, a number encoded as a string injected into the vars field will panic with

--
2 | panic: json: cannot unmarshal number into Go value of type string [recovered]
3 | panic: json: cannot unmarshal number into Go value of type string
4 |  
5 | goroutine 1 [running]:
6 | github.com/urfave/cli.HandleAction.func1(0xc0000e16c8)
7 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:478 +0x22d
8 | panic(0x840a40, 0xc000084780)
9 | /usr/local/go/src/runtime/panic.go:679 +0x1b2
10 | main.run(0xc0000a6780, 0x0, 0x0)
11 | /tmp/drone-terraform/main.go:136 +0xd27
12 | reflect.Value.call(0x82fce0, 0x8e07c8, 0x13, 0x8c1d6b, 0x4, 0xc000057688, 0x1, 0x1, 0xc0000d8170, 0x5, ...)
13 | /usr/local/go/src/reflect/value.go:460 +0x5f6
14 | reflect.Value.Call(0x82fce0, 0x8e07c8, 0x13, 0xc000057688, 0x1, 0x1, 0x1, 0x8c1680, 0x1)
15 | /usr/local/go/src/reflect/value.go:321 +0xb4
16 | github.com/urfave/cli.HandleAction(0x82fce0, 0x8e07c8, 0xc0000a6780, 0x0, 0x0)
17 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:487 +0x215
18 | github.com/urfave/cli.(*App).Run(0xc000001200, 0xc00001e1f0, 0x1, 0x1, 0x0, 0x0)
19 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:245 +0x519
20 | main.main()
21 | /tmp/drone-terraform/main.go:119 +0xe5c

Example YAML:

pipeline:
  terraform:
    image: jmccann/drone-terraform:6.3-0.12.20
    root_dir: terraform/
    init_options:
      backend-config:
        - "config/backend.remote"
    vars:
      id: "11234567"

This gets transformed internally by Drone into:

---
kind: pipeline
name: default

platform:
  os: linux
  arch: amd64

steps:
- name: terraform
  pull: if-not-exists
  image: jmccann/drone-terraform:6.3-0.12.20
  settings:
    init_options:
      backend-config:
      - config/backend.remote
    root_dir: terraform/
    vars:
      id: 11234567

So, the string is coerced into a JNumber type (json type).

I think one could solve this by handling the deserialization as a map[string]interface{} rather than a map[string]string and then converting the type using fmt.Sprintf("%v", ...).