Forrest logo
back to the terraform tool

terraform-plan:tldr:31ca3

terraform-plan: Focus Terraform's attention on only a subset of resources.
$ terraform plan -target ${resource_type-resource_name[instance index]}
try on your machine

The terraform plan command is used to create an execution plan that shows what actions Terraform will take when it applies the configuration. It examines the current state, the desired state, and any changes required to reach the desired state.

The -target flag is used to selectively plan and apply changes to specific resources. It allows you to target a specific resource to be planned or operated on, rather than applying changes to all resources defined in the configuration.

The ${resource_type-resource_name[instance index]} is a placeholder meant to be replaced with the actual resource you want to target. The format is specified as resource_type.resource_name[instance index], where:

  • resource_type is the type of the resource you want to target, such as aws_instance for an Amazon EC2 instance.
  • resource_name is the name of the resource you want to target. It should match the name attribute specified in your Terraform configuration.
  • instance index is an optional index value if you have multiple instances of the same resource. It is used to identify a specific instance among the available instances of that resource.

By using this command, you can generate a targeted execution plan that only includes the specified resource, allowing you to see the changes that will be applied only to that resource without affecting others.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the terraform tool