Search code examples
intellij-ideaterraformterraform-provider-awsvpcterraform-template-file

How to prevent a terraform resource from being deployed after it shows up in the planned diff?


I ran into this situation during my training the other day.

Say im working with another guy on a terraform infrastructure, and we have shared state (ofcourse).

He creates a resource and updates the state but doesnt deploy that said resource.

After which I code an important resource and want to deploy it, but i dont want the changes the other guy made to apply along with my resource.

What would be the ideal solution for this?

  • Seperate workspace?
  • Taint his resource?
  • Remove his resource from the state file?

Solution

  • This is not possible:

    "He creates a resource and updates the state but doesn't deploy that said resource."

    The state file tracks what is deployed. How would the state be updated with that resource, if the resource wasn't deployed?

    What would be the ideal solution for this?

    Seperate workspace?

    If you are both working on resources that belong in the same environment, then that's probably not the right solution.

    Taint his resource?

    Tainting a resource causes an already deployed resource to be deleted and redeployed. How would that help the situation you describe?

    Remove his resource from the state file?

    You should never modify the state file directly.


    Are you confusing the Terraform template files (.tf files) with the Terraform state file?


    I'm guessing you have some terminology wrong, and what you mean to say is the resource is defined in the Terraform template, and now you need to deploy something new without including that other resource. In that case you would need to use the -target argument to deploy only certain resources.