OpenTofu

Terraform/OpenTofu Notes

Using Workspaces for Environment Separation

Terraform workspaces are a powerful feature that allows you to manage multiple environments (such as dev, staging, and prod) within the same configuration. For example, to switch to the production workspace:

tofu workspace select prod

Applying Configuration Changes

When applying changes to your Terraform configuration, you can specify a variable file for different environments and approve the changes automatically:

tofu apply -var-file ./dev.tfvars -auto-approve

Importing Existing Resources

To import an existing resource into Terraform’s state, use the import command with the appropriate variable file: