Target Spcefic Resources With Terraform

In this post, we will show how to use the Terraform target command option to modify and add specific resources without modifying the entire configuration.

Terraform Target Command Options

The Terraform command option allows us to add and modify specific resources in a Terraform configuration without risking making changes to the entire configuration.

In the below code example, we are using the target command only to plan to add a single resource in the configuration.

terraform plan -target=azurerm_mssql_database.sqldb1

When Terraform runs, it will ignore checking or trying to fix configuration drift on resources that are not targeted.

The main benefit of using the target option is that it reduces the risk of modifying existing resources and allows us to add resources without risking configuration change.

Once you are OK with the planned output and the planned configuration changes, you could go ahead and use Terraform to apply the target option.

terraform plan -target=azurerm_mssql_database.sqldb1

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.