-
Notifications
You must be signed in to change notification settings - Fork 14
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
Cache Ruleset panics when import #1006
Comments
Hi @7onn, thank you for reporting this. You certainly shouldn't be seeing your program panic. Thank you for supplying code snippets - however, I'm struggling a bit with a repro because you have a bit of configuration setup - specifically, if I'm reading this correctly, an existing Ruleset? Would it be possible for you to supply us with a fully contained minimal repro? For something with multiple files like this, a repository might be best. Thanks in advance! |
It is hard to provide a fully reproducible environment because that would involve my PAT with privileges over my company's Cloudflare account. But to find the resources I'm trying to import, in Cloudflare, one can navigate to $ curl -s -X GET "https://api.cloudflare.com/client/v4/zones/<zone-id>/rulesets?per_page=200" -H "Authorization: Bearer <cloudflare-api-token>" -H "Content-Type: application/json" {
"result": [
{
"description": "",
"id": "5d85d2e2b1404e0fb6aa9cfd89aabe0d",
"kind": "zone",
"last_updated": "2024-12-03T13:29:35.474735Z",
"name": "default",
"phase": "http_request_cache_settings",
"version": "76"
},
],
"success": true,
"errors": [],
"messages": []
} Then, import this Ruleset in a typescript code. import { Ruleset } from '@pulumi/cloudflare';
import { Config } from '@pulumi/pulumi';
import { cloudflareProvider as provider } from './provider';
import { RulesetRule } from '@pulumi/cloudflare/types/input';
const pulumiConfig = new Config();
const zoneId = pulumiConfig.require('cloudflareZoneId');
const rules = pulumiConfig.requireObject('cacheRules') as RulesetRule[]
new Ruleset(
`ruleset/http_request_cache_settings`,
{
zoneId,
rules,
kind: 'zone',
name: 'default',
phase: 'http_request_cache_settings',
},
{
provider,
import:
"zone/<my-zone>/5d85d2e2b1404e0fb6aa9cfd89aabe0d"
}
); And feed it the YAML input provided in the |
I confirmed the same error is happening via CLI ❯ pulumi import cloudflare:index/ruleset:Ruleset "ruleset/http_request_cache_settings" zone/<zone-id>/5d85d2e2b1404e0fb6aa9cfd89aabe0d --provider 'urn:pulumi:<stack>::cloudflare-domains::pulumi:providers:cloudflare::cloudflare'
...
Previewing import (<stack>)
Type Name Plan Info
pulumi:pulumi:Stack cloudflare-domains-<stack> 1 error; 39 messages
= └─ cloudflare:index:Ruleset ruleset/http_request_cache_settings import 1 error
Diagnostics:
cloudflare:index:Ruleset (ruleset/http_request_cache_settings):
error: Preview failed: error reading from server: EOF
pulumi:pulumi:Stack (cloudflare-domains-<stack>):
error: preview failed
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x3710692]
goroutine 53 [running]:
github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/rulesets.toRulesetResourceModel({0x4a7bbd8, 0xc001dd23f0}, {0xf0?, {0xc0011ee0e0?, 0xc001077f80?}}, {0x20?, {0x0?, 0x0?}}, {{0xc001e3e032, 0x20}, ...})
/home/runner/work/pulumi-cloudflare/pulumi-cloudflare/upstream/internal/framework/service/rulesets/resource.go:627 +0x3cd2
github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/rulesets.(*RulesetResource).Read(0xc0000949e8, {0x4a7bbd8, 0xc001dd23f0}, {{{{0x4a8a818, 0xc001e09c50}, {0x42f6580, 0xc001e08bd0}}, {0x4a94340, 0xc001cf6820}}, 0xc0000949f8, ...}, ...)
/home/runner/work/pulumi-cloudflare/pulumi-cloudflare/upstream/internal/framework/service/rulesets/resource.go:206 +0x519
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0xc0018da488, {0x4a7bbd8, 0xc001dd23f0}, 0xc001dd2420, 0xc001d07148)
/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/internal/fwserver/server_readresource.go:117 +0x84e
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0xc0018da488, {0x4a7bbd8?, 0xc0018c8720?}, 0xc001d10e00)
/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/internal/proto6server/server_readresource.go:55 +0x38e
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge.(*provider).readResource(0xc001a6b188, {0x4a7bbd8, 0xc0018c8720}, 0xc001d073d0, 0x0?)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/pf/tfbridge/provider_read.go:151 +0x393
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge.(*provider).importResource(0xc001a6b188, {0x4a7bbd8, 0xc0018c8720}, 0xc001d073d0, {0xc001a48050, 0x46})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/pf/tfbridge/provider_read.go:266 +0x230
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge.(*provider).ReadWithContext(0xc001a6b188, {0x4a7bbd8?, 0xc0018c8270?}, {0xc001b28280, 0x79}, {0xc001a48050, 0x46}, 0xc0018c8330, 0xc0018c82a0)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/pf/tfbridge/provider_read.go:68 +0x268
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/plugin.(*providerServer).Read(0xc00185cdb0, {0x4a7bbd8, 0xc0018c8270}, 0xc00149fd00)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/pf/internal/plugin/provider_server.go:421 +0x184
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer.(*muxer).Read.func1({0x4a9f2e0?, 0xc00185cdb0?})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/x/muxer/muxer.go:382 +0x33
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer.resourceMethod[...](0xc0013bf800?, 0x4871b20, 0xc0015cf6b8?)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/x/muxer/muxer.go:335 +0xb5
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer.(*muxer).Read(0x6323ef0?, {0x4a7bbd8?, 0xc0018c8270?}, 0x4103980?)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/[email protected]/pkg/x/muxer/muxer.go:381 +0x4a
github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Read_Handler.func1({0x4a7bbd8?, 0xc0018c8270?}, {0x47bf640?, 0xc00149fd00?})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/proto/go/provider_grpc.pb.go:833 +0xce
github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x4a7bbd8, 0xc0018c1e60}, {0x47bf640, 0xc00149fd00}, 0xc001605620, 0xc0015dd6f8)
/home/runner/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/go/otgrpc/server.go:57 +0x3c4
github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Read_Handler({0x49c5b40, 0xc0013bf800}, {0x4a7bbd8, 0xc0018c1e60}, 0xc00149fc80, 0xc00125cb80)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/proto/go/provider_grpc.pb.go:835 +0x143
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000e2d000, {0x4a7bbd8, 0xc0018c1dd0}, {0x4a90000, 0xc001998000}, 0xc0013e2000, 0xc00185ce40, 0x6357950, 0x0)
/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1394 +0xe2b
google.golang.org/grpc.(*Server).handleStream(0xc000e2d000, {0x4a90000, 0xc001998000}, 0xc0013e2000)
/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1805 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1029 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 26
/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1040 +0x125
|
thank you for the extra context and steps! We'll investigate. |
Thank you for your patience. I've got a repro.
This results in the same error. It looks like one or more of your Rules somehow have an empty/nil This should of course not happen - but it is very likely an upstream Terraform bug. It would be interesting to see how your Rule got into this state; I kind of forced the issue using cURL and the API. I'll see if I can repro this using Terraform import and file a bug upstream. To unblock you for now, I'd recommend using PATCH to set the offending Please let us know how it goes, or if our guess here is off! |
I had gone to this line bc of the stack trace, and I even tried to set the Thanks a lot for the explanation <3 update: After patching all cache rules like
It did work! I'm able to import my resources in Pulumi now! I hope terraform folks fix that though :) Although I don't understand, this check here was resulting true even with the property missing 🤔 How could it not be nil? |
I'm so glad to see that the workaround was successful! 😀 I've verified the import fails using Terraform as well and filed cloudflare/terraform-provider-cloudflare#4813 upstream.
Not sure yet! Still working on a fix. A couple options:
|
This bug is fixed upstream via cloudflare/terraform-provider-cloudflare#4814 and the correct behavior will be available with the next upstream release/upgrade of this provider. |
Describe what happened
I'm on a task of covering CloudFlare configuration under IaC using Pulumi, and I have this block of code where I parse the
RulesetRule[]
out of an input yaml config file which crashes due topanic: runtime error: invalid memory address or nil pointer dereference
. This is weird, as I'm imitating the current config values that I got from CloudFlare API and the config properties that I got from the docs:This approach worked nicely for WAF rules and DNS records, but for cache rules, the provider panicked for some reason, which I cannot figure out why. I hope some help can come from this issue.
Sample program
A configuration Pulumi.yaml like the following:
A typescript program to parse the
cacheRules
property toRulesetRule[]
and forward to my cache settings Ruleset.The app Pulumi app src/index.ts
The app package JSON.
Log output
Affected Resource(s)
Cloudflare Cache Ruleset
Output of
pulumi about
Here's my env info
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: