Search code examples
terraformdevopsopen-sourceinfrastructure-as-codehashicorp

How to give a .tf file as input in Terraform Apply command?


I'm a beginner in Terraform.

I have a directory which contains 2 .tf files.

Now I want to run Terraform Apply on a selected .tf file & neglect the other one.

Can I do that? If yes, how? If no, why & what is the best practice?


Solution

  • You can't selectively apply one file and then the other. Two ways of (maybe) achieving what you're going for:

    • Use the -target flag to target resource(s) in one file and then the other.
    • Put each file (or more broadly, group of resources, which might be multiple files) in separate "modules" (folders). You can then apply them separately.