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

Cloudflare worker secret resource #2628

Closed
wants to merge 46 commits into from

Conversation

lboynton
Copy link
Contributor

@lboynton lboynton commented Jul 21, 2023

Trying to resurrect #870. I've manually tested the new resource is working, but I may need some help addressing the comments in #870 which were not resolved before.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

changelog detected ✅

@lboynton lboynton marked this pull request as ready for review September 5, 2023 14:17
@lboynton
Copy link
Contributor Author

@jacobbednarz sorry to ping directly, just wondered if this feature is something Cloudflare want to have in the provider? I still have some work to do on the tests, but I'm quite keen to contribute where I can for this.

@jacobbednarz
Copy link
Member

yes, happy to review it once it is ready. I don't generally review in progress PRs until they are complete due to limited bandwidth.

lboynton and others added 8 commits October 23, 2023 12:10
Tests fail with:

=== RUN   TestAccCloudflareWorkerSecret_Import
    import_cloudflare_worker_secret_test.go:17: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.

          map[string]string{
        - 	"secret_text": "pfeasocioh",
          
@lboynton
Copy link
Contributor Author

Ok the tests are passing for me locally, I think this is ready for review please 🙏

@lboynton lboynton marked this pull request as ready for review October 23, 2023 16:30
UpdateContext: resourceCloudflareWorkerSecretCreate,
DeleteContext: resourceCloudflareWorkerSecretDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Copy link
Member

Choose a reason for hiding this comment

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

this won't work with your custom import string of <account_id>/<script_name>/<secret_name>. you need to define a custom Import method and handle the import manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a custom import method which parses the import string of <account_id>/<script_name>/<secret_name>

return diag.FromErr(errors.Wrap(err, "error creating worker secret"))
}

d.SetId(fmt.Sprintf("%s/%s/%s", accountID, scriptName, name))
Copy link
Member

Choose a reason for hiding this comment

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

the ID should be using stringChecksum to ensure we are storing a hash, not including the values directly which may be dereferenced by other resources.

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 the checksum

examples/resources/cloudflare_worker_secret/resource.tf Outdated Show resolved Hide resolved
},
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckCloudflareWorkerSecretDestroy,
Steps: []resource.TestStep{
Copy link
Member

Choose a reason for hiding this comment

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

you should include a ImportState assertion here too (which would have caught your incorrect Import ID above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added back a separate import secret test to be consistent with the other tests. This is currently failing with:

=== RUN   TestAccCloudflareWorkerSecret_Import
    import_cloudflare_worker_secret_test.go:17: Step 2/2 error running import: exit status 1
        
        Error: invalid id ("0e5935a6b09194ee32e735261911e922") specified, should be in format "accountID/scriptName/secretName"
        
        
--- FAIL: TestAccCloudflareWorkerSecret_Import (23.28s)

This is because the Cloudflare API doesn't let you read back the secret text as it's encrypted. I'm not sure how to reconcile this to make the tests pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got the tests to pass by ignoring state verification for that field

lboynton and others added 7 commits October 30, 2023 09:16
This is currently failing because the secret_text is not set, but this is not returned from the API so I'm not sure how to resolve this
…ecret

# Conflicts:
#	internal/sdkv2provider/provider.go
@lboynton lboynton requested a review from jacobbednarz October 30, 2023 16:30
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!

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!

Copy link
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants