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

Issue 1840 Add custom_hostname wait_for_active_status #1953

Conversation

charmingnewt
Copy link
Contributor

@charmingnewt charmingnewt commented Oct 7, 2022

As shown in #1840, it can be problematic to create required validation records in the same terraform apply run because the custom_hostname resource completes creation before the required validation records are present on the resource.

This pull adds a wait_for_active_status flag similar to the flag introduced in #1567.

I was NOT able to run the acceptance tests because I do not have a suitable Cloudflare account to do so. However I did test this with my currently blocked configuration and it resolved the issues I was seeing.

Closes #1840

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

changelog detected ✅

@charmingnewt charmingnewt marked this pull request as ready for review October 7, 2022 14:56
Copy link
Member

@jacobbednarz jacobbednarz left a comment

Choose a reason for hiding this comment

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

this is a good start, thank you. i've left some nitpick wording changes in the PR. once they are handled, you will need to run make docs locally and commit the documentation updates too (the schema automatically generates these)

internal/provider/resource_cloudflare_custom_hostname.go Outdated Show resolved Hide resolved
internal/provider/resource_cloudflare_custom_hostname.go Outdated Show resolved Hide resolved
internal/provider/schema_cloudflare_custom_hostname.go Outdated Show resolved Hide resolved
@jacobbednarz
Copy link
Member

i've gone back and had a look at the initial issue however i don't think this actually addresses the problem raised.

in the initial ticket, ownership_verification and ownership_verification_http are both set from the initial creation call however, the initial issue is trying to use the ssl.validation_records object for validation which this PR will never check so i'm unsure how this PR is fixing your issue.

@nickysemenza are you able to confirm which config block should be checked for the manual validation records? perhaps the original issue is just using the wrong fields.

@jacobbednarz jacobbednarz added the workflow/pending-cloudflare-response Indicates an issue or PR requires a response from the Cloudflare team. label Oct 10, 2022
@charmingnewt
Copy link
Contributor Author

interesting. it seemed from my testing that the ssl.validation_records were set once the hostname hit active status. this PR worked well for me with my local testing. i'll attach a sample tf file that i was testing with. i'll admit i'm largely unfamiliar with the underlying cloudflare api so if there is a better way to accomplish this i'll take that up instead.

main.tf.txt
testing_results.txt

@nickysemenza
Copy link
Member

the SSL sub-object will get its validation_records set once it transitions from initializing->pending_validation (which, if the parent hostname passes validation on the first try, will likely happen around the same time as the hostname transitioning from pending -> active. (The ssl validation records require a call to the certificate authority to happen in the background) wheras the custom hostname validation records are generated in-house).

So as for the issue described in #1840, waiting until resource.cloudflare_custom_hostname.test.ssl.0.validation_records.0.txt_value has a value can be accomplished by waiting until ssl.status== "pending_validation" or something along those lines - perhaps wait_for_ssl_pending_validation would be more appropriate?

see https://developers.cloudflare.com/ssl/reference/certificate-statuses/ and https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/hostname-verification/#verification-statuses for references on statuses

@charmingnewt charmingnewt force-pushed the issue-1840-custom-hostname-wait-for-active-status branch 3 times, most recently from f5a7089 to 9334c95 Compare October 12, 2022 13:33
@charmingnewt
Copy link
Contributor Author

thanks for the info - i've adjusted the pr to reflect that input

@charmingnewt charmingnewt force-pushed the issue-1840-custom-hostname-wait-for-active-status branch from 9334c95 to f66ce0c Compare October 12, 2022 13:33
@charmingnewt charmingnewt force-pushed the issue-1840-custom-hostname-wait-for-active-status branch from bfd14e1 to b9a8e8d Compare October 14, 2022 14:34
@jacobbednarz
Copy link
Member

acceptance tests are passing

TF_ACC=1 go test $(go list ./...) -v -run "^TestAccCloudflareCustomHostname_" -count 1 -parallel 1 -timeout 120m -parallel 1
?       github.com/cloudflare/terraform-provider-cloudflare     [no test files]
=== RUN   TestAccCloudflareCustomHostname_Basic
=== PAUSE TestAccCloudflareCustomHostname_Basic
=== RUN   TestAccCloudflareCustomHostname_WaitForActive
=== PAUSE TestAccCloudflareCustomHostname_WaitForActive
=== RUN   TestAccCloudflareCustomHostname_WithCustomOriginServer
=== PAUSE TestAccCloudflareCustomHostname_WithCustomOriginServer
=== RUN   TestAccCloudflareCustomHostname_WithHTTPValidation
=== PAUSE TestAccCloudflareCustomHostname_WithHTTPValidation
=== RUN   TestAccCloudflareCustomHostname_WithCustomSSLSettings
=== PAUSE TestAccCloudflareCustomHostname_WithCustomSSLSettings
=== RUN   TestAccCloudflareCustomHostname_Update
=== PAUSE TestAccCloudflareCustomHostname_Update
=== RUN   TestAccCloudflareCustomHostname_WithNoSSL
=== PAUSE TestAccCloudflareCustomHostname_WithNoSSL
=== RUN   TestAccCloudflareCustomHostname_UpdatingZoneForcesNewResource
=== PAUSE TestAccCloudflareCustomHostname_UpdatingZoneForcesNewResource
=== RUN   TestAccCloudflareCustomHostname_Import
=== PAUSE TestAccCloudflareCustomHostname_Import
=== CONT  TestAccCloudflareCustomHostname_Basic
--- PASS: TestAccCloudflareCustomHostname_Basic (8.25s)
=== CONT  TestAccCloudflareCustomHostname_Update
--- PASS: TestAccCloudflareCustomHostname_Update (14.25s)
=== CONT  TestAccCloudflareCustomHostname_Import
--- PASS: TestAccCloudflareCustomHostname_Import (10.16s)
=== CONT  TestAccCloudflareCustomHostname_UpdatingZoneForcesNewResource
--- PASS: TestAccCloudflareCustomHostname_UpdatingZoneForcesNewResource (15.28s)
=== CONT  TestAccCloudflareCustomHostname_WithNoSSL
--- PASS: TestAccCloudflareCustomHostname_WithNoSSL (7.64s)
=== CONT  TestAccCloudflareCustomHostname_WithHTTPValidation
--- PASS: TestAccCloudflareCustomHostname_WithHTTPValidation (7.60s)
=== CONT  TestAccCloudflareCustomHostname_WithCustomSSLSettings
--- PASS: TestAccCloudflareCustomHostname_WithCustomSSLSettings (12.76s)
=== CONT  TestAccCloudflareCustomHostname_WithCustomOriginServer
--- PASS: TestAccCloudflareCustomHostname_WithCustomOriginServer (8.60s)
=== CONT  TestAccCloudflareCustomHostname_WaitForActive
--- PASS: TestAccCloudflareCustomHostname_WaitForActive (10.60s)
PASS
ok      github.com/cloudflare/terraform-provider-cloudflare/internal/provider   95.440s

@jacobbednarz jacobbednarz merged commit ebc001e into cloudflare:master Oct 17, 2022
@github-actions github-actions bot added this to the v3.26.0 milestone Oct 17, 2022
@jacobbednarz
Copy link
Member

jacobbednarz commented Oct 17, 2022

thanks for this one @will-bluem-olo! we appreciate the effort you've put into this one -- your first contribution at that! 🎉

github-actions bot pushed a commit that referenced this pull request Oct 17, 2022
@github-actions
Copy link
Contributor

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

@charmingnewt charmingnewt deleted the issue-1840-custom-hostname-wait-for-active-status branch October 20, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workflow/pending-cloudflare-response Indicates an issue or PR requires a response from the Cloudflare team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

custom hostname validation_records are not predictable
3 participants