CLI Infra Provisioning with OpenTofu
Overview
Stackgen CLI now supports infrastructure provisioning using OpenTofu as an alternative to Terraform. This allows your teams to align with the open-source, community-driven IaC ecosystem while maintaining compatibility with existing CLI workflows.
The --iac-tool
flag has been introduced for Infrastructure Lifecycle Management (ILM) commands to let you choose between Terraform and OpenTofu as the provisioning engine. By default, the CLI uses OpenTofu unless explicitly overridden.
Prerequisites
-
Ensure your system has the appropriate binary (tofu or terraform) installed and available in
$PATH
. -
You will need the StackGen CLI version 0.62.0. to use this flag. To upgrade to the latest version, run the command:
brew upgrade stackgenhq/stackgen/stackgen
Refer to the CLI Guide for instructions to Upgrade StackGen CLI for other OS.
Usage
This command lets you switch between OpenTofu and Terraform.
stackgen [command] [--iac-tool=<provisioning engine>]
Flags
Flag | Description | Default |
---|---|---|
--iac-tool=tofu | Use OpenTofu for IaC | ✅ |
--iac-tool=terraform | Use HashiCorp Terraform for IaC |
Example: You can add the --iac-tool
flag with StackGen commands as shown below:
-
Provision your IaC using OpenTofu:
stackgen provision --appstack-id <appstack-id> --cloud-profile <aws-profile> --iac-tool=tofu --var 'region=us-west-2'
The above command provisions infrastructure for the specified
appstack-id
using the given AWS profile and region, with OpenTofu as the IaC tool. -
Detect Drifts using OpenTofu:
stackgen drift detect --appstack-id <appstack-id> --cloud-profile <aws-profile> --iac-tool=tofu --var 'region=us-west-2'
The above command detects drifts on the infrastructure that you provisioned above with OpenTofu as the IaC tool.
-
Destroy your IaC using the Terraform:
stackgen destroy --appstack-id <appstack-id> --iac-tool=tofu --var 'region=us-east-2'
The above command destroys the infrastructure for the specified
appstack-id
using the given AWS profile and region, with Terraform as the IaC tool.