# Conditionally create or skip resource (without name change)

**URL:** <https://discuss.hashicorp.com/t/conditionally-create-or-skip-resource-without-name-change/73365>\
**Category:** Terraform\
**Created:** [February 19, 2025, 4:53pm UTC](https://discuss.hashicorp.com/t/conditionally-create-or-skip-resource-without-name-change/73365 "2025-02-19T16:53:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steinmann.erik](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/steinmann.erik/32/44292_2.png) [@steinmann.erik](https://discuss.hashicorp.com/u/steinmann.erik)\
**Post date:** [February 19, 2025, 4:53pm UTC](https://discuss.hashicorp.com/t/conditionally-create-or-skip-resource-without-name-change/73365/1 "2025-02-19T16:53:48Z")

</div>

Hello Terraform Community Members,

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)?

Thanks.

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [February 19, 2025, 9:20pm UTC](https://discuss.hashicorp.com/t/conditionally-create-or-skip-resource-without-name-change/73365/2 "2025-02-19T21:20:30Z")

</div>

Hi @steinmann.erik,

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/hashicorp/original/1X/79bf76adfd92a75631996933098f9ce29d37abf3.svg) [@system](https://discuss.hashicorp.com/u/system)\
**Post date:** [August 18, 2025, 9:20pm UTC](https://discuss.hashicorp.com/t/conditionally-create-or-skip-resource-without-name-change/73365/3 "2025-08-18T21:20:39Z")

</div>

Closed on August 18, 2025, 9:20pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
