This repository provides a Docker environment for working with OpenTofu, as well as instructions for configuring your .zshrc
to streamline your workflow.
-
Build the Docker Image:
Use the following command to build the Docker image. Ensure the path points to your local OpenTofu directory:
docker build --platform linux/amd64 -t opentofu-env ~/yourrepo/
-
Environment Details:
- Base Image: Ubuntu 22.04
- Dependencies: curl, gnupg, lsb-release, git
- OpenTofu Installation: Automated via script from OpenTofu
-
Working Directory:
The working directory inside the container is set to
/workspace
. -
Entrypoint:
By default, the container runs:
tofu init && tofu plan
The provided script (opentofu.sh
) automates the setup and execution process:
-
Format with
tofu fmt
:Ensures your configuration files are properly formatted.
-
Identify Modules Directories:
The script searches for
modules
directories in the current working directory hierarchy. -
Docker Run Command:
Depending on whether a
modules
directory is found, it executes Docker with mounted volumes:- Current directory (
/workspace
) - Found
modules
directory (optional) - AWS credentials (
~/.aws
)
Example with modules:
docker run --platform linux/amd64 -it --rm \ -v "$current_dir:/workspace" \ -v "$modules_dir:/modules" \ -v ~/.aws:/root/.aws \ opentofu-env /bin/bash -c 'echo /workspace; ls -R /workspace; echo /modules; ls -R /modules; tofu init && tofu plan'
- Current directory (
-
Execute the Script:
Run the shell script to automatically find modules directories and execute the Docker container:
./opentofu.sh
-
Customizing the Script:
Modify the script as necessary for your specific environment and requirements.
- Ensure Docker is installed and running on your machine.
- The script assumes AWS credentials are stored at
~/.aws
. - Adjust paths and configurations as per your project structure.
To ensure a smooth experience with OpenTofu, you may need to modify your .zshrc
file. Below are the recommended steps and configurations.
-
Open
.zshrc
File:Use a text editor to open your
.zshrc
file. You can usenano
,vim
, or any editor of your choice:nano ~/.zshrc
-
Add OpenTofu Alias:
Add the following alias to your
.zshrc
to quickly run your OpenTofu script:# OpenTofu alias alias tofuplan="~/yourrepo/opentofu.sh"
-
Save and Close the File:
After making the changes, save the file (
CTRL + O
innano
,:wq
invim
) and close it. -
Apply Changes:
Reload the
.zshrc
file to apply your changes without restarting the terminal:source ~/.zshrc
By adding these configurations, you streamline your workflow and enable quick access to OpenTofu commands. Adjust as needed for your personal setup.