I would like to run terraform only for a specific resource

You can use -target=resource like this:

terraform plan -target=module.mymodule.aws_instance.myinstance
terraform apply -target=module.mymodule.aws_instance.myinstance

or

terraform plan -target=aws_instance.myinstance
terraform apply -target=aws_instance.myinstance

Disclaimer: Before downvoting the answer, please note that he actually asked to either “exclude” or “run only ec2 resource”. And after all this time the exclude feature request is still open in the terraform repo.

Leave a Comment