Overview
Suga uses CDKTF (Cloud Development Kit for Terraform) to generate Terraform configurations. By default, the generated stacks use local state files. For production environments and team collaboration, you’ll want to configure a remote backend to store your Terraform state securely and enable state locking. This guide covers how to add backend configuration to your Suga-generated Terraform stacks for common backend providers.Prerequisites
Ensure you have completed these steps before configuring a backend.
- Generate your Terraform stack using
suga build
(this runs CDKTF synthesis) - Choose a backend provider (AWS S3, Google Cloud Storage, Azure Storage, Terraform Cloud, etc.)
- Create the backend storage resources (bucket, storage account, workspace, etc.)
- Ensure proper permissions are configured for accessing the backend
Understanding Suga’s CDKTF Output
When you runsuga build
, CDKTF synthesizes your infrastructure into standard Terraform JSON configuration files:
Generated Directory Structure
terraform
directory.
Adding Backend Configuration
After runningsuga build
, add a backend configuration file to the synthesized output:
1
Generate the Stack
Generate Terraform Stack
2
Create Backend Configuration
Create
backend.tf
in the synthesized stack directory:Create Backend File
3
Add Backend Configuration
Choose your backend provider and add the appropriate configuration:
backend.tf - AWS S3
Ensure your S3 bucket has versioning enabled and consider enabling MFA delete for production environments.
4
Initialize and Deploy
Initialize Terraform
Deploy Infrastructure
Only the cdktf files are managed by Suga. You can safely add custom
.tf
files to the stack directory to extend the configuration.Managing Multiple Environments
For managing multiple environments, we recommend using Terraform workspaces:Create and Switch Workspaces
Each workspace maintains its own state file, allowing you to manage different environments with the same configuration.