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

Plan crashes with provider 2.19.1 #988

Closed
warwick-mitchell1 opened this issue Mar 11, 2021 · 12 comments · Fixed by #992
Closed

Plan crashes with provider 2.19.1 #988

warwick-mitchell1 opened this issue Mar 11, 2021 · 12 comments · Fixed by #992
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/crash Categorizes issue or PR as related to a crash caused by the provider. kind/regression Categorizes issue or PR as related to a regression from a prior release. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@warwick-mitchell1
Copy link

warwick-mitchell1 commented Mar 11, 2021

Terraform version

Terraform v0.14.6

  • provider registry.terraform.io/cloudflare/cloudflare v2.19.1
  • provider registry.terraform.io/datadog/datadog v2.22.0
  • provider registry.terraform.io/hashicorp/aws v3.31.0
  • provider registry.terraform.io/hashicorp/google v3.59.0
  • provider registry.terraform.io/hashicorp/google-beta v3.59.0
  • provider registry.terraform.io/hashicorp/helm v2.0.2
  • provider registry.terraform.io/hashicorp/kubernetes v2.0.2
  • provider registry.terraform.io/hashicorp/null v3.1.0
  • provider registry.terraform.io/hashicorp/random v3.1.0
  • provider registry.terraform.io/hashicorp/tls v3.1.0
  • provider registry.terraform.io/hashicorp/vault v2.18.0
  • provider registry.terraform.io/vancluever/acme v2.1.2

Affected resource(s)

cloudflare_record

Terraform configuration files

resource "cloudflare_record" "root" {
  zone_id = local.cloudflare_zone_id
  name    =  terraform.workspace
  value   = google_compute_address.cluster.address
  type    = "A"

  proxied = local.cloudflare_proxy
}

Debug output

2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: 2021/03/11 08:18:12 [DEBUG] Cloudflare API Response Details:
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: ---[ RESPONSE ]--------------------------------------
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: HTTP/2.0 200 OK
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Cf-Cache-Status: DYNAMIC
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Cf-Ray: 62e359c81b905463-LHR
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Cf-Request-Id: 08c1f6710b00005463cba5e000000001
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Content-Type: application/json
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Date: Thu, 11 Mar 2021 08:18:12 GMT
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Expect-Ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Server: cloudflare
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Set-Cookie: __cfduid=d85745164d4d411811887353aa872bdf61615450691; expires=Sat, 10-Apr-21 08:18:11 GMT; path=/; domain=.api.cloudflare.com; HttpOnly; SameSite=Lax; Secure
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Set-Cookie: __cflb=0H2s; SameSite=Lax; path=/; expires=Thu, 11-Mar-21 10:48:13 GMT; HttpOnly
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Set-Cookie: __cfruid=; path=/; domain=.api.cloudflare.com; HttpOnly; Secure; SameSite=None
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: Vary: Accept-Encoding
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: X-Envoy-Upstream-Service-Time: 14
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: {
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  "result": {
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "id": "",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "zone_id": "",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "zone_name": ".com",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "name": ".com",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "type": "A",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "content": "252",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "proxiable": true,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "proxied": true,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "ttl": 1,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "locked": false,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "meta": {
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:    "auto_added": false,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:    "managed_by_apps": false,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:    "managed_by_argo_tunnel": false,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:    "source": "primary"
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   },
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "created_on": "2020-10-20T21:26:07.261004Z",
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:   "modified_on": "2020-10-20T21:26:07.261004Z"
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  },
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  "success": true,
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  "errors": [],
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  "messages": []
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: }
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: -----------------------------------------------------
2021-03-11T08:18:12.837Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: 2021/03/11 08:18:12 [DEBUG] Data found in config: map[string]interface {}{}
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: panic: runtime error: invalid memory address or nil pointer dereference
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1c3adec]
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: goroutine 403 [running]:
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/cloudflare/terraform-provider-cloudflare/cloudflare.resourceCloudflareRecordRead(0xc000676690, 0x1f3fcc0, 0xc00070e180, 0xc000676690, 0x0)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/cloudflare/terraform-provider-cloudflare/cloudflare/resource_cloudflare_record.go:442 +0xacc
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0000b6d80, 0xc000586730, 0x1f3fcc0, 0xc00070e180, 0xc00054a2f0, 0x0, 0x0)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/helper/schema/resource.go:460 +0x129
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000f3c8, 0x2115080, 0xc000358690, 0xc0008a8120, 0xc00000f3c8, 0xc000358690, 0xc000099ba0)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/helper/plugin/grpc_provider.go:525 +0x3dd
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x1efc420, 0xc00000f3c8, 0x2115080, 0xc000358690, 0xc0008a80c0, 0x0, 0x2115080, 0xc000358690, 0xc000b06400, 0x1f1)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x214
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100, 0xc00010e780, 0x280f710, 0x0, 0x0, 0x0)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:1171 +0x522
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).handleStream(0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100, 0x0)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:1494 +0xcc5
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00011c160, 0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100)
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:834 +0xa5
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: created by google.golang.org/grpc.(*Server).serveStreams.func1
2021-03-11T08:18:12.840Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:832 +0x1fd
2021-03-11T08:18:12.843Z [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"

Panic output

 2021/03/11 08:18:12 [DEBUG] Data found in config: map[string]interface {}{}
 panic: runtime error: invalid memory address or nil pointer dereference
 [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1c3adec]

 goroutine 403 [running]:
 github.com/cloudflare/terraform-provider-cloudflare/cloudflare.resourceCloudflareRecordRead(0xc000676690, 0x1f3fcc0, 0xc00070e180, 0xc000676690, 0x0)
  github.com/cloudflare/terraform-provider-cloudflare/cloudflare/resource_cloudflare_record.go:442 +0xacc
 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0000b6d80, 0xc000586730, 0x1f3fcc0, 0xc00070e180, 0xc00054a2f0, 0x0, 0x0)
  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/helper/schema/resource.go:460 +0x129
 github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000f3c8, 0x2115080, 0xc000358690, 0xc0008a8120, 0xc00000f3c8, 0xc000358690, 0xc000      099ba0)
  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/helper/plugin/grpc_provider.go:525 +0x3dd
 github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x1efc420, 0xc00000f3c8, 0x2115080, 0xc000358690, 0xc0008a80c0, 0x0, 0x2115080, 0xc000358690, 0      xc000b06400, 0x1f1)
  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x214
 google.golang.org/grpc.(*Server).processUnaryRPC(0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100, 0xc00010e780, 0x280f710, 0x0, 0x0, 0x0)
  google.golang.org/grpc@v1.30.0/server.go:1171 +0x522
 google.golang.org/grpc.(*Server).handleStream(0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100, 0x0)
  google.golang.org/grpc@v1.30.0/server.go:1494 +0xcc5
 google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00011c160, 0xc00037fdc0, 0x2120a40, 0xc000582480, 0xc00025a100)
  google.golang.org/grpc@v1.30.0/server.go:834 +0xa5
 created by google.golang.org/grpc.(*Server).serveStreams.func1
  google.golang.org/grpc@v1.30.0/server.go:832 +0x1fd

Expected output

Plan to succeed

Actual output

Crash, see above

Steps to reproduce

  1. Run a terraform plan

Additional factoids

Work around was to pin at last known good version 2.18.0

References

No response

@warwick-mitchell1 warwick-mitchell1 added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 11, 2021
@JordanP
Copy link

JordanP commented Mar 11, 2021

I can confirm, exact same stack trace. 2.19.0 is fine here. only 2.19.1 has the bug. 97b4439 looks like the culprit

@jacobbednarz
Copy link
Member

Yep, 2.19.1 only had a single commit 🙂

I started looking into this earlier today via #984 but still don't have a test case that replicates. Is it particular record types? Existing state? Any pointers how you've hit this one?

@schans
Copy link

schans commented Mar 11, 2021

Hitting the same issue. Looks to me that record.Priority is not set and then then the assignment errors out on line 442. I think this happens for me for pretty much all dns records.

@jacobbednarz
Copy link
Member

I don't know whether it is as simple as that because we have other test cases exercising various code paths (types, values, etc) that are not triggering a panic.

I'll continue digging when I'm in front of a computer next.

@schans
Copy link

schans commented Mar 11, 2021

Inspected some records states and I can see not all records have the priority set in the state file:

resource "cloudflare_record" "XXXXXX" {
created_on = "2021-03-10T10:08:47.278383Z"
data = {}
hostname = "_46134123412348c626123c30334.docs.mycomp.com"
id = "c7650123412341234bef9fe7218419f2b"
metadata = {
"auto_added" = "false"
"managed_by_apps" = "false"
"managed_by_argo_tunnel" = "false"
"source" = "primary"
}
modified_on = "2021-03-10T10:08:47.278383Z"
name = "_4645c1edd123412346123c30334.docs.mycomp.com"
proxiable = true
proxied = false
ttl = 1
type = "CNAME"
value = "_verifydasdfasdf.domains.othercomp.com"
zone_id = "XXXXXXXXXXXXXXXXX"
}

@ChristophShyper
Copy link

ChristophShyper commented Mar 11, 2021

I'm getting a bunch of following errors:
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: write unix @->/tmp/plugin771003864: write: broken pipe"
Error: rpc error: code = Canceled desc = context canceled

And part of crash report:


panic: runtime error: invalid memory address or nil pointer dereference
--
422 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x103cdac]
423 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:
424 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: goroutine 45 [running]:
425 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/cloudflare/terraform-provider-cloudflare/cloudflare.resourceCloudflareRecordRead(0xc000262460, 0x13417c0, 0xc0001a5500, 0xc000262460, 0x0)
426 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/cloudflare/terraform-provider-cloudflare/cloudflare/resource_cloudflare_record.go:442 +0xacc
427 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000157cb0, 0xc0006300f0, 0x13417c0, 0xc0001a5500, 0xc0007babf0, 0x0, 0x0)
428 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/helper/schema/resource.go:460 +0x129
429 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000188c10, 0x1516240, 0xc0009237a0, 0xc00087ab40, 0xc000188c10, 0xc0009237a0, 0xc0006a1ba0)
430 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/helper/plugin/grpc_provider.go:525 +0x3dd
431 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x12fd8c0, 0xc000188c10, 0x1516240, 0xc0009237a0, 0xc00087aae0, 0x0, 0x1516240, 0xc0009237a0, 0xc000640480, 0x204)
432 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  github.com/hashicorp/terraform-plugin-sdk@v1.16.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x214
433 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).processUnaryRPC(0xc000134380, 0x1521a00, 0xc000876180, 0xc0006ac500, 0xc00017eae0, 0x1c0c510, 0x0, 0x0, 0x0)
434 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:1171 +0x522
435 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).handleStream(0xc000134380, 0x1521a00, 0xc000876180, 0xc0006ac500, 0x0)
436 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:1494 +0xcc5
437 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0003f4290, 0xc000134380, 0x1521a00, 0xc000876180, 0xc0006ac500)
438 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:834 +0xa5
439 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1: created by google.golang.org/grpc.(*Server).serveStreams.func1
440 | 2021-03-11T03:42:39.964Z [DEBUG] plugin.terraform-provider-cloudflare_v2.19.1:  google.golang.org/grpc@v1.30.0/server.go:832 +0x1fd
441 | 2021-03-11T03:42:39.966Z [DEBUG] plugin: plugin process exited: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/2.19.1/linux_amd64/terraform-provider-cloudflare_v2.19.1 pid=24688 error="exit status 2"

Started to happen today with newest provider 2.19.1.

Works ok with 2.19.0.

@usrlocalang
Copy link

Should priority be set in the terraform code? Its failing when it tries to dereference the pointer. https://github.com/cloudflare/terraform-provider-cloudflare/blob/master/cloudflare/resource_cloudflare_record.go#L442

This function does not check for the zero value(Priority not present) https://github.com/hashicorp/terraform/blob/6697245c18dad6848e7647598dda1ab04c2680ca/internal/legacy/helper/schema/resource_diff.go#L409

squat added a commit to pinguiorg/infrastructure that referenced this issue Mar 11, 2021
Pin the CloudFlare provider version to overcome:
cloudflare/terraform-provider-cloudflare#988

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
@tedivm
Copy link

tedivm commented Mar 11, 2021

This also broke all of our workspaces. This should probably be reverted.

@chaswag
Copy link

chaswag commented Mar 11, 2021

Our config that hits the error:

provider "cloudflare" {
api_token = "${var.cloudflare_api_token}"
}
resource "cloudflare_record" "XXX" {
zone_id = "XXX"
name = "stage-green-${var.env}-api.XXX"
value = "${aws_alb.api.dns_name}"
type = "CNAME"
ttl = "300"
}

The error:

Error: Error refreshing state: 1 error occurred:
* module.XXX.cloudflare_record.XXX: 1 error occurred:
* module.XXX.cloudflare_record.XXX: cloudflare_record.XXX: unexpected EOF

Pinning the provider at 2.19.0 avoids it for us.

@jacobbednarz
Copy link
Member

@usrlocalang no - priority is only valid for some record types and for this block in particular, the d.GetOkExists should only be picking up when the value has been set in the past. I may have to adjust the check as it known to encounter edge cases and undefined behaviours in some scenarios.

This function does not check for the zero value(Priority not present)

d.GetOkExists isn't meant to be; it's only checking the schema and if it meets the criteria, then continue on. As I mentioned above though, we may have hit an edge case here with the method. 0 is a valid input here.

@tedivm apologies for the disruption, I'd recommend pinning to v2.19.0 in the meantime while this is being addressed.

@jacobbednarz
Copy link
Member

The potential fix here looks like this:

@@ -437,7 +437,7 @@ func resourceCloudflareRecordRead(d *schema.ResourceData, meta interface{}) erro
        }
        d.Set("proxiable", record.Proxiable)

-       if _, ok := d.GetOkExists("priority"); ok {
+       if record.Priority != nil {
                priority := record.Priority
                p := *priority
                d.Set("priority", fmt.Sprintf("%d", int(p)))

Which then moves the onus onto the service API to always provide the priority as needed. The issue, however, is that I don't yet have a test case that fails in the broken code causing others to crash which means we don't have a good understanding of the conditions that cause this scenario.

@jacobbednarz jacobbednarz added kind/crash Categorizes issue or PR as related to a crash caused by the provider. kind/regression Categorizes issue or PR as related to a regression from a prior release. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 11, 2021
jacobbednarz added a commit that referenced this issue Mar 11, 2021
Following on from the changes in 2.19.0 (and 2.19.1 to actually ship the
change), a regression was introduced that is inadvertantly causing a
panic due to the `d.GetOkExists` failing to accurately determine when to
apply the `record.Priority` value to the state.

`d.GetOkExists` is documented as:

> GetOkExists can check if TypeBool attributes that are Optional with
> no Default value have been set.

While the value isn't a bool, it acts similarly as 0 in this context is
both a valid value and a zero value for the field.

To combat the panic, I've swapped the check to instead compare the value
provided by the API to determine whether or not we want to set it. This
approach wasn't initially taken as the API used to return 0 in all cases
where the value wasn't explicitly set and the underlying library would
ignore it. Hopefully, with MX records allowing 0, this is no longer an
issue going forward.

Closes #988
@jacobbednarz
Copy link
Member

I've pushed up #992 with a fix for this but seeing how I don't have a reproducible case, I'll need a few people here to checkout the branch locally and build the provider to confirm it fixes the issue before we release it.

Please report your findings in #992, not here.

jacobbednarz added a commit that referenced this issue Mar 12, 2021
Following on from the changes in 2.19.0 (and 2.19.1 to actually ship the
change), a regression was introduced that is inadvertantly causing a
panic due to the `d.GetOkExists` failing to accurately determine when to
apply the `record.Priority` value to the state.

`d.GetOkExists` is documented as:

> GetOkExists can check if TypeBool attributes that are Optional with
> no Default value have been set.

While the value isn't a bool, it acts similarly as 0 in this context is
both a valid value and a zero value for the field.

To combat the panic, I've swapped the check to instead compare the value
provided by the API to determine whether or not we want to set it. This
approach wasn't initially taken as the API used to return 0 in all cases
where the value wasn't explicitly set and the underlying library would
ignore it. Hopefully, with MX records allowing 0, this is no longer an
issue going forward.

Closes #988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/crash Categorizes issue or PR as related to a crash caused by the provider. kind/regression Categorizes issue or PR as related to a regression from a prior release. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
8 participants