cf-terraforming
cf-terraforming copied to clipboard
Panic while running cf-terraforming generate for access application
Confirmation
- [X] My issue isn't already found on the issue tracker.
- [X] 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/[email protected]/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/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
/Users/hariharakumar-hana/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/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
brew install cloudflare/cloudflare/cf-terraformingshould upgrade to v0.20.0- Running cf-terraforming generate command panics for access application. Not sure if limited to only that
- Generate command worked on previous version v0.19.0
References
No response
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/[email protected]/command.go:987 +0x828
github.com/spf13/cobra.(*Command).ExecuteC(0x1033eb5a0)
/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/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
@jacobbednarz could you please take a look?😇
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!
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!
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"
}
}
}
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/[email protected]/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x104d0c360)
/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
/Users/sebastian/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/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
This issue hasn't been updated in a while. If it's still reproducing, please comment to let us know. Thank you!
Sigh..
Getting this error when trying to generate page rules. Using the v4.52.0 of the provider worked for me. It looks like you have to play a bit of a game of "find the provider version that will let you export the resource type you want without an error", which is unfortunate.
This issue hasn't been updated in a while. If it's still reproducing, please comment to let us know. Thank you!
No activity from cf, you mean?
There actually seems to be a commit in master for this which implements the "generation" (but not the "import") for cloudflare_zero_trust_access_application (new API v5 name for cloudflare_access_application): https://github.com/cloudflare/cf-terraforming/commit/4de037fd1fefb557d8fd18c0d7d1ba6711537812
I built from source (v0.23.3-dev+802c81227453 on master) and was able to get the generation to work apparently.
@hhkumar @sebdanielsson are you still facing this issue?
as @huyz mentioned the resource has been renamed cloudflare_zero_trust_access_application. The import functionality will land soon
There's been a new release. Please try that and feel free to open an issue if its not resolved
Hi, thanks! It's working now. One interesting thing is that when running terraform plan and apply, it constantly wants to make changes due to updated_at, aud, and more changing values or becoming known after apply. I feel like those should be ignored.