This page describes how to export and review the results of a preview. A preview
describes the actions to actuate a specific Terraform configuration.
Before you create a new deployment or update a deployment, you can preview the
deployment to verify what is planned to change.

If you have not yet created the preview that you want to view, see
[Preview a deployment](https://docs.cloud.google.com/infrastructure-manager/docs/preview-deployment.md.txt).

This page assumes you are familiar with Terraform. For details, see
[Terraform and Infrastructure Manager](https://docs.cloud.google.com/infrastructure-manager/docs/infra-manager-terraform.md.txt).

## Before you begin

1. [Enable Infra Manager](https://docs.cloud.google.com/infrastructure-manager/docs/enable-service.md.txt).
2. Ensure that you have the IAM permissions needed to export previews: `roles/config.admin`.
3. Create a [preview deployment](https://docs.cloud.google.com/infrastructure-manager/docs/preview-deployment.md.txt).

## Export the results of the preview

To review the results of a preview, first export the results. Then, view the
exported results using an appropriate tool.

To export a preview, its state must be `SUCCEEDED` or
`STALE`. You can view the current state of a preview using the
[describe or list commands](https://docs.cloud.google.com/infrastructure-manager/docs/list-preview.md.txt).

Export the results of a preview and save it locally using the following
command:

    gcloud infra-manager previews export projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID

Replace:

- <var translate="no">PROJECT_ID</var>: the project ID where Infrastructure Manager runs.
- <var translate="no">LOCATION</var>: the location where Infra Manager runs. See [Infrastructure Manager locations](https://docs.cloud.google.com/infrastructure-manager/docs/locations.md.txt) for the list of valid locations.
- <var translate="no">PREVIEW_ID</var>: the preview identifier that you specify. See [Preview name](https://docs.cloud.google.com/infrastructure-manager/docs/deployments-revisions.md.txt#preview_name) for details about constraints on the preview identifier.

## View the results of the preview

The results are exported in two formats: the *binary plan file* , and the
*JSON representation*. You can use either format to review the results. To view
the results, use an appropriate tool for the format.

> [!NOTE]
> **Note:** If you export the results of a preview in the binary plan file format, you need to have your Terraform configuration stored locally, and run `terraform init` on the configuration before you can view the results.

### Review the binary plan file

To view the binary plan file:

1. Verify that you have the [Terraform CLI](https://developer.hashicorp.com/terraform/cli)
   installed.

2. Verify that the Terraform configuration that you used to create the preview
   is present locally and initialized with `terraform init`.

3. Print the proposed plan using
   [`terraform show`](https://developer.hashicorp.com/terraform/cli/commands/show).

### Review the JSON representation

To view the JSON representation, you can use your IDE or tools like
[jq](https://jqlang.github.io/jq/).

To enforce policy constraints you can use JSON representation with tools like
[Terraform vet](https://cloud.google.com/docs/terraform/policy-validation/quickstart).

## View resource change and drift details

You can use previews to view resource drift for your deployment. Viewing
resource drift for your deployments is useful to verify that changes to your
configurations are intended, and to summarize *how your deployment will change*
when your deployment is updated with a particular preview.

When you create a preview, you use the Infra Manager API to view
changes to your resources as you update your deployments.

### View resource drift

To view a list of resource drifts of a preview deployment:

    gcloud infra-manager resource-drifts list --preview=projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID

Replace:

- <var translate="no">PROJECT_ID</var>: The identifier of the Google Cloud project where your preview deployment is located.
- <var translate="no">LOCATION</var>: The region or zone of your preview deployment.
- <var translate="no">PREVIEW_ID</var>: The identifier of your preview deployment.

> [!NOTE]
> **Note:** Infra Manager resource drifts are structured versions of `resource_drift` in the [`terraform plan` representation](https://developer.hashicorp.com/terraform/internals/json-format#plan-representation).

### View details of a drift

To view details of a resource drift from a preview deployment:

    gcloud infra-manager resource-drifts describe projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceDrifts/RESOURCE_DRIFT_ID

Replace:

- <var translate="no">PROJECT_ID</var>: The identifier of the Google Cloud project where your preview deployment is located.
- <var translate="no">LOCATION</var>: The region or zone of your preview deployment.
- <var translate="no">PREVIEW_ID</var>: The identifier of your preview deployment.
- <var translate="no">RESOURCE_DRIFT_ID</var>: The identifier of your drift.

## Preview resource changes

You can use previews to check how your resources will change if you update a
deployment from your preview.

### View resource changes

To view a list of resource changes of a preview deployment:

    gcloud infra-manager resource-changes list --preview=projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID

Replace:

- <var translate="no">PROJECT_ID</var>: The identifier of the Google Cloud project where your preview deployment is located.
- <var translate="no">LOCATION</var>: The region or zone of your preview deployment.
- <var translate="no">PREVIEW_ID</var>: The identifier of your preview deployment.

> [!NOTE]
> **Note:** Infra Manager resource changes are structured versions of `resource_changes` in the [`terraform plan` representation](https://developer.hashicorp.com/terraform/internals/json-format#plan-representation).

### View details of a resource change

To view details of a resource change from a preview deployment:

    gcloud infra-manager resource-changes describe projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceChanges/RESOURCE_CHANGE_ID

Replace:

- <var translate="no">PROJECT_ID</var>: The identifier of the Google Cloud project where your preview deployment is located.
- <var translate="no">LOCATION</var>: The region or zone of your preview deployment.
- <var translate="no">PREVIEW_ID</var>: The identifier of your preview deployment.
- <var translate="no">RESOURCE_CHANGE_ID</var>: The identifier of your resource change.

## What's next

- [View and list previews](https://docs.cloud.google.com/infrastructure-manager/docs/list-preview.md.txt).
- [Deploy resources](https://docs.cloud.google.com/infrastructure-manager/docs/deploy-resources.md.txt).
- Learn more about [Terraform with Google Cloud](https://docs.cloud.google.com/docs/terraform.md.txt).
- [Update a deployment](https://docs.cloud.google.com/infrastructure-manager/docs/update-deployment.md.txt).
- [View the state of a deployment](https://docs.cloud.google.com/infrastructure-manager/docs/view-deployments.md.txt).
- [View resources deployed](https://docs.cloud.google.com/infrastructure-manager/docs/view-resources.md.txt).
- [Delete a deployment](https://docs.cloud.google.com/infrastructure-manager/docs/delete-deployments.md.txt).