Skip to main content
⏳ Estimated read time: 5 min read

detect

The detect subcommand detects drift between the current state of infrastructure and the desired state defined in your StackGen appStack or your custom IaC.

Usage

  stackgen drift detect [flags]

Flags

FlagDescriptionRequired
--appstack-id stringStackGen appstack ID. To run drift detection for a specific appstack.Required if --iac-dir is not set
--backend-configBackend config to pass to the drift detectionOptional
--env-profile stringEnvironment profile to use for drift detection. Works only with --appstack-id.Optional
-h, --helpHelp for detectOptional
--iac-dir stringPath to the directory containing IaC files.Required if --appstack-id is not set
--name stringUnique name for the IaC source.Required if --appstack-id is not provided
--timeout durationTimeout for drift detection (default: 10m0s)Optional
--var stringsVariables to pass to the drift detectionOptional
--var-file stringPath to the vars fileOptional

You can use this subcommand and flags to detect drift for your IaC in two ways:

Detect Drift for an appStack

Click to view

Usage

Detect drift for an appStack:

stackgen drift detect --appstack-id=<appstack-id> --var="region=<region>"

Flags

Refer to the section on Flags to know more about the supported flags.

Example: Run a drift detection on your appStack with an appStack ID 12345 deployed in the us-east-1 region on your AWS cloud.

stackgen drift detect --appstack-id=12345 --var="region=us-east-1"

Sample Output: You will also see a summary table.

Drift Summary:
Total Resources: 16
Total Drifts: 1
Resources to be Created: 0
Resources to be Updated: 1
Resources to be Deleted: 0
Resource Drifts:
+----------+---------------+---------+-----------+--------------------------------+
| RESOURCE | TYPE | ACTION | REGION | DESCRIPTION |
+----------+---------------+---------+-----------+--------------------------------+
| this | aws_s3_bucket | changed | us-east-1 | Resource attributes has been |
| | | | | updated |
+----------+---------------+---------+-----------+--------------------------------+

This kind of result tells you there's partial drift. Some things are out of sync, and you might want to review, update, or reapply your IaC to bring the actual state back in line.

Output Explained

The command will return a summary of detected drift:

FieldDescription
Total ResourcesYour IaC configuration defines 16 resources in total.
Total Drifts1 of those resources shows signs of drift. These are either not deployed yet, manually changed, or out of sync.
Resources to be Created0 resource is defined in your IaC but not found in the live environment. You will have to create it.
Resources to be Updated1 existing resource was manually altered (e.g., instance type, security group rules) and differs from what's declared in your IaC.
Resources to be Deleted0 resources were found in the live environment that are missing from your IaC (so nothing extra was created manually).

Detect Drift for a Custom IaC

Click to view

Usage

Run drift detection against your own local IaC project (e.g., Terraform).

stackgen drift detect --name <my-project> --iac-dir <./terraform>

Flags

Refer to the section on Flags to know more about the supported flags.

Example: Run drift detection using your local IaC, in this case, a Terraform project.

stackgen drift detect --name mytest --iac-dir ./terraform

Sample Output: You will also see a summary table.

Drift Summary:
Total Resources: 16
Total Drifts: 1
Resources to be Created: 0
Resources to be Updated: 1
Resources to be Deleted: 0
Resource Drifts:
+----------+---------------+---------+-----------+--------------------------------+
| RESOURCE | TYPE | ACTION | REGION | DESCRIPTION |
+----------+---------------+---------+-----------+--------------------------------+
| this | aws_s3_bucket | changed | us-east-1 | Resource attributes has been |
| | | | | updated |
+----------+---------------+---------+-----------+--------------------------------+

This kind of result tells you there's partial drift. Some things are out of sync, and you might want to review, update, or reapply your IaC to bring the actual state back in line.

Output Explained

The command will return a summary of detected drift:

FieldDescription
Total ResourcesYour IaC configuration defines 16 resources in total.
Total Drifts1 of those resources shows signs of drift. These are either not deployed yet, manually changed, or out of sync.
Resources to be Created0 resource is defined in your IaC but not found in the live environment. You will have to create it.
Resources to be Updated1 existing resource was manually altered (e.g., instance type, security group rules) and differs from what's declared in your IaC.
Resources to be Deleted0 resources were found in the live environment that are missing from your IaC (so nothing extra was created manually).

To see how this looks in your StackGen User Interface refer to the steps mentioned in the Drifts User Guide