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 worker kv #595

Merged
merged 7 commits into from
Feb 27, 2020
Merged

Add worker kv #595

merged 7 commits into from
Feb 27, 2020

Conversation

nrf110
Copy link
Contributor

@nrf110 nrf110 commented Feb 12, 2020

Support Workers KV Pairs. This should resolve #565

Proposed resource syntax:
resource "cloudflare_workers_kv" "example_kv" { namespace_id = cloudflare_workers_kv_namespace.example_ns.id key = "test-key" value = "some value" }

@ghost ghost added size/L kind/documentation Categorizes issue or PR as related to documentation. labels Feb 12, 2020
@jacobbednarz
Copy link
Member

Looks like integration tests are failing for this one:

------- Stdout: -------
=== RUN   TestAccCloudflareWorkersKV_Basic
=== PAUSE TestAccCloudflareWorkersKV_Basic
=== CONT  TestAccCloudflareWorkersKV_Basic
--- FAIL: TestAccCloudflareWorkersKV_Basic (0.00s)
    testing.go:654: Step 0 error: 4 problems:
        
        - Invalid multi-line string: On /opt/teamcity-agent/temp/buildTmp/tf-test760257884/main.tf line 3: Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the "heredoc" multi-line template syntax.
        - Invalid multi-line string: On /opt/teamcity-agent/temp/buildTmp/tf-test760257884/main.tf line 4: Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the "heredoc" multi-line template syntax.
        - Invalid multi-line string: On /opt/teamcity-agent/temp/buildTmp/tf-test760257884/main.tf line 5: Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the "heredoc" multi-line template syntax.
        - Unterminated template string: On /opt/teamcity-agent/temp/buildTmp/tf-test760257884/main.tf line 3: No closing marker was found for the string.
FAIL

client := meta.(*cloudflare.API)
namespaceID, key := parseId(d)

value, err := client.ReadWorkersKV(context.Background(), namespaceID, key)
Copy link
Member

Choose a reason for hiding this comment

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

All of the Worker KV methods require setting api.AccountID however we're not setting it or documenting it as a required configuration parameter. How does it work at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None of the methods have a parameter for the account ID, it is set on the cloudflare.API client when the provider configures it. This is identical to how the existing cloudflare_workers_kv_namespace resource works, but I can add it to the documentation if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a note in the docs that setting account_id on the provider, or the CLOUDFLARE_ACCOUNT_ID environment variable is necessary to use this. Does that cover the requirement?

return &schema.Resource{
Create: resourceCloudflareWorkersKVCreate,
Read: resourceCloudflareWorkersKVRead,
Update: resourceCloudflareWorkersKVUpdate,
Copy link
Member

Choose a reason for hiding this comment

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

I see your create + update methods are pretty similar. In some resources where this is also the case, the Create and Update just share the one method. Up to you as I don't mind either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any harm in calling d.SetId in an Update method? That's the main difference between them. I'm all for saving some code if that isn't an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These have been combined into one method.

@nrf110
Copy link
Contributor Author

nrf110 commented Feb 18, 2020

@jacobbednarz I think I've addressed all of the feedback so far. Anything else we need before this can be approved?

@patryk patryk merged commit 5da2e89 into cloudflare:master Feb 27, 2020
@patryk
Copy link
Contributor

patryk commented Feb 27, 2020

Thanks @nrf110 for the PR!

boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this pull request Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Workers KV data resource
3 participants