This document provides essential guidance for AI agents working on the iacconsole-cli codebase.
iacconsole-cli is an infrastructure layers configuration orchestrator that dynamically manages OpenTofu or Terraform. It provides infrastructure configuration definitions from outside the Terraform code, using either files or an Infrastructure Layers Configuration Management Database (CMDB) called IaCConsole-DB. Its core purpose is to enable the reuse of Terraform code across multiple environments by separating configuration from the infrastructure code itself.
The key concepts are:
- units: Reusable, generic Terraform/OpenTofu code modules located in a
units_path(e.g.,examples/units/). Each subdirectory within an organization folder (e.g.,demo-org/vpc) is a "unit". - Inventory (Configuration Sources): Configuration data that can come from two sources:
- File-based: JSON files that define the configuration for different environments (
examples/inventory/). - IaCConsole-DB: External OpenAPI-based Configuration Management Database (CMDB).
- File-based: JSON files that define the configuration for different environments (
- Dimensions: Key-value pairs (
-d key:value) that select specific configuration objects (from either source) to apply to a unit. - Orchestration Flow:
iacconsole-clidynamically creates a temporary directory, copies the selectedunitcode, generates.tfvarsfiles from the specified dimension's inventory sources, and then executes thetofuorterraformcommand within that directory.
The main application logic is in Go (cmd/ and utils/ directories), while the infrastructure code it manages is HCL (Terraform) located in the examples/ directory.
main.go: Main entry point for the CLI application.cmd/exec.go: Implements the primaryexeccommand, which is the main orchestration logic.utils/: Contains the core Go helper functions.preparetemp.go: Logic for creating the temporary execution directory.generatevars.go: Logic for processing inventory files and generating Terraform variables.dimensions.go: Handles the parsing and management of dimension data.
examples/inventory/: Contains the hierarchical configuration data (JSON files). This is the "database" for the infrastructure configurations.examples/units/: Contains the reusable Terraform modules ("units").examples/.iacconsole-cli: An example of the user-level configuration file (usually located at$HOME/.iacconsole-cli). It defines paths and backend settings.
The primary workflow involves running the exec command to prepare and execute a Terraform/OpenTofu action.
Get the iacconsole-cli binary:
- Download pre-built binaries for Linux and macOS from the releases page
- Or build it yourself:
go build -o bin/iacconsole-cli .Run a typical command:
This command initializes the vpc unit for the test-account in the staging1 datacenter of the demo-org.
./bin/iacconsole-cli exec -o demo-org -d account:test-account -d datacenter:staging1 -u vpc -- init-o: Organization (subfolder ininventoryandunits).-d: Dimension (maps to a config file, e.g.,inventory/demo-org/datacenter/staging1.json).-t: unit (the Terraform code to use, e.g.,units/demo-org/vpc).--: Separator. Everything after it is passed directly to thetofuorterraformbinary (e.g.,plan,apply).
To debug, you can prevent the temporary directory from being deleted by using the -c=false flag (or by not using -c). This allows you to inspect the generated .tfvars and the final state of the execution directory.
iacconsole-cli supports two sources for infrastructure configuration ("inventory"):
-
File-based Inventory: By default,
iacconsole-clireads configuration from JSON files located in theinventory_pathspecified in the.iacconsole-cliconfig file. This is the primary method for local development and testing. -
IaCConsole-DB (CMDB): If the
IACCONSOLE_API_URLenvironment variable is set,iacconsole-cliwill fetch configuration from this external OpenAPI-based CMDB. This allows for centralized management of configurations.- The
IACCONSOLE_API_URLcontains the API endpoint and credentials. - To get a free account and API keys, visit https://iacconsole.com/, fill in the form with your Account Name, Email, and press Create Account.
- You'll receive generated credentials and a ready-to-use export command like
export IACCONSOLE_API_URL=https://6634b72292e9e996105de19e:generatedpassword@api.iacconsole.com. - Full API documentation is available at [Swagger API docs](https://app.swaggerhub.com/apis-docs/altuhovsu/iacconsole-api/.
- The
inventory-to-toaster.shscript inexamples/shows how to upload local inventory files to the database. - The CMDB can also be accessed directly from CI/CD pipelines like Jenkins:
- The
// Example Jenkins usage to fetch available dimension values
import groovy.json.JsonSlurper
def toasterDimValuesRequest(String dimkey){
def accessToken = "youraccountid:yourpassword".bytes.encodeBase64().toString()
def req = new URL("https://api.iacconsole.com/v1/dimension/demo-org/${dimkey}").openConnection();
req.setRequestProperty("Authorization", "Basic " + accessToken)
def content = req.getInputStream().getText()
json = new JsonSlurper().parseText(content)
return json.Dimensions.DimValue
}
println(toasterDimValuesRequest("datacenter")) // Returns [staging1, staging2]
println(toasterDimValuesRequest("account")) // Returns [test-account]- Go Code: The Go code is straightforward and follows standard practices. The core logic involves file system operations (
os,path/filepath), JSON parsing (encoding/json), and command execution (os/exec). - Variable Injection:
iacconsole-cliinjects variables into the Terraform context:- For a dimension
-d datacenter:staging1, it createsvar.iacconsole-cli_datacenter_name,var.iacconsole-cli_datacenter_data, andvar.iacconsole-cli_datacenter_defaults. - Environment variables prefixed with
iacconsole-cli_envvar_(e.g.,export iacconsole-cli_envvar_aws_region=us-east-1) are available in Terraform asvar.iacconsole-cli_envvar_aws_region.
- For a dimension
- Configuration Files:
unit_manifest.jsoninside a unit directory can declare required dimensions.dim_defaults.jsoninside an inventory dimension directory provides default values for all items in that dimension.
- Backend State: Remote state configuration is managed via the
.iacconsole-cliconfig file. The state path ($iacconsole_state_path) is dynamically generated based on the organization and dimensions to ensure state isolation.