TFE Enterprise - API method equivalent to -target with the CLI?

Terraform CLI has a -target argument so I can select a limited set of resource(s) to act upon with plan/apply/destroy. Is there an equivalent to this via the API for Terraform Enterprise?

Hi @kevin.buchs,

As a general rule Terraform CLI performs remote operations using the public Terraform Cloud/Enterprise API and so any option that Terraform CLI will allow for a remotely-executed plan/apply run must have some underlying API equivalent for it to use, and it will typically be one of the optional request properties for the Create a Run action.

For -target in particular, the corresponding property is data.attributes.target-addrs, which expects a JSON array where each element is a separate address to pass to a separate -target option.

For example, if you would’ve run terraform apply -target=aws_instance.example1 -target=aws_instance.example2 at the command line then the equivalent array in the API would be ["aws_instance.example1", "aws_instance.example2"].

The usual recommendation against using resource targeting for routine operations apply here in the same way as for the command line option: this mechanism is intended for exceptional use only, such as recovering from mistakes or situations where Terraform’s own error messages recommend it as part of the solution to a problem. I’d recommend always creating an untargeted run shortly after the completion of a targeted run in order to ensure that your workspace is fully converged with the updated configuration.

Thanks @apparentlymart ! Awesome answer much appreciated.