cf-terraforming
cf-terraforming copied to clipboard
panic: interface {} is nil, not string
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
v0.8.1
Expected outcome
cf-terraforming generate --token $TOKEN -z $ZONE --resource-type cloudflare_record > cf_import.tf
Expected it to output resources into my tf file.
Actual outcome
DEBU[0002] initializing Terraform in .
DEBU[0006] reading Terraform schema for Cloudflare provider
DEBU[0008] beginning to read and build cloudflare_record resources
panic: interface conversion: interface {} is nil, not string
goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.generateResources.func1(0x1961d60?, {0x1588966?, 0x9?, 0x9?})
/home/runner/work/cf-terraforming/cf-terraforming/internal/app/cf-terraforming/cmd/generate.go:574 +0xba34
github.com/spf13/cobra.(*Command).execute(0x1961d60, {0xc0000e45a0, 0x9, 0x9})
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:876 +0x67b
github.com/spf13/cobra.(*Command).ExecuteC(0x1962260)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:990 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:918
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute()
/home/runner/work/cf-terraforming/cf-terraforming/internal/app/cf-terraforming/cmd/root.go:30 +0x25
main.main()
/home/runner/work/cf-terraforming/cf-terraforming/cmd/cf-terraforming/main.go:8 +0x17
Steps to reproduce
Try to generate a cloudflare_record
References
No response
I'm also having this issue, @jmartin-eezy did you ever get this resolved?
@nebriv unfortunately not. I ended up building a small golang client to retrieve cloudflare record IDs (which are not available from the dashboard at this time) so I could import records manually. That process is very tedious but didn't find a workaround.
Hi! I've opened #638 to fix a similar issue, but based on the last comment, it sounds like the problem may be somewhere else. Could you check if setting environment variable USE_STATIC_RESOURCE_IDS
to true
fixes it? If not, could you please generate an updated stack trace from the latest commit on master
or the latest release and share it here? Also, please share the ID(s) of the affected zone(s), privately to janik (at) cloudflare.com works too if you prefer.
It seems to have the same error. --verbose
was 7.4k lines, so I sent that via email.
% cf-terraforming version
cf-terraforming v0.13.0-dev+6f0300c221e3
cf-terraforming generate -t $CF_TOKEN --zone $CF_ZONE --resource-type cloudflare_record
panic: interface conversion: interface {} is nil, not string
goroutine 1 [running]:
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.generateResources.func1(0x1034a1180?, {0x102e82d52?, 0x6?, 0x6?})
/Users/username/Documents/GitHub/cf-terraforming/internal/app/cf-terraforming/cmd/generate.go:1116 +0x4ff4
github.com/spf13/cobra.(*Command).execute(0x1034a1180, {0x14000124540, 0x6, 0x6})
/Users/username/go/pkg/mod/github.com/spf13/[email protected]/command.go:944 +0x5b0
github.com/spf13/cobra.(*Command).ExecuteC(0x1034a0ea0)
/Users/username/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x35c
github.com/spf13/cobra.(*Command).Execute(...)
/Users/username/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute()
/Users/username/Documents/GitHub/cf-terraforming/internal/app/cf-terraforming/cmd/root.go:30 +0x28
main.main()
/Users/username/Documents/GitHub/cf-terraforming/cmd/cf-terraforming/main.go:8 +0x1c
Thanks @alphabet5!
Based on your stack trace, the panic occurs here:
if os.Getenv("USE_STATIC_RESOURCE_IDS") == "true" {
resourceID = "terraform_managed_resource"
} else {
id := ""
switch structData["id"].(type) {
case float64:
id = fmt.Sprintf("%f", structData["id"].(float64))
default:
id = structData["id"].(string) // <--- here
}
resourceID = fmt.Sprintf("terraform_managed_resource_%s", id)
}
Currently, records on Secondary DNS zones don't have IDs (though we're planning to change that) and can't be managed through Terraform, simply because they also can't be changed through our API. If you'd still like to export them, that should work with USE_STATIC_RESOURCE_IDS
set to true
. Please make sure that variable is exported so cf-terraforming has access to it.
This seems to work for me:
export USE_STATIC_RESOURCE_IDS=true
cf-terraforming generate ...
Alternatively, on one line:
USE_STATIC_RESOURCE_IDS=true cf-terraforming generate ...
However, the resulting resources would need to be renamed to avoid conflicts (normally we try to add IDs to the name to make them unique, but in the case of Secondary DNS we can't, and with this environment variable set, we don't try).
Secondary DNS zones (#638) are the only zones that can have records without IDs, and we definitely want to improve that. Sorry for the inconvenience!
I don't know what I did to screw that up, but it does work as expected now. Thanks @janik-cloudflare.
Great :) Glad to hear it & happy to help!