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

Add Hyperdrive Resource provider #3111

Merged
merged 8 commits into from
Mar 14, 2024

Conversation

carlos-alberto
Copy link
Contributor

@carlos-alberto carlos-alberto commented Feb 8, 2024

Implements #3092

Requires cloudflare/cloudflare-go#1491 to be released and cloudflare/cloudflare-go#1501 to land.

Note: Not sure if the acctest is actually viable, as I believe DB creds need to actually be valid for the api request to work.

Copy link
Contributor

github-actions bot commented Feb 8, 2024

changelog detected ✅

Copy link
Contributor

@OilyLime OilyLime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for implementing this! Just one issue, and that's due to incorrect information in our API spec. We'll make sure to fix that.

docs/resources/hyperdrive_config.md Show resolved Hide resolved
Copy link
Contributor

@OilyLime OilyLime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you @carlos-alberto for this contribution! We have more stuff cooking and I'll try to update this implementation when new things become available.

@carlos-alberto
Copy link
Contributor Author

@OilyLime I've dropped support for max_age and stale_while_revalidate for now as the api doesn't return these values afaik.

@jacobbednarz I've ran the acceptance tests locally and they now pass, but just a heads up that they require a real db to connect to, so will fail if the configuration is not updated to point to a real db.

@OilyLime
Copy link
Contributor

@carlos-alberto The API does return max_age and stale-while_revalidate but only when they are defined.

I get the following when I curl the API for one of my configs.

{
    "result": {
        "id": "<id>",
        "name": "<name>",
        "origin": {
        ...
        },
        "caching": {
            "disabled": false,
            "max_age": 30,
            "stale_while_revalidate": 10
        }
    },
    "success": true,
    "errors": [],
    "messages": []
}

- Drop support for max_age and stale_while_revalidate as the api does
  not return these values. The docs also state they are not yet used.
- Fix the caching schema to allow it to be computed.

I have ran the tests, however they require a real db to connect to, so
will fial if the configuration is not updated to point to a real db.
@carlos-alberto
Copy link
Contributor Author

carlos-alberto commented Mar 6, 2024

@carlos-alberto The API does return max_age and stale-while_revalidate but only when they are defined.

I get the following when I curl the API for one of my configs.

{
    "result": {
        "id": "<id>",
        "name": "<name>",
        "origin": {
        ...
        },
        "caching": {
            "disabled": false,
            "max_age": 30,
            "stale_while_revalidate": 10
        }
    },
    "success": true,
    "errors": [],
    "messages": []
}

@OilyLime we have a hyperdrive config with id 37ccf9bf6a2e47e08f26b4a2c228c0d9 which shows in the UI as

image

However the api returns:

{
            "id": "37ccf9bf6a2e47e08f26b4a2c228c0d9",
            "name": "db-prod-ieiovpwdgwnwxxymgdif",
            "origin": {
                "host": "<redacted>",
                "port": <redacted>,
                "database": "<redacted>",
                "user": "<redacted>"
            },
            "caching": {
                "disabled": false
            }
        }

I wonder if we could land this PR and support for the caching settings could be added later? I think the only way we could support them currently is to duplicate the defaults in the terraform provider, which will make it more difficult for them to be changed later.

@OilyLime
Copy link
Contributor

I wonder if we could land this PR and support for the caching settings could be added later? I think the only way we could support them currently is to duplicate the defaults in the terraform provider, which will make it more difficult for them to be changed later.

That sounds good to me, thanks again for your valuable contribution @carlos-alberto !

@jacobbednarz
Copy link
Member

jacobbednarz commented Mar 14, 2024

looks like the tests are throwing an immediate panic due to not handling failure scenarios in the remote API (lacking entitlements, lacking access, etc). we should rectify this so the provider doesn't end up in an unusable state.

TF_ACC=1 go test ./internal/framework/service/hyperdrive_config -v -run "^TestAccCloudflareHyperdriveConfig_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareHyperdriveConfig_Basic
=== PAUSE TestAccCloudflareHyperdriveConfig_Basic
=== RUN   TestAccCloudflareHyperdriveConfig_Minimum
=== PAUSE TestAccCloudflareHyperdriveConfig_Minimum
=== CONT  TestAccCloudflareHyperdriveConfig_Basic
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10358cd40]

goroutine 75 [running]:
github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/hyperdrive_config.buildHyperdriveConfigModelFromHyperdriveConfig({0x1040c41f0, 0x140009eb170}, 0x140003d7960, {{0x0, 0x0}, {0x0, 0x0}, {{0x0, 0x0}, {0x0, ...}, ...}, ...})
	/Users/jacob/go/src/github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/hyperdrive_config/resource.go:221 +0xf0
github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/hyperdrive_config.(*HyperdriveConfigResource).Create(0x140005344d8, {0x1040c41f0, 0x140009eb170}, {{{{0x1040c9630, 0x140009f2ba0}, {0x103f02880, 0x140009f24e0}}, {0x1040cb278, 0x140003894a0}}, {{{0x1040c9630, ...}, ...}, ...}, ...}, ...)
	/Users/jacob/go/src/github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/hyperdrive_config/resource.go:87 +0x39c
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0x14000881d40, {0x1040c41f0, 0x140009eb170}, 0x14000a074c0, 0x14000a07460)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/internal/fwserver/server_createresource.go:101 +0x41c
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x14000171620?, {0x1040c41f0, 0x140009eb170}, 0x140009d6cd0, 0x14000a07620)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/internal/fwserver/server_applyresourcechange.go:57 +0x380
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0x14000881d40, {0x1040c41f0?, 0x140009eb0b0?}, 0x140009d6c30)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/internal/proto6server/server_applyresourcechange.go:55 +0x314
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x1040c4228?, {0x1040c41f0?, 0x140009eae10?}, 0x140009d6c30)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0x140006e4320, {0x1040c41f0?, 0x140009ea420?}, 0x140003d7260)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:845 +0x2b0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x10407bd80?, 0x140006e4320}, {0x1040c41f0, 0x140009ea420}, 0x140009ec000, 0x0)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400035ee00, {0x1040c41f0, 0x140009ea390}, {0x1040ca040, 0x14000808340}, 0x140009e25a0, 0x14000a82ea0, 0x1048c1038, 0x0)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/google.golang.org/[email protected]/server.go:1383 +0xb8c
google.golang.org/grpc.(*Server).handleStream(0x1400035ee00, {0x1040ca040, 0x14000808340}, 0x140009e25a0)
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/google.golang.org/[email protected]/server.go:1794 +0xc70
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/google.golang.org/[email protected]/server.go:1027 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 320
	/Users/jacob/.asdf/installs/golang/1.21.7/packages/pkg/mod/google.golang.org/[email protected]/server.go:1038 +0x150
FAIL	github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/hyperdrive_config	3.786s
FAIL
make: *** [testacc] Error 1

fixed in c2ad546

@jacobbednarz jacobbednarz merged commit cd3041c into cloudflare:master Mar 14, 2024
9 checks passed
@github-actions github-actions bot added this to the v4.27.0 milestone Mar 14, 2024
@jacobbednarz
Copy link
Member

thanks for the PR. i've merged this as is and provided some feedback to the internal team around the config validation to make it a little easier to perform integration testing without a real DB present.

github-actions bot pushed a commit that referenced this pull request Mar 14, 2024
Copy link
Contributor

This functionality has been released in v4.27.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 Mar 20, 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.

3 participants