cloudflare / cf-terraforming

A command line utility to facilitate terraforming your existing Cloudflare resources.
Mozilla Public License 2.0
972 stars 138 forks source link

panic: interface conversion: interface {} is bool, not string when generating `cloudflare_access_application` #734

Open sashasimkin opened 3 months ago

sashasimkin commented 3 months ago

Confirmation

cf-terraforming version

0.20.0

Expected outcome

Resource generated.

Actual outcome

panik

Steps to reproduce

$ cf-terraforming -a *** -t $CLOUDFLARE_API_TOKEN generate --resource-type cloudflare_access_application

panic: interface conversion: interface {} is bool, not string

goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0xc00012b778, 0x8}, {0xcbcedc0, 0xc000680e10}, {0x0?, 0xcbd8480?}, 0xc000680c48)
    internal/app/cf-terraforming/cmd/util.go:228 +0xe1d
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0xc00012b778, 0x8}, {0xcbd1da0, 0xc000680b40}, {0x0, 0x0}, 0xc000680c48)
    internal/app/cf-terraforming/cmd/util.go:275 +0x167c
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.init.generateResources.func2(0xd103f40, {0xca66777?, 0x4?, 0xca666f7?})
    internal/app/cf-terraforming/cmd/generate.go:1325 +0x62ae
github.com/spf13/cobra.(*Command).execute(0xd103f40, {0xc000141680, 0x6, 0x8})
    /Users/x/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0xd104500)
    /Users/x/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /Users/x/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute()
    internal/app/cf-terraforming/cmd/root.go:30 +0x1a
main.main()
    cmd/cf-terraforming/main.go:8 +0xf

I dug into the code a little, and seems like terraforming can't cope with policies.*.reusable (looking at this case https://github.com/cloudflare/cf-terraforming/blob/v0.20.0/internal/app/cf-terraforming/cmd/util.go#L251), here's an excerpt of API response that I received while running with --verbose flag:

{
  "result": [
    {
      "id": "***",
      "uid": "***",
      "type": "warp",
      "name": "Warp Login App",
      "aud": "***",
      "created_at": "2024-07-02T15:17:29Z",
      "updated_at": "2024-08-02T15:47:40Z",
      "domain": "***.cloudflareaccess.com/warp",
      "allowed_idps": [],
      "session_duration": "24h",
      "auto_redirect_to_identity": false,
      "policies": [
        {
          "created_at": "2024-07-02T15:17:29Z",
          "decision": "allow",
          "exclude": [],
          "id": "***",
          "include": [
            {
              "login_method": {
                "id": "***"
              }
            }
          ],
          "name": "Allow access with AWS login",
          "require": [],
          "uid": "***",
          "updated_at": "2024-08-02T15:47:40Z",
          "reusable": false,
          "precedence": 2
        },
        {
          "created_at": "2024-08-02T15:46:23Z",
          "decision": "allow",
          "exclude": [],
          "id": "***",
          "include": [
            {
              "email_domain": {
                "domain": "***"
              }
            }
          ],
          "name": "Allow all @***",
          "require": [],
          "uid": "***",
          "updated_at": "2024-08-02T15:47:40Z",
          "reusable": false,
          "precedence": 3
        }
      ],
      "tags": []
    },
......

References

No response

sashasimkin commented 2 months ago

On current master (3ab7b24) the error is different:

$ cf-terraforming -a $CF_ACC -t $CLOUDFLARE_API_TOKEN generate --resource-type cloudflare_access_application
2024/08/06 13:38:09 [DEBUG] GET https://releases.hashicorp.com/terraform/index.json
2024/08/06 13:38:10 [DEBUG] GET https://releases.hashicorp.com/terraform/1.9.3/terraform_1.9.3_SHA256SUMS.72D7468F.sig
2024/08/06 13:38:10 [DEBUG] GET https://releases.hashicorp.com/terraform/1.9.3/terraform_1.9.3_SHA256SUMS
2024/08/06 13:38:10 [DEBUG] GET https://releases.hashicorp.com/terraform/1.9.3/terraform_1.9.3_darwin_amd64.zip
panic: interface conversion: interface {} is []interface {}, not string

goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0xc0004ef498, 0x8}, {0xb9939c0, 0xc000119140}, {0x0?, 0xb99d200?}, 0xc000118f90)
    /Users/x/go/pkg/mod/github.com/cloudflare/cf-terraforming@v0.20.1-0.20240802023314-3ab7b24cd8ab/internal/app/cf-terraforming/cmd/util.go:228 +0xe1d
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0xc0004ef498, 0x8}, {0xb9969e0, 0xc000118e88}, {0x0, 0x0}, 0xc000118f90)
    /Users/x/go/pkg/mod/github.com/cloudflare/cf-terraforming@v0.20.1-0.20240802023314-3ab7b24cd8ab/internal/app/cf-terraforming/cmd/util.go:275 +0x167c
github.com/x/cf-terraforming/internal/app/cf-terraforming/cmd.init.generateResources.func2(0xbecc200, {0xb828b13?, 0x4?, 0xb828a97?})
    /Users/x/go/pkg/mod/github.com/cloudflare/cf-terraforming@v0.20.1-0.20240802023314-3ab7b24cd8ab/internal/app/cf-terraforming/cmd/generate.go:1328 +0x62ee
github.com/spf13/cobra.(*Command).execute(0xbecc200, {0xc000198360, 0x6, 0x6})
    /Users/x/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:989 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0xbecc7c0)
    /Users/x/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /Users/x/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute()
    /Users/x/go/pkg/mod/github.com/cloudflare/cf-terraforming@v0.20.1-0.20240802023314-3ab7b24cd8ab/internal/app/cf-terraforming/cmd/root.go:30 +0x1a
main.main()
    /Users/x/go/pkg/mod/github.com/cloudflare/cf-terraforming@v0.20.1-0.20240802023314-3ab7b24cd8ab/cmd/cf-terraforming/main.go:8 +0xf