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 support for turnstile_widget #563

Merged
merged 1 commit into from
May 21, 2023

Conversation

punkeel
Copy link
Member

@punkeel punkeel commented May 18, 2023

  • Supports pagination
  • The API doesn't return an 'id' field, so we add a helper to get the resource ID. This also helps deduplicate code between generate and import

Tested with cloudflare/terraform-provider-cloudflare@master + cloudflare-go@master:

~/code/github/punkeel/tfcf ❯ /Users/maxime/Code/github/punkeel/cf-terraforming/cf-terraforming generate --resource-type cloudflare_turnstile_widget --account 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9

resource "cloudflare_turnstile_widget" "terraform_managed_resource_0x4AAAAAAAEg5sP3rwf91fe8" {
  account_id = "6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9"
  domains    = ["ungeek.fr"]
  mode       = "managed"
  name       = "test site"
  region     = "world"
}

resource "cloudflare_turnstile_widget" "terraform_managed_resource_0x4AAAAAAAE0gwg0H1StXlOx" {
  account_id = "6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9"
  domains    = ["example.com"]
  mode       = "managed"
  name       = "My Terraform-managed widget"
  region     = "world"
}

resource "cloudflare_turnstile_widget" "terraform_managed_resource_0x4AAAAAAAE2z4LbxEka5UBh" {
  account_id = "6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9"
  domains    = ["guerreiro.me"]
  mode       = "managed"
  name       = "My website"
  region     = "world"
}

~/code/github/punkeel/tfcf ❯ /Users/maxime/Code/github/punkeel/cf-terraforming/cf-terraforming import --resource-type cloudflare_turnstile_widget --account 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9

terraform import cloudflare_turnstile_widget.terraform_managed_resource_0x4AAAAAAAEg5sP3rwf91fe8 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9/0x4AAAAAAAEg5sP3rwf91fe8
terraform import cloudflare_turnstile_widget.terraform_managed_resource_0x4AAAAAAAE0gwg0H1StXlOx 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9/0x4AAAAAAAE0gwg0H1StXlOx
terraform import cloudflare_turnstile_widget.terraform_managed_resource_0x4AAAAAAAE2z4LbxEka5UBh 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9/0x4AAAAAAAE2z4LbxEka5UBh

@punkeel punkeel force-pushed the maxime/turnstile-support branch 4 times, most recently from 029dd23 to f61c3c4 Compare May 18, 2023 02:23
@jacobbednarz jacobbednarz force-pushed the maxime/turnstile-support branch from ddfc1f2 to 931e327 Compare May 19, 2023 03:17
@jacobbednarz
Copy link
Member

thanks for the PR @punkeel. i ripped a bunch of this out as it looks like you were having an issue with determing the ID of a resource which we've solved in other places using (this)[https://github.com//pull/563/files#diff-c8a271423d325a18f64e8eb426bae4c393315dfd1fbc9bad21916c9eead1647aR948-R950] pattern. i've given this a run through and everything still looks to be working but can you eyeball it to make sure you're happy with this one as well?

@punkeel
Copy link
Member Author

punkeel commented May 21, 2023

Your changes LGTM, thanks! 🙏

- `ListTurnstileWidgets` performs the pagination for us.
- The API doesn't return an 'id' field, change `jsonStructData` directly to
  "spoof" it.
@punkeel punkeel force-pushed the maxime/turnstile-support branch from 931e327 to 318698a Compare May 21, 2023 21:47
if err != nil {
log.Fatal(err)
}
for i := 0; i < len(jsonStructData); i++ {
Copy link
Member Author

Choose a reason for hiding this comment

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

added the ID hack here

@jacobbednarz jacobbednarz merged commit e1ae871 into cloudflare:master May 21, 2023
@jacobbednarz
Copy link
Member

nice, thanks!

@punkeel punkeel deleted the maxime/turnstile-support branch September 29, 2023 11:24
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