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

Fix possible panic during resourceCloudflareSpectrumApplicationRead #1599

Merged
merged 5 commits into from
May 11, 2022
Merged

Fix possible panic during resourceCloudflareSpectrumApplicationRead #1599

merged 5 commits into from
May 11, 2022

Conversation

joshuamsager
Copy link
Contributor

Fixes a panic in resourceCloudflareSpectrumApplicationRead where application.EdgeIPs.Connectivity could be nil. This is impacting our team from upgrading to the latest provider version. We were previously on: v3.4.0.

Relavent logs:

Stack trace from the terraform-provider-cloudflare_v3.14.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xba37c0]

goroutine 279 [running]:
github.com/cloudflare/terraform-provider-cloudflare/cloudflare.resourceCloudflareSpectrumApplicationRead(0xc00072e080, {0xdada00?, 0xc0004a8480})
        github.com/cloudflare/terraform-provider-cloudflare/cloudflare/resource_cloudflare_spectrum_application.go:116 +0x10e0
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xf05178?, {0xf05178?, 0xc00043f1d0?}, 0xd?, {0xdada00?, 0xc0004a8480?})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:712 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000457340, {0xf05178, 0xc00043f1d0}, 0xc0004531e0, {0xdada00, 0xc0004a8480})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1015 +0x585
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc000187230, {0xf050d0?, 0xc00071b840?}, 0xc00071b8c0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:613 +0x497
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc000388a00, {0xf05178?, 0xc0004030e0?}, 0xc000791aa0)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:746 +0x438
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xd80140?, 0xc000388a00}, {0xf05178, 0xc0004030e0}, 0xc000791a40, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001ae8c0, {0xf07c00, 0xc000374d00}, 0xc0008959e0, 0xc000460f60, 0x14002f0, 0x0)
        google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0001ae8c0, {0xf07c00, 0xc000374d00}, 0xc0008959e0, 0x0)
        google.golang.org/[email protected]/server.go:1619 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:919 +0x28a

Error: The terraform-provider-cloudflare_v3.14.0 plugin crashed!

It appears this regression was introduced here: https://github.com/cloudflare/terraform-provider-cloudflare/pull/1515/files#diff-98e27307f62b90eef57324e5dfb984be43e94aa8fcec759596265dd981f168efR116

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2022

Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/terraform-provider-cloudflare/blob/master/docs/changelog-process.md.

Example:

```release-note:TYPE
Release note
```

If you do not require a release note to be included, please add the workflow/skip-changelog-entry label.

.changelog/1599.txt Outdated Show resolved Hide resolved
@jacobbednarz
Copy link
Member

@joshuamsager can you please add a test case exercising this new code path for coverage?

@joshuamsager
Copy link
Contributor Author

joshuamsager commented May 9, 2022

@joshuamsager can you please add a test case exercising this new code path for coverage?

Hey @jacobbednarz, when trying to come up with a test locally... I receive errors from the API server:

2022/05/09 11:20:03 [DEBUG] Cloudflare API Request Details:
---[ REQUEST ]---------------------------------------
POST /client/v4/zones/<REDACTED>/spectrum/apps HTTP/1.1
Host: api.cloudflare.com
User-Agent: terraform/1.1.9 terraform-plugin-sdk/2.10.1 terraform-provider-cloudflare/dev
Content-Length: 271
Content-Type: application/json
X-Auth-Email: <REDACTED>
X-Auth-Key: <REDACTED>
Accept-Encoding: gzip

{
 "dns": {
  "type": "CNAME",
  "name": "qvgfshhqbg.cdn2.rhopifycloud.com"
 },
 "origin_direct": [
  "tcp://1.2.3.4:23"
 ],
 "protocol": "tcp/22",
 "traffic_type": "direct",
 "tls": "off",
 "proxy_protocol": "off",
 "origin_port": 22,
 "edge_ips": {
  "type": "static",
  "ips": [
   "198.51.100.10"
  ]
 },
 "ip_firewall": true
}
-----------------------------------------------------
2022/05/09 11:20:07 [DEBUG] Cloudflare API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 400 Bad Request
Cf-Cache-Status: DYNAMIC
Cf-Ray: 708b6abfeb1586ae-ORD
Content-Type: application/json; charset=UTF-8
Date: Mon, 09 May 2022 15:20:07 GMT
Expect-Ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
Set-Cookie: __cflb=0H28vgHxwvgAQtjUGU4vq74ZFe3sNVUZXW2QpHxQ52u; SameSite=Lax; path=/; expires=Mon, 09-May-22 17:50:08 GMT; HttpOnly
Set-Cookie: __cfruid=2e62042a3fc5e51dd91e036ed3b734de17760aa8-1652109607; path=/; domain=.api.cloudflare.com; HttpOnly; Secure; SameSite=None
Vary: Accept-Encoding
X-Envoy-Upstream-Service-Time: 67

{
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10012,
      "message": "json: unknown field \"traffic_type\""
    }
  ],
  "messages": []
}

Which happens when I run any of the tests in: terraform-provider-cloudflare/cloudflare/resource_cloudflare_spectrum_application_test.go. When I test this API call locally using Postman, the API succeeds only after removing all of the optional parameters from the JSON body.

In any case, I added the test case I believe to test the new codepath in: d666c6c

@jacobbednarz
Copy link
Member

thanks, I'll pull this locally and have a look tomorrow.

@jacobbednarz
Copy link
Member

i managed to get to the bottom of this one, and it was a combination of account entitlements and tighter validation on some endpoints for payloads.

i did have to mark your new test as pending in our acceptance test suite for now as it requires BYO IP setup and i don't yet have that (confirmed it was fixed in another account with BYO IP enabled though).

TF_ACC=1 go test $(go list ./...) -v -run "^TestAccCloudflareSpectrumApplication_" -count 1 -parallel 1 -timeout 120m -parallel 1
?   	github.com/cloudflare/terraform-provider-cloudflare	[no test files]
=== RUN   TestAccCloudflareSpectrumApplication_Import
=== PAUSE TestAccCloudflareSpectrumApplication_Import
=== RUN   TestAccCloudflareSpectrumApplication_Basic
--- PASS: TestAccCloudflareSpectrumApplication_Basic (29.45s)
=== RUN   TestAccCloudflareSpectrumApplication_OriginDNS
--- PASS: TestAccCloudflareSpectrumApplication_OriginDNS (13.53s)
=== RUN   TestAccCloudflareSpectrumApplication_OriginPortRange
--- PASS: TestAccCloudflareSpectrumApplication_OriginPortRange (14.28s)
=== RUN   TestAccCloudflareSpectrumApplication_Update
--- PASS: TestAccCloudflareSpectrumApplication_Update (19.57s)
=== RUN   TestAccCloudflareSpectrumApplication_EdgeIPConnectivity
--- PASS: TestAccCloudflareSpectrumApplication_EdgeIPConnectivity (10.48s)
=== RUN   TestAccCloudflareSpectrumApplication_EdgeIPsWithoutConnectivity
    resource_cloudflare_spectrum_application_test.go:228: pending getting BYO IP assigned to the acceptance testing account
--- SKIP: TestAccCloudflareSpectrumApplication_EdgeIPsWithoutConnectivity (0.00s)
=== CONT  TestAccCloudflareSpectrumApplication_Import
--- PASS: TestAccCloudflareSpectrumApplication_Import (14.03s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/cloudflare	101.917s
?   	github.com/cloudflare/terraform-provider-cloudflare/tools/cmd/changelog-check	[no test files]
?   	github.com/cloudflare/terraform-provider-cloudflare/tools/cmd/maintainer-only-file-check	[no test files]
?   	github.com/cloudflare/terraform-provider-cloudflare/tools/cmd/tf-log-check	[no test files]
?   	github.com/cloudflare/terraform-provider-cloudflare/version	[no test files]

@jacobbednarz jacobbednarz merged commit 89fa272 into cloudflare:master May 11, 2022
@github-actions github-actions bot added this to the v3.15.0 milestone May 11, 2022
@jacobbednarz
Copy link
Member

thanks for getting this one over the line @joshuamsager, you rock!

@github-actions
Copy link
Contributor

This functionality has been released in v3.15.0 of the Terraform Cloudflare Provider.

Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@joshuamsager joshuamsager deleted the joshuamsager/fix-cloudflare-panic-resourceCloudflareSpectrumApplicationRead branch January 28, 2023 15:38
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

Successfully merging this pull request may close these issues.

2 participants