Looking for a way to exclude a resource unless explicitly targeted

Is there a way to mark a resource so that normal actions of plan & apply will ignore it unless it is explicitly targeted?

when = target

Would be ideal.

Hi @RoyceTheBiker,

Unfortunately, there is no such feature in Terraform today. Indeed, even the existing -target feature is there only for specialized, occasional use and is not considered part of the main Terraform workflow.

If you have parts of your infrastructure that you want to work with separately, the standard way to represent that is to write two separate Terraform configurations, and then run terraform apply in each of them separately so that each of them has an independent state.


A post was split to a new topic: How to handle short-lived infrastructure created to support a CI pipeline

Hey, I had a similar use case where we wanted certain resources to be ignored from the subsequent terraform apply. Though the targeted approach would be much easier, the resource lifecycle meta arguments can be leveraged to exclude resources from subsequent terraform re-runs.

  • When you want Terraform to ignore changes between subsequent apply commands you can use the lifecycle ignore_changes meta-argument.
  • The ignore_changes argument means that Terraform will set the value when the resource is first deployed and then forever ignore any changes to it.

Hope this helps!

1 Like

Sweet, had a cluster that was trying to recreate argocd constantly on every apply due to: configs.secret.***. ignore_changes allowed us to ignore that secret without recreating argo.