I’m trying to manage (pre-existing) resources like “google_pubsub_topic” “input”. This resource should be conditionally either be managed or not managed.
Using for_each and count would (artificially) require the name of the resource to change to “input[1]” or “input[“value”]” which is not really desired.
Is there any best practices to follow, suggestion, or some feature planned to allow a complete resource to be toggled (e.g. via an “if” meta statement)?
There is no universally supported method for this right now.
The current best-case scenario is if the provider has a plural version of a corresponding data resource to lookup zero or more possible instances, you can use that data in the for_each of the import block to declare what needs to be imported. Using for_each in the import does not require using it in the target resource block.
In your case however, I don’t see a google_pubsub_topics data source or similar to fetch the instance id, and not fail if it does not exist. If the system running terraform can be configured to access the service via their cli tooling, you might be able to use a generic data resource like external or shell to fetch the list of instances to import.