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

adding_d1_support #2960

Merged
merged 9 commits into from
Dec 27, 2023
Merged

Conversation

mephmanx
Copy link
Contributor

@mephmanx mephmanx commented Nov 23, 2023

Adding initial support for D1 works script bindings. Acceptance tests related to worker scripts pass.

Depends on cloudflare/cloudflare-go#1446

Signed-off-by: Chris Lyons <52037738+mephmanx@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Nov 23, 2023

changelog detected ✅

Signed-off-by: Chris Lyons <52037738+mephmanx@users.noreply.github.com>
@mephmanx
Copy link
Contributor Author

The worker script acceptance tests pass but I could not run the entire suite of acceptance tests as I dont not have everything enabled on my cloudflare account.

@jacobbednarz
Copy link
Member

with cloudflare/clouflare-go@master shimmed in here, i'm still seeing errors.

TF_ACC=1 go test ./internal/sdkv2provider -v -run "^TestAccCloudflareWorkerScript_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareWorkerScript_Import
--- PASS: TestAccCloudflareWorkerScript_Import (14.56s)
=== RUN   TestAccCloudflareWorkerScript_MultiScriptEnt
=== PAUSE TestAccCloudflareWorkerScript_MultiScriptEnt
=== RUN   TestAccCloudflareWorkerScript_ModuleUpload
=== PAUSE TestAccCloudflareWorkerScript_ModuleUpload
=== CONT  TestAccCloudflareWorkerScript_MultiScriptEnt
    resource_cloudflare_workers_script_test.go:39: Step 3/3 error: Error running apply: exit status 1
        
        Error: error updating worker script: binding MY_DATABASE of type d1 must have an `id` specified (10021)
        
          with cloudflare_worker_script.eertxymdvb,
          on terraform_plugin_test.tf line 18, in resource "cloudflare_worker_script" "eertxymdvb":
          18: resource "cloudflare_worker_script" "eertxymdvb" {
        
    resource_cloudflare_workers_script_test.go:152: operation error S3: ListObjectsV2, resolve auth scheme: resolve endpoint: endpoint rule error, Invalid region: region was not a valid DNS name.
--- FAIL: TestAccCloudflareWorkerScript_MultiScriptEnt (29.17s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1039d4d7c]

goroutine 686 [running]:
testing.tRunner.func1.2({0x103de4d40, 0x104967310})
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1545 +0x1c8
testing.tRunner.func1()
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1548 +0x360
panic({0x103de4d40?, 0x104967310?})
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/runtime/panic.go:914 +0x218
github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider.testAccCheckCloudflareWorkerScriptCreateBucket.func1()
	/Users/jacob/go/src/github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider/resource_cloudflare_workers_script_test.go:155 +0x24c
testing.(*common).Cleanup.func1()
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1169 +0x110
testing.(*common).runCleanup(0x14000103520, 0x102d06768?)
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1347 +0xd8
testing.tRunner.func2()
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1589 +0x2c
runtime.Goexit()
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/runtime/panic.go:523 +0x14c
testing.(*common).FailNow(0x14000103520)
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:999 +0x48
testing.(*common).Fatalf(0x14000103520, {0x103a36a85?, 0x30?}, {0x140007320c0?, 0x1?, 0x0?})
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1083 +0x64
github.com/hashicorp/terraform-plugin-testing/helper/resource.runNewTest({0x103fa7448, 0x140006558c0}, {0x103faed20, 0x14000103520}, {0x0, 0x14000134cc0, {0x0, 0x0, 0x0}, 0x1400056cff0, ...}, ...)
	/Users/jacob/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.5.1/helper/resource/testing_new.go:387 +0x1d08
github.com/hashicorp/terraform-plugin-testing/helper/resource.Test({0x103faed20, 0x14000103520}, {0x0, 0x14000134cc0, {0x0, 0x0, 0x0}, 0x1400056cff0, 0x0, 0x0, ...})
	/Users/jacob/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.5.1/helper/resource/testing.go:908 +0x58c
github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider.TestAccCloudflareWorkerScript_MultiScriptEnt(0x14000103520)
	/Users/jacob/go/src/github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider/resource_cloudflare_workers_script_test.go:39 +0xce4
testing.tRunner(0x14000103520, 0x103f916c8)
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1595 +0xe8
created by testing.(*T).Run in goroutine 1
	/Users/jacob/.asdf/installs/golang/1.21.3/go/src/testing/testing.go:1648 +0x33c
FAIL	github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider	44.121s
FAIL
make: *** [testacc] Error 1

is database_id meant to be id here?

@mephmanx
Copy link
Contributor Author

I updated the form name in the cloudflare-go lib with this PR

cloudflare/cloudflare-go#1450

That should fix this error. It looks like the msg I now get is:

Error: error updating worker script: D1 bindings require module-format workers. (10021)

@jacobbednarz
Copy link
Member

with the latest cloudflare-go PR shimmed in, we're working now

TF_ACC=1 go test ./internal/sdkv2provider -v -run "^TestAccCloudflareWorkerScript_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareWorkerScript_Import
--- PASS: TestAccCloudflareWorkerScript_Import (14.31s)
=== RUN   TestAccCloudflareWorkerScript_MultiScriptEnt
=== PAUSE TestAccCloudflareWorkerScript_MultiScriptEnt
=== RUN   TestAccCloudflareWorkerScript_ModuleUpload
=== PAUSE TestAccCloudflareWorkerScript_ModuleUpload
=== CONT  TestAccCloudflareWorkerScript_MultiScriptEnt
--- PASS: TestAccCloudflareWorkerScript_MultiScriptEnt (41.14s)
=== CONT  TestAccCloudflareWorkerScript_ModuleUpload
--- PASS: TestAccCloudflareWorkerScript_ModuleUpload (22.46s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider	78.740s

@mephmanx
Copy link
Contributor Author

Is there anything I can do to get the unit tests to pass?

@jacobbednarz
Copy link
Member

no, it's dependent on an upstream release. the tests above show this is fine once that happens.

Copy link
Contributor

Marking this pull request as stale due to 14 days of inactivity. This helps our maintainers find and focus on the active pull requests. If this pull request receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the lifecycle/stale label.
If this pull request was automatically closed and you feel this pull request should be reopened, we encourage creating a new pull request linking back to this one for added context. Thank you!

@mephmanx
Copy link
Contributor Author

Would like to get this moved forward...

@mephmanx
Copy link
Contributor Author

I have a worker ready to use this with. I deploy the worker via terraform and need to include the d1 binding in the terraform script as it unbinds on each deploy.

@mephmanx
Copy link
Contributor Author

I know you are busy but if you could take a look and see if this can be merged or let me know whatever changes need to be made. Its a bit annoying to rebind the D1 DB to a worker after each terraform deploy...

@mephmanx
Copy link
Contributor Author

Ok, I see the lint error....Ill get that today. Thank you so much for looking at it, I have my user preferences microservices already running off D1 and REALLY like it...this is the only thing that I need to put the bow on it.

Signed-off-by: Chris Lyons <52037738+mephmanx@users.noreply.github.com>
@mephmanx
Copy link
Contributor Author

I ran gofmt in each of the 4 files I changed....if you could please execute the lint step once it gets there. Thank you again!

@mephmanx
Copy link
Contributor Author

@jacobbednarz

Please rerun when you have a bit of time.... hopefully the lint thing is fixed now.

@jacobbednarz
Copy link
Member

acceptance tests all passing

TF_ACC=1 go test ./internal/sdkv2provider -v -run "^TestAccCloudflareWorkerScript_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareWorkerScript_Import
--- PASS: TestAccCloudflareWorkerScript_Import (12.28s)
=== RUN   TestAccCloudflareWorkerScript_MultiScriptEnt
=== PAUSE TestAccCloudflareWorkerScript_MultiScriptEnt
=== RUN   TestAccCloudflareWorkerScript_ModuleUpload
=== PAUSE TestAccCloudflareWorkerScript_ModuleUpload
=== CONT  TestAccCloudflareWorkerScript_MultiScriptEnt
--- PASS: TestAccCloudflareWorkerScript_MultiScriptEnt (33.54s)
=== CONT  TestAccCloudflareWorkerScript_ModuleUpload
--- PASS: TestAccCloudflareWorkerScript_ModuleUpload (31.53s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider	78.168s

@jacobbednarz jacobbednarz merged commit f361f1b into cloudflare:master Dec 27, 2023
9 checks passed
@github-actions github-actions bot added this to the v4.22.0 milestone Dec 27, 2023
github-actions bot pushed a commit that referenced this pull request Dec 27, 2023
Copy link
Contributor

This functionality has been released in v4.22.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!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants