|
1 | | -<!-- |
2 | | - ** MANAGED BY AWS CODE HABITS |
3 | | - ** DO NOT EDIT THIS FILE |
4 | | - ** |
5 | | - ** 1) Make all changes to `doc/habits.yaml` |
6 | | - ** 2) Run `make doc/build` to rebuild this file |
7 | | - ** |
8 | | ---> |
| 1 | +# Terraform Development Environment |
9 | 2 |
|
10 | | -![logo][logo] |
| 3 | +A comprehensive VS Code Dev Container with tools to help you build and manage infrastructure with Terraform across AWS, Azure, and GCP. |
11 | 4 |
|
| 5 | +## Features |
12 | 6 |
|
13 | | -# AWS Terraform Dev Container |
| 7 | +- **Multi-cloud Support**: Pre-installed CLIs and tools for AWS, Azure, and GCP |
| 8 | +- **Terraform Ecosystem**: Complete suite of Terraform tools including terraform-docs, tflint, tfsec, terrascan, and more |
| 9 | +- **Security Best Practices**: Pre-commit hooks for security scanning and credential management |
| 10 | +- **Developer Experience**: VS Code integration with tasks, settings, and extensions |
| 11 | +- **Performance Optimization**: Caching strategies and optimized volume mounts |
14 | 12 |
|
15 | | -A VSCode Dev Container with [tools][tools] to help you build and manage AWS infrastructure with Terraform |
| 13 | +## Prerequisites |
16 | 14 |
|
17 | | -|  | |
18 | | -|:--:| |
19 | | -| *Develop your project in a Docker container* | |
| 15 | +- [Docker](https://www.docker.com/products/docker-desktop/) - Required for running containers |
| 16 | +- [Visual Studio Code](https://code.visualstudio.com/) - The recommended IDE |
| 17 | +- [VS Code Remote Development Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) - Required for Dev Containers |
20 | 18 |
|
21 | | -|  | |
22 | | -|:--:| |
23 | | -| *Increase productivity with well-defined `Make` commands* | |
| 19 | +## Getting Started |
24 | 20 |
|
25 | | -|  | |
26 | | -|:--:| |
27 | | -| *Ensure every team member has all the tools on their correct versions* | |
| 21 | +1. Clone this repository: |
| 22 | + ```bash |
| 23 | + git clone <repository-url> |
| 24 | + ``` |
28 | 25 |
|
29 | | -|  | |
30 | | -|:--:| |
31 | | -| *Extensions already installed for you* | |
| 26 | +2. Open the folder in VS Code: |
| 27 | + ```bash |
| 28 | + code . |
| 29 | + ``` |
32 | 30 |
|
| 31 | +3. When prompted, click "Reopen in Container" or use the command palette (F1) and select "Remote-Containers: Reopen in Container" |
33 | 32 |
|
34 | | -## Table of Contents |
| 33 | +4. Wait for the container to build and initialize (this may take a few minutes the first time) |
35 | 34 |
|
36 | | -- [Getting Started](#getting-started) |
| 35 | +## Included Tools |
37 | 36 |
|
38 | | -- [Prerequisites](#prerequisites) |
| 37 | +| Tool | Version | Description | |
| 38 | +|------|---------|-------------| |
| 39 | +| Terraform | 1.5.7 | Infrastructure as Code tool | |
| 40 | +| AWS CLI | v2 | Command line interface for AWS | |
| 41 | +| Azure CLI | Latest | Command line interface for Azure | |
| 42 | +| Google Cloud SDK | Latest | Command line interface for GCP | |
| 43 | +| terraform-docs | 0.16.0 | Documentation generator for Terraform modules | |
| 44 | +| tflint | 0.47.0 | Terraform linter | |
| 45 | +| tfsec | 1.28.0 | Security scanner for Terraform code | |
| 46 | +| terrascan | 1.18.3 | Detect compliance and security violations | |
| 47 | +| terragrunt | 0.48.0 | Thin wrapper for Terraform that provides extra tools | |
| 48 | +| infracost | 0.10.28 | Cloud cost estimates for Terraform | |
| 49 | +| checkov | 2.3.360 | Static code analysis tool for IaC | |
| 50 | +| pre-commit | Latest | Framework for managing git pre-commit hooks | |
39 | 51 |
|
| 52 | +## Authentication |
40 | 53 |
|
41 | | -- [Usage](#usage) |
| 54 | +The container includes helper scripts for authenticating with each cloud provider: |
42 | 55 |
|
| 56 | +### AWS Authentication |
43 | 57 |
|
| 58 | +```bash |
| 59 | +.devcontainer/scripts/aws-auth.sh [--profile PROFILE] [--region REGION] [--sso] |
| 60 | +``` |
44 | 61 |
|
| 62 | +### Azure Authentication |
45 | 63 |
|
46 | | -## Getting Started |
| 64 | +```bash |
| 65 | +.devcontainer/scripts/azure-auth.sh [--subscription SUBSCRIPTION_ID] [--tenant TENANT_ID] [--service-principal] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] |
| 66 | +``` |
| 67 | + |
| 68 | +### GCP Authentication |
47 | 69 |
|
48 | | -1. On a terminal, inside your Terraform project, execute the following on Mac, Linux or [WSL][wsl]: |
49 | 70 | ```bash |
50 | | -curl -sL https://raw.githubusercontent.com/awslabs/aws-terraform-dev-container/main/scripts/init.sh | bash |
51 | | -```` |
52 | | -2. Open the folder with VSCode |
53 | | -3. Reopen in Container |
| 71 | +.devcontainer/scripts/gcp-auth.sh [--project PROJECT_ID] [--credentials FILE_PATH] |
| 72 | +``` |
54 | 73 |
|
55 | | -To reopen in container manually, open the [command pallete](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) on VS Code and select `Rebuild and Reopen in Container` |
| 74 | +## VS Code Tasks |
56 | 75 |
|
| 76 | +The environment includes pre-configured VS Code tasks for common operations: |
57 | 77 |
|
58 | | -## Prerequisites |
59 | | - A list of things you need, or how to install them. |
| 78 | +- **Terraform: Init** - Initialize a Terraform working directory |
| 79 | +- **Terraform: Plan** - Generate and show an execution plan |
| 80 | +- **Terraform: Apply** - Build or change infrastructure |
| 81 | +- **Terraform: Destroy** - Destroy Terraform-managed infrastructure |
| 82 | +- **Terraform: Validate** - Validate the Terraform files |
| 83 | +- **Terraform: Format** - Rewrite Terraform configuration files to canonical format |
| 84 | +- **TFLint: Run** - Run TFLint for static analysis |
| 85 | +- **TFSec: Run** - Run TFSec for security scanning |
| 86 | +- **Checkov: Run** - Run Checkov for compliance checks |
| 87 | +- **Pre-commit: Run All Hooks** - Run all pre-commit hooks |
60 | 88 |
|
61 | | -- [Docker](https://www.docker.com/products/docker-desktop/) - The fastest way to containerize applications |
62 | | -- [Visual Studio Code](https://code.visualstudio.com/) - Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. |
63 | | -- [VSCode Remote Development Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) - An extension pack that lets you open any folder in a container, on a remote machine, or in WSL and take advantage of VS Code's full feature set. |
| 89 | +To run a task, press `Ctrl+Shift+P` (or `Cmd+Shift+P` on macOS) and select "Tasks: Run Task", then choose the task you want to run. |
64 | 90 |
|
| 91 | +## Pre-commit Hooks |
65 | 92 |
|
| 93 | +The environment includes pre-configured pre-commit hooks for Terraform validation, formatting, and security scanning. To install the hooks: |
66 | 94 |
|
67 | | -## Usage |
68 | | -```bash |
69 | | -make [tab][tab] |
70 | | -``` |
71 | | -For example, if you want to explore the most common [terraform][terraform] commands: |
72 | 95 | ```bash |
73 | | -make terraform/[tab] |
74 | | -apply clean destroy fmt init init/ plan validate version |
| 96 | +pre-commit install |
75 | 97 | ``` |
76 | 98 |
|
77 | | -To display all available commands: |
78 | | -```bash |
79 | | -make help |
80 | | -``` |
81 | | -For more information about each [Make targets available](Makefile.md). |
| 99 | +## Environment Variables |
82 | 100 |
|
| 101 | +Environment variables for Terraform and cloud providers can be configured in `.devcontainer/config/terraform.env`. The following variables are available: |
83 | 102 |
|
| 103 | +### Terraform Configuration |
84 | 104 |
|
| 105 | +- `TF_PLUGIN_CACHE_DIR` - Directory for caching Terraform plugins |
| 106 | +- `TF_CLI_ARGS_init` - Arguments for `terraform init` |
| 107 | +- `TF_CLI_ARGS_plan` - Arguments for `terraform plan` |
| 108 | +- `TF_CLI_ARGS_apply` - Arguments for `terraform apply` |
| 109 | +- `TF_LOG` - Terraform logging level |
85 | 110 |
|
| 111 | +### AWS Provider Configuration |
86 | 112 |
|
87 | | -## References |
88 | | -- [Terraform by HashiCorp](https://www.terraform.io) - Terraform is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure. |
89 | | -- [Changelog](CHANGELOG.md) - All notable changes. |
90 | | -- [Code Of Conduct](CODE_OF_CONDUCT.md) - Amazon Open Source Code of Conduct |
91 | | -- [Contributing](CONTRIBUTING.md) - Learn how to contribute |
92 | | -- [License](LICENSE) - MIT No Attribution |
93 | | -- [GNU Make](https://www.gnu.org/software/make/manual/make.html) - If you are new to make, or are looking for a general introduction. |
| 113 | +- `AWS_PROFILE` - AWS profile to use |
| 114 | +- `AWS_REGION` - AWS region to use |
| 115 | +- `AWS_SDK_LOAD_CONFIG` - Load config from AWS config file |
94 | 116 |
|
| 117 | +### Azure Provider Configuration |
95 | 118 |
|
96 | | -## License |
97 | | -This project is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file. |
| 119 | +- `ARM_SUBSCRIPTION_ID` - Azure subscription ID |
| 120 | +- `ARM_TENANT_ID` - Azure tenant ID |
| 121 | +- `ARM_CLIENT_ID` - Azure client ID |
| 122 | +- `ARM_CLIENT_SECRET` - Azure client secret |
| 123 | + |
| 124 | +### GCP Provider Configuration |
| 125 | + |
| 126 | +- `GOOGLE_APPLICATION_CREDENTIALS` - Path to GCP service account key file |
| 127 | +- `CLOUDSDK_CORE_PROJECT` - GCP project ID |
98 | 128 |
|
99 | | -## Copyright |
100 | | -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 129 | +## Customization |
101 | 130 |
|
| 131 | +### Adding Custom Tools |
102 | 132 |
|
103 | | -[repo]: https://gitlab.aws.dev/proserve-labs/aws-terraform-dev-container |
104 | | -[logo]: doc/logo.png |
| 133 | +To add custom tools to the container, modify the `.devcontainer/Dockerfile` and add your installation commands. |
| 134 | + |
| 135 | +### Customizing VS Code Settings |
| 136 | + |
| 137 | +VS Code settings can be customized in `.vscode/settings.json`. |
| 138 | + |
| 139 | +### Customizing Pre-commit Hooks |
| 140 | + |
| 141 | +Pre-commit hooks can be customized in `.pre-commit-config.yaml`. |
| 142 | + |
| 143 | +## Volume Mounts |
| 144 | + |
| 145 | +The container includes the following volume mounts: |
| 146 | + |
| 147 | +- `~/.aws` - AWS credentials and configuration |
| 148 | +- `~/.azure` - Azure credentials and configuration |
| 149 | +- `~/.config/gcloud` - GCP credentials and configuration |
| 150 | +- `~/.ssh` - SSH keys |
| 151 | +- `terraform-cache` - Terraform plugin cache |
| 152 | + |
| 153 | +## Security Considerations |
| 154 | + |
| 155 | +- Credentials are mounted from the host to avoid storing them in the container |
| 156 | +- Pre-commit hooks include security scanning for Terraform code |
| 157 | +- Secret detection is enabled to prevent committing sensitive information |
| 158 | + |
| 159 | +## Troubleshooting |
| 160 | + |
| 161 | +### Common Issues |
| 162 | + |
| 163 | +1. **Docker not running**: Ensure Docker is running on your system |
| 164 | +2. **Permission issues**: Ensure you have the necessary permissions for the mounted volumes |
| 165 | +3. **Authentication failures**: Check your credentials and ensure they are properly configured |
| 166 | + |
| 167 | +### Logs |
| 168 | + |
| 169 | +Container logs can be viewed in VS Code by clicking on the "Remote" indicator in the bottom-left corner and selecting "Show Container Log". |
| 170 | + |
| 171 | +## License |
105 | 172 |
|
106 | | -[docker]: https://www.docker.com/products/docker-desktop/ |
107 | | -[vscode-dev-container]: https://code.visualstudio.com/docs/remote/containers |
108 | | -[terraform]: https://www.terraform.io |
109 | | -[license]: LICENSE |
110 | | -[tools]: TOOLS |
111 | | -[wsl]: https://learn.microsoft.com/en-us/windows/wsl/install |
| 173 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments