Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic while running cf-terraforming generate for access application #707

Open
2 tasks done
hhkumar opened this issue May 17, 2024 · 6 comments
Open
2 tasks done

Panic while running cf-terraforming generate for access application #707

hhkumar opened this issue May 17, 2024 · 6 comments

Comments

@hhkumar
Copy link

hhkumar commented May 17, 2024

Confirmation

  • My issue isn't already found on the issue tracker.
  • I have replicated my issue using the latest version of the library and it is still present.

cf-terraforming version

cf-terraforming 0.20.0

Expected outcome

cf-terraforming generate --zone <zone_id> --resource-type cloudflare_access_application generates resource blocks for the applications in the zone

Actual outcome

cf-terraforming % cf-terraforming generate --zone <zone_id> --resource-type cloudflare_access_application
panic: interface conversion: interface {} is float64, not string

goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x1400016e2e8, 0x8}, {0x1033d2ca0, 0x140003393b0}, {0x0?, 0x1033dc6e0?}, 0x140003390e0)
	internal/app/cf-terraforming/cmd/util.go:228 +0xbb0
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x1400016e2e8, 0x8}, {0x1033d5c80, 0x1400025e828}, {0x0, 0x0}, 0x140003390e0)
	internal/app/cf-terraforming/cmd/util.go:275 +0x1200
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.init.generateResources.func2(0x1038f2fe0, {0x103268c6b?, 0x4?, 0x103268beb?})
	internal/app/cf-terraforming/cmd/generate.go:1325 +0x5494
github.com/spf13/cobra.(*Command).execute(0x1038f2fe0, {0x14000089b40, 0x4, 0x4})
	/Users/hariharakumar-hana/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0x828
github.com/spf13/cobra.(*Command).ExecuteC(0x1038f35a0)
	/Users/hariharakumar-hana/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/hariharakumar-hana/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 +0x24
main.main()
	cmd/cf-terraforming/main.go:8 +0x1c

Steps to reproduce

  1. brew install cloudflare/cloudflare/cf-terraforming should upgrade to v0.20.0
  2. Running cf-terraforming generate command panics for access application. Not sure if limited to only that
  3. Generate command worked on previous version v0.19.0

References

No response

@hhkumar hhkumar changed the title Issue running cf-terraforming generate Panic while running cf-terraforming generate for access application May 17, 2024
@sebdanielsson
Copy link

Getting the same error when trying to import cloudflare_access_application.

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

goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x140006153b8, 0x8}, {0x102ecaca0, 0x1400000f9b0}, {0x0?, 0x102ed46e0?}, 0x1400000f6e0)
	internal/app/cf-terraforming/cmd/util.go:228 +0xbb0
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x140006153b8, 0x8}, {0x102ecdc80, 0x1400000f338}, {0x0, 0x0}, 0x1400000f6e0)
	internal/app/cf-terraforming/cmd/util.go:275 +0x1200
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.init.generateResources.func2(0x1033eafe0, {0x102d60c6b?, 0x4?, 0x102d60beb?})
	internal/app/cf-terraforming/cmd/generate.go:1325 +0x5494
github.com/spf13/cobra.(*Command).execute(0x1033eafe0, {0x1400003bb00, 0x4, 0x4})
	/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0x828
github.com/spf13/cobra.(*Command).ExecuteC(0x1033eb5a0)
	/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/sebastian/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 +0x24
main.main()
	cmd/cf-terraforming/main.go:8 +0x1c

@sebdanielsson
Copy link

@jacobbednarz could you please take a look?😇

@andywancg
Copy link

I'm also seeing the same problem, looks like I can import other resource types ok but I get the same error when trying to extract out an existing application I've got configured in Cloudflare with the same panic error - interface {} is float64, not string.

I'm no golang expert but I've taken a quick look at the code and it looks like it's using a generic map to write the values out to keep the code simple, but I'm assuming it's the JSON unmarshalling that's flipping a value to the float64.

Not sure if I can easily hack a fix for it but looking at internal/app/cf-terraforming/cmd/util.go on line 228 I think:
mapCty[k] = cty.StringVal(v.(string))
needs to cater for non-string values.

A proper fix might involve more changes to the response handler when it receives data from the API to populate structs or something similar depending on the type of object being queried.

I'll let you know if I manage to find a quick hack for this if the repo owner can't find a proper fix before me, but as mentioned, I'm no golang expert!

@andywancg
Copy link

I've been able to get it a little bit further, but I'm hitting further issues unfortunately. I've got the code to be able to handle different variable types now however when querying for the "cloudflare_access_application" resource type, I start seeing nested arrays in the response which means an additional layer of handling is required. Not sure what to suggest at this stage, as I'd need to understand the API a little more and the code itself to work out how best to handle the different responses, and I've not got very much spare time on my hands right now, sorry!

@kirkj-lightspeed
Copy link

I'm not part of the project team, but I had a similar error. It was because I had updated cf-terraforming, but hadn't switched to a newer version of the terraform provider.

i.e. I needed to update to version 4 in my cloudflare.tf:

terraform {
  required_providers {
    cloudflare = {
      source = "cloudflare/cloudflare"
      version = "~> 4"
    }
  }
}

@sebdanielsson
Copy link

Updated to the latest cf-terraforming (0.21.0) + the latest stable cloudflare terraform provider (4.48.0) and now get a similar error message:

panic: interface conversion: interface {} is []interface {}, not string

goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x140006813f8, 0x8}, {0x1047b20e0, 0x1400043aeb8}, {0x0?, 0x1047bcda0?}, 0x1400043abe8)
	internal/app/cf-terraforming/cmd/util.go:228 +0xbb0
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.writeAttrLine({0x140006813f8, 0x8}, {0x1047b5580, 0x1400043a738}, {0x0, 0x0}, 0x1400043abe8)
	internal/app/cf-terraforming/cmd/util.go:275 +0x1200
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.init.generateResources.func2(0x104d0bda0, {0x10463aad7?, 0x4?, 0x10463aa5b?})
	internal/app/cf-terraforming/cmd/generate.go:1406 +0x5614
github.com/spf13/cobra.(*Command).execute(0x104d0bda0, {0x140000b9880, 0x4, 0x4})
	/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x104d0c360)
	/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute()
	internal/app/cf-terraforming/cmd/root.go:30 +0x24
main.main()
	cmd/cf-terraforming/main.go:8 +0x1c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants