cloudflare / cf-terraforming

A command line utility to facilitate terraforming your existing Cloudflare resources.
Mozilla Public License 2.0
943 stars 135 forks source link

Issue when providing to many resources #694

Closed tsteckenborn closed 5 months ago

tsteckenborn commented 5 months ago

Confirmation

cf-terraforming version

cf-terraforming 0.19.0

Expected outcome

Executing cf-terraforming generate --help states: --resource-type string Comma delimitered string of which resource(s) you wish to generate. I'd expect a string containing all resources to return results, given a single resource returns results.

Actual outcome

cf-terraforming generate --resource-type "cloudflare_access_application,cloudflare_access_group,cloudflare_access_identity_provider,cloudflare_access_mutual_tls_certificate,cloudflare_access_policy,cloudflare_access_rule,cloudflare_access_service_token,cloudflare_account_member,cloudflare_api_shield,cloudflare_api_token,cloudflare_argo,cloudflare_authenticated_origin_pulls,cloudflare_authenticated_origin_pulls_certificate,cloudflare_bot_management,cloudflare_byo_ip_prefix,cloudflare_certificate_pack,cloudflare_custom_hostname,cloudflare_custom_hostname_fallback_origin,cloudflare_custom_pages,cloudflare_custom_ssl,cloudflare_filter,cloudflare_firewall_rule,cloudflare_healthcheck,cloudflare_ip_list,cloudflare_load_balancer,cloudflare_load_balancer_monitor,cloudflare_load_balancer_pool,cloudflare_logpull_retention,cloudflare_logpush_job,cloudflare_logpush_ownership_challenge,cloudflare_magic_firewall_ruleset,cloudflare_origin_ca_certificate,cloudflare_page_rule,cloudflare_rate_limit,cloudflare_record,cloudflare_ruleset,cloudflare_spectrum_application,cloudflare_tiered_cache,cloudflare_teams_list,cloudflare_teams_location,cloudflare_teams_proxy_endpoint,cloudflare_teams_rule,cloudflare_tunnel,cloudflare_turnstile_widget,cloudflare_url_normalization_settings,cloudflare_waf_group,cloudflare_waf_override,cloudflare_waf_package,cloudflare_waf_rule,cloudflare_waiting_room,cloudflare_worker_cron_trigger,cloudflare_worker_route,cloudflare_worker_script,cloudflare_workers_kv,cloudflare_workers_kv_namespace,cloudflare_zone,cloudflare_zone_dnssec,cloudflare_zone_lockdown,cloudflare_zone_settings_override"

Returns:

no resources found to generate

While cf-terraforming generate --resource-type "cloudflare_record" returns results.

Steps to reproduce

See above.

References

No response

jacobbednarz commented 5 months ago

do you have resources available for all those you are attempting to export? if not, this is expected behaviour to exit early.

tsteckenborn commented 5 months ago

No, I don't. Is that expected behavior documented somewhere / would it be possible to give a more precise error message?

If a command tells me that I could import multiple elements and the return then says that there are no resources found (and not one step didn't find anything, therefore we abort) that's been irritating to me.

Is there a way to import all existing supported elements or would I need to manually search and try?

Br, Tobias

jacobbednarz commented 5 months ago

the behaviour isn't documented as it is the default for all operations (single or multiple resources). it gives you the ability to import multiple resources while still adhering to the expectation that you should be notified if they do not exist (instead of failing silently).

we don't provide the ability to export all resources (only selected ones) due to potential issues with auth and not having access to all resources.

tsteckenborn commented 5 months ago

Okay, I just tested it in another format and it outputs all values until it hits one without. That partially explains your response.

Then let me phrase my comment in a different way, keeping the generic behaviour you were mentioning.

I'd have a suggestion for improvement: Include the name of the resources it didn't find while trying to generate in the error message, so you clearly know what failed. E.g. no resources of type "cloudflare_access_application" found to generate.

Besides that we could close the issue as it's - as you said - no bug but intended behaviour.

Edit: To illustrate why I am making this suggestion, I tried to find the easiest way to export everything, starting with a multiple resource string like this. The first thing I encountered was no resources found to generate. No information about an early return or that it was a specific resource it was trying to generate that caused the response. Only if I change the order to have one with resources and then it fails, it is implicitly clear that it returns early because one of the types in between doesn't return a resource. A clearer statement of what is happening and why would be helpful.

jacobbednarz commented 5 months ago

sounds good 👍 if you want to send over a PR, happy to review it to clarify the resource in question (the debug logs will show it already but people rarely use those).