The Terraform Decoded script automates the setup of a modular and efficient Terraform development environment. It's designed to simplify the creation of a structured Terraform project, handling Terraform initialization, .gitignore
file creation, and AWS CLI profile selection.
- Automated Directory Structure: Creates a well-organized directory structure for Terraform projects.
- AWS Profile Integration: Enables the selection of an AWS CLI profile for Terraform configurations, simplifying AWS resource management.
- Terraform Initialization: Provides an option to automatically run
terraform init
. - Gitignore Initialization: Generates a
.gitignore
file tailored for Terraform projects to exclude sensitive or unnecessary files from version control.
Before running the script, ensure the following requirements are met:
- Operating System: Linux. The script uses bash syntax and Linux-specific commands which may not be compatible with other operating systems.
- AWS CLI: Installed and configured with at least one profile. This is necessary for the script to allow AWS profile selection for Terraform configurations.
- Terraform: Installed locally. The script expects Terraform to be available for initializing directories and setting up configurations.
- Bash Environment: The script is a Bash script and requires a Bash shell to run.
No specific installation is required for the script itself. However, make sure you have the necessary permissions to execute it:
Clone from github.
git clone https://github.com/erikngigi/Terraform-Environemnt-Automation.git
Make the shell script executable
cd Terraform-Environemnt-Automation
chmod +x terraform-start.sh
Execute the script within the directory where you want to initialize your Terraform project:
./terraform-start.sh
Follow the interactive prompts to:
- Create a new directory structure for your Terraform project.
- Select an AWS CLI profile for your Terraform configurations.
- Initialize the directory with Terraform.
- Generate a
.gitignore
file appropriate for Terraform projects.
The script starts by defining ANSI escape codes for coloring output, enhancing the readability and user experience.
check_credentials_file
ensures the AWS CLI is properly configured by checking for the existence of the AWS credentials file.
directory_structure_template
creates a comprehensive directory and file structure for a Terraform project, including directories for modules (like containers, instances, databases), and base Terraform files (main.tf
, outputs.tf
, etc.).
extract_profiles
and prompt_for_profile_selection
assist in selecting an AWS CLI profile from the configured profiles, which is then integrated into the Terraform configuration to manage AWS resources.
The script offers options to initialize Terraform in the new project directory and to create a .gitignore
file, ensuring that sensitive or unnecessary files are not tracked in version control.
Upon execution, the script sets up a Terraform project structure with directories for documentation, infrastructure (with submodules for different components), and files necessary for Terraform and AWS configurations.
- Welcome Message: The script begins with a greeting and a brief introduction.
- Directory Structure Creation: Prompts the user to create a new Terraform project directory.
- AWS Profile Selection: Allows choosing an AWS CLI profile to configure the Terraform provider.
- Terraform Initialization: Offers to run
terraform init
in the new directory. .gitignore
File Creation: Proposes to create a.gitignore
file tailored for Terraform projects.
.
├── main.tf
├── modules
│ ├── containers - (Manages containerized applications and their configurations.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── templates
│ │ │ └── app.json.tpl
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── database - (Sets up and maintains database resources like RDS or DynamoDB.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── instances - (Provisions and configures virtual machine instances.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── templates
│ │ │ └── extras.sh
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── management - (Oversees administrative and management tools or services.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── network - (Defines and configures networking components such as VPCs, subnets, and security groups.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── notifications - (Handles setup for notification services and alerting mechanisms.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── templates
│ │ │ └── email-sns-stack.json.tpl
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── scaling - (Manages auto-scaling policies and resources to ensure application scalability.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── security - (Implements security measures, including IAM roles, policies, and security configurations.)
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── templates
│ │ │ ├── ecs-ec2-role-policy.json.tpl
│ │ │ ├── ecs-ec2-role.json.tpl
│ │ │ └── ecs-service-role.json.tpl
│ │ ├── variables.tf
│ │ └── versions.tf
│ └── storage - (Manages storage solutions like S3 buckets, EBS volumes, and other data storage resources.)
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── outputs.tf
├── provider.tf
├── README.md
├── terraform.tfstate
├── terraform.tfstate.backup
├── terraform.tfvars
└── variables.tf
- Cross-Platform Compatibility: Adapt the script for compatibility with other operating systems, such as macOS and Windows, ensuring a broader user base can utilize it.
- Cloud Provider Flexibility: Introduce options for configuring multiple cloud providers (e.g., Azure, Google Cloud) in addition to AWS, catering to projects that span across different clouds.
- Interactive Menu for Terraform Versions: Implement a feature to select different Terraform versions for initialization, allowing users to work with specific versions as per project requirements.
- Advanced Directory Structure Customization: Provide users with options to customize the directory structure based on project size or type (e.g., microservices, monolith), including naming conventions.
- Error Handling and Validation: Enhance error handling and input validation throughout the script to minimize execution failures and guide users through correcting inputs.
- Sensitive Data Management: Integrate mechanisms to securely handle sensitive data, such as secret management tools or encryption for
.tfvars
files containing sensitive information. - Audit Logging: Add functionality to log script activities, such as changes made to the filesystem and AWS CLI profile selections, aiding in troubleshooting and auditing.
- Help Command: Implement a
--help
command that displays usage information, command options, and a brief description of the script’s functionality. - Verbose Mode: Add a verbose mode (
-v
flag) for detailed output during script execution, offering insights into the operations being performed. - Documentation Update: Regularly update the documentation to reflect new features, usage examples, and FAQs to assist users in navigating complex scenarios.
- CI/CD Pipeline Integration: Provide guidelines or templates for integrating the generated Terraform project structure with popular CI/CD tools (e.g., Jenkins, GitHub Actions, GitLab CI).
- Version Control System Integration: Automate the initial commit to a version control system (e.g., Git) with an option to link the repository to remote VCS providers like GitHub, GitLab, or Bitbucket.
- Unit and Integration Tests: Develop a suite of unit and integration tests to ensure script reliability and functionality across updates and environmental changes.
- Script Modularity: Refactor the script into modular components to facilitate easier updates, maintenance, and customization by the community or individual users.
- Open Source Contribution Guidelines: Establish clear guidelines for community contributions, including how to propose features, report issues, and submit pull requests.
- Localization: Add support for multiple languages in script prompts and documentation, making the tool accessible to a global audience.
This checklist not only aims to guide future development efforts but also encourages community involvement in enhancing and expanding the script's capabilities. By addressing these items, the Terraform Decoded script can evolve into an even more powerful and versatile tool for infrastructure management and development.
The Terraform Decoded script is a convenient tool for quickly setting up a Terraform project with a structured directory layout, initialized Terraform environment, and integrated AWS CLI profile selection. By following the prerequisites and utilizing the script as described, developers can significantly streamline their Terraform project setup process on Linux systems.
To further enhance the Terraform Decoded script and ensure it meets a wide range of development requirements, here's a possible TODO checklist. This list aims to guide future improvements and feature integrations, making the script more versatile and user-friendly.