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

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>]
note

Currently, the following ILM actions have the supported --iac-tool flag:

Flags

FlagDescriptionDefault
--iac-tool=tofuUse OpenTofu for IaC
--iac-tool=terraformUse 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.