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.
This page assumes you are familiar with Terraform. For details, see Terraform and Infrastructure Manager.
Before you begin
- Enable Infra Manager.
- Ensure that you have the IAM permissions needed to export
previews:
roles/config.admin
. - Create a preview deployment.
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.
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:
- PROJECT_ID: the project ID where Infrastructure Manager runs.
- LOCATION: the location where Infra Manager runs. See Infrastructure Manager locations for the list of valid locations.
- PREVIEW_ID: the preview identifier that you specify. See 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.
Review the binary plan file
To view the binary plan file:
Verify that you have the Terraform CLI installed.
Verify that the Terraform configuration that you used to create the preview is present locally and initialized with
terraform init
.Print the proposed plan using
terraform show
.
Review the JSON representation
To view the JSON representation, you can use your IDE or tools like jq.
To enforce policy constraints you can use JSON representation with tools like Terraform vet.
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 resource drift, call ListResourceDrifts
:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://config.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceDrifts"
Replace:
- PROJECT_ID: The identifier of the Google Cloud project where your preview deployment is located.
- LOCATION: The region or zone of your preview deployment.
- PREVIEW_ID: The identifier of your preview deployment.
The result will look like:
{
"resourceDrifts": [
{
"name": "projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceDrifts/RESOURCE_DRIFT_ID",
"terraformInfo": {
"address": "google_resource_type.resource_name",
"type": "google_resource_type",
"resourceName": "resource_name",
"provider": "registry.terraform.io/hashicorp/google"
},
"propertyDrifts": [
{
"path": "$.json_path_to_property_field",
"before": "config-defined-state",
"after": "remote-state"
}
]
}
]
}
View details of a drift
To view details of a drift, call GetResourceDrift
:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://config.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceDrifts/RESOURCE_DRIFT_ID"
Replace:
- PROJECT_ID: The identifier of the Google Cloud project where your preview deployment is located.
- LOCATION: The region or zone of your preview deployment.
- PREVIEW_ID: The identifier of your preview deployment.
- RESOURCE_DRIFT_ID: The identifier of your drift.
The result will look like:
{
"name": "projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceDrifts/RESOURCE_DRIFT_ID",
"terraformInfo": {
"address": "google_resource_type.resource_name",
"type": "google_resource_type",
"resourceName": "resource_name",
"provider": "registry.terraform.io/hashicorp/google"
},
"propertyDrifts": [
{
"path": "$.json_path_to_property_field",
"before": "config-defined-state",
"after": "remote-state"
}
]
}
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 how your preview deployment would affect your resources, call
ListResourceChanges
:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://config.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceChanges"
Replace:
- PROJECT_ID: The identifier of the Google Cloud project where your preview deployment is located.
- LOCATION: The region or zone of your preview deployment.
- PREVIEW_ID: The identifier of your preview deployment.
- RESOURCE_CHANGE_ID: The identifier of your resource change.
The result will look like:
{
"resourceChanges": [
{
"name": "projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceChanges/RESOURCE_CHANGE_ID",
"terraformInfo": {
"address": "google_resource_type.resource_name",
"type": "google_resource_type",
"resourceName": "resource_name",
"provider": "registry.terraform.io/hashicorp/google",
"actions": [
"update"
]
},
"intent": "UPDATE",
"propertyChanges": [
{
"path": "$.json_path_to_property_field1",
"before": "true"
},
{
"path": "$.json_path_to_property_field2",
"before": "old value",
"after": "new value"
}
]
}
]
}
View details of a resource change
To view details of a resource change, call GetResourceChange
:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://config.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceChanges/RESOURCE_CHANGE_ID"
Replace:
- PROJECT_ID: The identifier of the Google Cloud project where your preview deployment is located.
- LOCATION: The region or zone of your preview deployment.
- PREVIEW_ID: The identifier of your preview deployment.
- RESOURCE_CHANGE_ID: The identifier of your resource change.
The result will look like:
{
"name": "projects/PROJECT_ID/locations/LOCATION/previews/PREVIEW_ID/resourceChanges/RESOURCE_CHANGE_ID",
"terraformInfo": {
"address": "google_resource_type.resource_name",
"type": "google_resource_type",
"resourceName": "resource_name",
"provider": "registry.terraform.io/hashicorp/google",
"actions": [
"update"
]
},
"intent": "UPDATE",
"propertyChanges": [
{
"path": "$.json_path_to_property_field1",
"before": "true"
},
{
"path": "$.json_path_to_property_field2",
"before": "old value",
"after": "new value"
}
]
}
What's next
- View and list previews.
- Deploy resources.
- Learn more about Terraform with Google Cloud.
- Update a deployment.
- View the state of a deployment.
- View resources deployed.
- Delete a deployment.