├── .devcontainer ├── README.md └── devcontainer.json ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── pull_request_template.md └── workflows │ ├── hygiene.yaml │ ├── release-please.yml │ └── test.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── .prettierignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Makefile.md ├── README.md ├── SECURITY.md ├── doc ├── habits.yaml ├── logo.png └── logo.svg ├── files ├── aws │ └── cloudformation │ │ ├── parameters.json │ │ └── template.yml ├── pre-commit │ └── .pre-commit-config.yaml └── terraform │ ├── .pre-commit-config.yaml │ └── .tflint.hcl ├── lib ├── ansible │ ├── ansible.cfg │ ├── files │ │ ├── aws │ │ │ └── config │ │ ├── doc │ │ │ ├── CHANGELOG.md │ │ │ ├── CODE_OF_CONDUCT.md │ │ │ ├── CONTRIBUTING.md │ │ │ ├── SECURITY.md │ │ │ ├── habits.yaml │ │ │ └── logo.png │ │ └── github │ │ │ ├── ISSUE_TEMPLATE │ │ │ ├── bug_report.md │ │ │ ├── feature_request.md │ │ │ └── question.md │ │ │ ├── actions │ │ │ └── .keep │ │ │ ├── pull_request_template.md │ │ │ └── workflows │ │ │ └── .keep │ ├── hosts │ ├── playbooks │ │ ├── aws │ │ │ └── config │ │ │ │ ├── init.yaml │ │ │ │ └── remove.yaml │ │ ├── doc │ │ │ ├── build.yaml │ │ │ ├── init.yaml │ │ │ └── remove.yaml │ │ ├── github │ │ │ ├── actions │ │ │ │ ├── init.yaml │ │ │ │ └── remove.yaml │ │ │ ├── issues │ │ │ │ ├── init.yaml │ │ │ │ └── remove.yaml │ │ │ ├── pull-request │ │ │ │ ├── init.yaml │ │ │ │ └── remove.yaml │ │ │ └── workflows │ │ │ │ ├── init.yaml │ │ │ │ └── remove.yaml │ │ ├── habits │ │ │ └── remove.yaml │ │ └── ubuntu │ │ │ ├── install.yaml │ │ │ └── update.yaml │ └── templates │ │ └── readme.j2 ├── make │ ├── ansible.mk │ ├── aws │ │ ├── amplify.mk │ │ ├── cdk.mk │ │ ├── cfn-lint.mk │ │ ├── cli.mk │ │ ├── cloudformation.mk │ │ ├── cloudwatch.mk │ │ ├── code-artifact.mk │ │ ├── cognito.mk │ │ ├── config.mk │ │ ├── dynamodb.mk │ │ ├── sigv4-proxy.mk │ │ ├── sso.mk │ │ ├── sts.mk │ │ └── systems-manager.mk │ ├── checkov.mk │ ├── cobra.mk │ ├── devcontainer.mk │ ├── doc.mk │ ├── docker.mk │ ├── git.mk │ ├── github.mk │ ├── gitignore.mk │ ├── go.mk │ ├── gomplate.mk │ ├── habits.mk │ ├── make │ │ ├── helpers.mk │ │ └── test.mk │ ├── nodejs.mk │ ├── npm.mk │ ├── nuke.mk │ ├── nvm.mk │ ├── pnpm.mk │ ├── pre-commit.mk │ ├── prettier.mk │ ├── python.mk │ ├── terraform-docs.mk │ ├── terraform.mk │ ├── terrascan.mk │ ├── tflint.mk │ ├── tfsec.mk │ ├── tfswitch.mk │ └── ubuntu.mk └── scripts │ ├── banner.sh │ ├── gitignore.sh │ ├── post-start.sh │ └── python │ └── aws │ ├── sigv4-test.py │ └── take-snapshot-opensearch.py ├── scripts ├── Makefile ├── README.md ├── remote │ ├── init.sh │ └── install.sh └── standalone │ ├── init.sh │ └── install.sh └── tools.env /.devcontainer/README.md: -------------------------------------------------------------------------------- 1 | ## Troubleshooting 2 | 3 | ### Using SSH-Agent on Windows 10 WSL2 4 | 5 | On WSL, Ubuntu: 6 | 7 | ```bash 8 | sudo apt-get install keychain 9 | ``` 10 | 11 | Edit your `~/.bashrc`, `~/.zshrc` and add the following to the bottom of your file: 12 | 13 | ```bash 14 | # For Loading the SSH key 15 | /usr/bin/keychain -q --nogui "${HOME}/.ssh/id_rsa" 16 | source "${HOME}/.keychain/${HOSTNAME}-sh" 17 | ``` 18 | 19 | - [Source](https://esc.sh/blog/ssh-agent-windows10-wsl2/) 20 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AWS Code Habits", 3 | "image": "mcr.microsoft.com/devcontainers/base:bullseye", 4 | "features": { 5 | "ghcr.io/devcontainers-contrib/features/ansible": { 6 | "version": "latest" 7 | }, 8 | "ghcr.io/devcontainers-contrib/features/pre-commit": { 9 | "version": "latest" 10 | } 11 | }, 12 | "postCreateCommand": "sudo apt -qq update && sudo apt -qq install --yes bash-completion make", 13 | "postStartCommand": "sudo apt -qq update" 14 | } 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: Create a new ticket for a bug. 4 | --- 5 | 6 | 7 | 8 | - Version: 9 | - Local OS Version: 10 | - Local chip architecture: 11 | - Reproduces in: 12 | 13 | Steps to Reproduce: 14 | 15 | 1. 16 | 2. 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 💡 Feature Request 3 | about: Create a new ticket for a new feature request 4 | --- 5 | 6 | Type your idea here. 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ❔ Question 3 | about: What is your question about? 4 | --- 5 | 6 | Add more context here. 7 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## 🧠 Pull Request 2 | 3 | ### Changes 4 | 5 | 6 | 7 | ### Type of change 8 | 9 | 16 | 17 | ## Why 18 | 19 | 20 | 21 | ## How (Optional) 22 | 23 | 24 | 25 | ## Checklist 26 | 27 | 28 | 29 | 30 | - [ ] Jest unit tests (as needed) 31 | - [ ] Integration tests (as needed) 32 | - [ ] Storybook stories (as needed) 33 | - [ ] Run storybook locally 34 | - [ ] Acceptance Criteria met 35 | - [ ] Screenshot added to Summary for UI ticket 36 | - [ ] Check test coverage of new or updated components (Reduce Banlist) 37 | 38 | 43 | -------------------------------------------------------------------------------- /.github/workflows/hygiene.yaml: -------------------------------------------------------------------------------- 1 | name: Hygiene 2 | 3 | on: 4 | push: 5 | branches: 6 | - feature/* 7 | - bugfix/* 8 | - hotfix/* 9 | - develop 10 | - main 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | code-hygiene: 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - uses: actions/checkout@v3 21 | 22 | - name: Set up Python 3.10 23 | uses: actions/setup-python@v4 24 | with: 25 | python-version: "3.10" 26 | 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | pip install pre-commit 31 | 32 | - name: Install pre-commit hooks and execute rules 33 | run: pre-commit run --all-files 34 | 35 | doc-hygiene: 36 | needs: code-hygiene 37 | runs-on: ubuntu-latest 38 | 39 | steps: 40 | - uses: actions/checkout@v3 41 | 42 | - name: Build documentation 43 | run: make doc/build 44 | 45 | - name: Check documentation status 46 | run: git diff --exit-code # exit 1 if there's a difference between what was pushed with what was produced by doc/build. 47 | -------------------------------------------------------------------------------- /.github/workflows/release-please.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | 6 | name: Release 7 | jobs: 8 | release-please: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: google-github-actions/release-please-action@v3 12 | with: 13 | release-type: simple 14 | package-name: aws-code-habits 15 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | push: 4 | branches: 5 | - main 6 | schedule: 7 | - cron: "0 0 * * *" 8 | 9 | jobs: 10 | habits: 11 | runs-on: [ubuntu-latest] 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: Habits Install 16 | run: make habits/install 17 | 18 | - name: Habits Init 19 | run: make habits/init 20 | 21 | - name: Generate documentation 22 | run: make doc/build 23 | 24 | - name: Habits Check 25 | run: make habits/check 26 | 27 | - name: Uninstall Habits 28 | run: make habits/remove 29 | checkov: 30 | runs-on: [ubuntu-latest] 31 | steps: 32 | - uses: actions/checkout@v4 33 | 34 | - name: Checkov Install 35 | run: make checkov/install 36 | 37 | - name: Checkov version 38 | run: make checkov/version 39 | cobra: 40 | runs-on: [ubuntu-latest] 41 | steps: 42 | - uses: actions/checkout@v4 43 | 44 | - name: Cobra Install 45 | run: make go/install cobra/install 46 | 47 | # - name: Cobra version 48 | # run: make cobra/version # TODO 49 | go: 50 | runs-on: [ubuntu-latest] 51 | steps: 52 | - uses: actions/checkout@v4 53 | 54 | - name: Go Install 55 | run: make go/install 56 | 57 | - name: Go version 58 | run: make go/version 59 | gomplate: 60 | runs-on: [ubuntu-latest] 61 | steps: 62 | - uses: actions/checkout@v4 63 | 64 | - name: Gomplate Install 65 | run: make gomplate/install 66 | 67 | - name: Gomplate version 68 | run: make gomplate/version 69 | nodejs: 70 | runs-on: [ubuntu-latest] 71 | steps: 72 | - uses: actions/checkout@v4 73 | 74 | - name: NodeJS Install 75 | run: make nodejs/install 76 | 77 | - name: NodeJS version 78 | run: make nodejs/version 79 | npm: 80 | runs-on: [ubuntu-latest] 81 | steps: 82 | - uses: actions/checkout@v4 83 | 84 | - name: NPM Install 85 | run: make npm/install 86 | 87 | - name: NPM version 88 | run: make npm/version 89 | nuke: 90 | runs-on: [ubuntu-latest] 91 | steps: 92 | - uses: actions/checkout@v4 93 | 94 | - name: Nuke Install 95 | run: make nuke/install 96 | 97 | - name: Nuke version 98 | run: make nuke/version 99 | pre-commit: 100 | runs-on: [ubuntu-latest] 101 | steps: 102 | - uses: actions/checkout@v4 103 | 104 | - name: Pre-Commit Install 105 | run: make pre-commit/install 106 | 107 | - name: Pre-Commit version 108 | run: make pre-commit/version 109 | prettier: 110 | runs-on: [ubuntu-latest] 111 | steps: 112 | - uses: actions/checkout@v4 113 | 114 | - name: Setup NPM Global 115 | run: make npm/install-global npm/update-path 116 | 117 | - name: Install Prettier 118 | run: make prettier/install 119 | 120 | - name: Prettier version 121 | run: make prettier/version 122 | terraform: 123 | runs-on: [ubuntu-latest] 124 | steps: 125 | - uses: actions/checkout@v4 126 | 127 | - name: Terraform Install 128 | run: make terraform/install 129 | 130 | - name: Terraform version 131 | run: make terraform/version 132 | terraform-docs: 133 | runs-on: [ubuntu-latest] 134 | steps: 135 | - uses: actions/checkout@v4 136 | 137 | - name: Terraform-Docs Install 138 | run: make terraform-docs/install 139 | 140 | - name: Terraform-Docs version 141 | run: make terraform-docs/version 142 | terrascan: 143 | runs-on: [ubuntu-latest] 144 | steps: 145 | - uses: actions/checkout@v4 146 | 147 | - name: Terrascan Install 148 | run: make terrascan/install 149 | 150 | - name: Terrascan version 151 | run: make terrascan/version 152 | tflint: 153 | runs-on: [ubuntu-latest] 154 | steps: 155 | - uses: actions/checkout@v4 156 | 157 | - name: TFLint Install 158 | run: make tflint/install 159 | 160 | - name: TFLint version 161 | run: make tflint/version 162 | tfsec: 163 | runs-on: [ubuntu-latest] 164 | steps: 165 | - uses: actions/checkout@v4 166 | 167 | - name: Tfsec Install 168 | run: make tfsec/install 169 | 170 | - name: Tfsec version 171 | run: make tfsec/version 172 | tfswitch: 173 | runs-on: [ubuntu-latest] 174 | steps: 175 | - uses: actions/checkout@v4 176 | 177 | - name: Tfswitch Install 178 | run: make tfswitch/install 179 | 180 | - name: Tfswitch version 181 | run: make tfswitch/version 182 | ubuntu: 183 | runs-on: [ubuntu-latest] 184 | steps: 185 | - uses: actions/checkout@v4 186 | 187 | - name: Ubuntu version 188 | run: make ubuntu/version 189 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/macos,windows,linux,visualstudiocode,python,node 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,windows,linux,visualstudiocode,python,node 3 | 4 | ### Linux ### 5 | *~ 6 | 7 | # temporary files which can be created if a process still has a handle open of a deleted file 8 | .fuse_hidden* 9 | 10 | # KDE directory preferences 11 | .directory 12 | 13 | # Linux trash folder which might appear on any partition or disk 14 | .Trash-* 15 | 16 | # .nfs files are created when an open file is removed but is still being accessed 17 | .nfs* 18 | 19 | ### macOS ### 20 | # General 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Icon must end with two \r 26 | Icon 27 | 28 | 29 | # Thumbnails 30 | ._* 31 | 32 | # Files that might appear in the root of a volume 33 | .DocumentRevisions-V100 34 | .fseventsd 35 | .Spotlight-V100 36 | .TemporaryItems 37 | .Trashes 38 | .VolumeIcon.icns 39 | .com.apple.timemachine.donotpresent 40 | 41 | # Directories potentially created on remote AFP share 42 | .AppleDB 43 | .AppleDesktop 44 | Network Trash Folder 45 | Temporary Items 46 | .apdisk 47 | 48 | ### macOS Patch ### 49 | # iCloud generated files 50 | *.icloud 51 | 52 | ### Node ### 53 | # Logs 54 | logs 55 | *.log 56 | npm-debug.log* 57 | yarn-debug.log* 58 | yarn-error.log* 59 | lerna-debug.log* 60 | .pnpm-debug.log* 61 | 62 | # Diagnostic reports (https://nodejs.org/api/report.html) 63 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 64 | 65 | # Runtime data 66 | pids 67 | *.pid 68 | *.seed 69 | *.pid.lock 70 | 71 | # Directory for instrumented libs generated by jscoverage/JSCover 72 | lib-cov 73 | 74 | # Coverage directory used by tools like istanbul 75 | coverage 76 | *.lcov 77 | 78 | # nyc test coverage 79 | .nyc_output 80 | 81 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 82 | .grunt 83 | 84 | # Bower dependency directory (https://bower.io/) 85 | bower_components 86 | 87 | # node-waf configuration 88 | .lock-wscript 89 | 90 | # Compiled binary addons (https://nodejs.org/api/addons.html) 91 | build/Release 92 | 93 | # Dependency directories 94 | node_modules/ 95 | jspm_packages/ 96 | 97 | # Snowpack dependency directory (https://snowpack.dev/) 98 | web_modules/ 99 | 100 | # TypeScript cache 101 | *.tsbuildinfo 102 | 103 | # Optional npm cache directory 104 | .npm 105 | 106 | # Optional eslint cache 107 | .eslintcache 108 | 109 | # Optional stylelint cache 110 | .stylelintcache 111 | 112 | # Microbundle cache 113 | .rpt2_cache/ 114 | .rts2_cache_cjs/ 115 | .rts2_cache_es/ 116 | .rts2_cache_umd/ 117 | 118 | # Optional REPL history 119 | .node_repl_history 120 | 121 | # Output of 'npm pack' 122 | *.tgz 123 | 124 | # Yarn Integrity file 125 | .yarn-integrity 126 | 127 | # dotenv environment variable files 128 | .env 129 | .env.development.local 130 | .env.test.local 131 | .env.production.local 132 | .env.local 133 | 134 | # parcel-bundler cache (https://parceljs.org/) 135 | .cache 136 | .parcel-cache 137 | 138 | # Next.js build output 139 | .next 140 | out 141 | 142 | # Nuxt.js build / generate output 143 | .nuxt 144 | dist 145 | 146 | # Gatsby files 147 | .cache/ 148 | # Comment in the public line in if your project uses Gatsby and not Next.js 149 | # https://nextjs.org/blog/next-9-1#public-directory-support 150 | # public 151 | 152 | # vuepress build output 153 | .vuepress/dist 154 | 155 | # vuepress v2.x temp and cache directory 156 | .temp 157 | 158 | # Docusaurus cache and generated files 159 | .docusaurus 160 | 161 | # Serverless directories 162 | .serverless/ 163 | 164 | # FuseBox cache 165 | .fusebox/ 166 | 167 | # DynamoDB Local files 168 | .dynamodb/ 169 | 170 | # TernJS port file 171 | .tern-port 172 | 173 | # Stores VSCode versions used for testing VSCode extensions 174 | .vscode-test 175 | 176 | # yarn v2 177 | .yarn/cache 178 | .yarn/unplugged 179 | .yarn/build-state.yml 180 | .yarn/install-state.gz 181 | .pnp.* 182 | 183 | ### Node Patch ### 184 | # Serverless Webpack directories 185 | .webpack/ 186 | 187 | # Optional stylelint cache 188 | 189 | # SvelteKit build / generate output 190 | .svelte-kit 191 | 192 | ### Python ### 193 | # Byte-compiled / optimized / DLL files 194 | __pycache__/ 195 | *.py[cod] 196 | *$py.class 197 | 198 | # C extensions 199 | *.so 200 | 201 | # Distribution / packaging 202 | .Python 203 | build/ 204 | develop-eggs/ 205 | dist/ 206 | downloads/ 207 | eggs/ 208 | .eggs/ 209 | .venv/lib/ 210 | lib64/ 211 | parts/ 212 | sdist/ 213 | var/ 214 | wheels/ 215 | share/python-wheels/ 216 | *.egg-info/ 217 | .installed.cfg 218 | *.egg 219 | MANIFEST 220 | 221 | # PyInstaller 222 | # Usually these files are written by a python script from a template 223 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 224 | *.manifest 225 | *.spec 226 | 227 | # Installer logs 228 | pip-log.txt 229 | pip-delete-this-directory.txt 230 | 231 | # Unit test / coverage reports 232 | htmlcov/ 233 | .tox/ 234 | .nox/ 235 | .coverage 236 | .coverage.* 237 | nosetests.xml 238 | coverage.xml 239 | *.cover 240 | *.py,cover 241 | .hypothesis/ 242 | .pytest_cache/ 243 | cover/ 244 | 245 | # Translations 246 | *.mo 247 | *.pot 248 | 249 | # Django stuff: 250 | local_settings.py 251 | db.sqlite3 252 | db.sqlite3-journal 253 | 254 | # Flask stuff: 255 | instance/ 256 | .webassets-cache 257 | 258 | # Scrapy stuff: 259 | .scrapy 260 | 261 | # Sphinx documentation 262 | docs/_build/ 263 | 264 | # PyBuilder 265 | .pybuilder/ 266 | target/ 267 | 268 | # Jupyter Notebook 269 | .ipynb_checkpoints 270 | 271 | # IPython 272 | profile_default/ 273 | ipython_config.py 274 | 275 | # pyenv 276 | # For a library or package, you might want to ignore these files since the code is 277 | # intended to run in multiple environments; otherwise, check them in: 278 | # .python-version 279 | 280 | # pipenv 281 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 282 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 283 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 284 | # install all needed dependencies. 285 | #Pipfile.lock 286 | 287 | # poetry 288 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 289 | # This is especially recommended for binary packages to ensure reproducibility, and is more 290 | # commonly ignored for libraries. 291 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 292 | #poetry.lock 293 | 294 | # pdm 295 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 296 | #pdm.lock 297 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 298 | # in version control. 299 | # https://pdm.fming.dev/#use-with-ide 300 | .pdm.toml 301 | 302 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 303 | __pypackages__/ 304 | 305 | # Celery stuff 306 | celerybeat-schedule 307 | celerybeat.pid 308 | 309 | # SageMath parsed files 310 | *.sage.py 311 | 312 | # Environments 313 | .venv 314 | env/ 315 | venv/ 316 | ENV/ 317 | env.bak/ 318 | venv.bak/ 319 | 320 | # Spyder project settings 321 | .spyderproject 322 | .spyproject 323 | 324 | # Rope project settings 325 | .ropeproject 326 | 327 | # mkdocs documentation 328 | /site 329 | 330 | # mypy 331 | .mypy_cache/ 332 | .dmypy.json 333 | dmypy.json 334 | 335 | # Pyre type checker 336 | .pyre/ 337 | 338 | # pytype static type analyzer 339 | .pytype/ 340 | 341 | # Cython debug symbols 342 | cython_debug/ 343 | 344 | # PyCharm 345 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 346 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 347 | # and can be added to the global gitignore or merged into this file. For a more nuclear 348 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 349 | #.idea/ 350 | 351 | ### VisualStudioCode ### 352 | .vscode/* 353 | !.vscode/settings.json 354 | !.vscode/tasks.json 355 | !.vscode/launch.json 356 | !.vscode/extensions.json 357 | !.vscode/*.code-snippets 358 | 359 | # Local History for Visual Studio Code 360 | .history/ 361 | 362 | # Built Visual Studio Code Extensions 363 | *.vsix 364 | 365 | ### VisualStudioCode Patch ### 366 | # Ignore all local history of files 367 | .history 368 | .ionide 369 | 370 | ### Windows ### 371 | # Windows thumbnail cache files 372 | Thumbs.db 373 | Thumbs.db:encryptable 374 | ehthumbs.db 375 | ehthumbs_vista.db 376 | 377 | # Dump file 378 | *.stackdump 379 | 380 | # Folder config file 381 | [Dd]esktop.ini 382 | 383 | # Recycle Bin used on file shares 384 | $RECYCLE.BIN/ 385 | 386 | # Windows Installer files 387 | *.cab 388 | *.msi 389 | *.msix 390 | *.msm 391 | *.msp 392 | 393 | # Windows shortcuts 394 | *.lnk 395 | 396 | # End of https://www.toptal.com/developers/gitignore/api/macos,windows,linux,visualstudiocode,python,node 397 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: "^$" 2 | fail_fast: false 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.5.0 6 | hooks: 7 | - id: check-added-large-files 8 | args: ["--maxkb=1024"] 9 | # forbid files which have a UTF-8 byte-order marker 10 | - id: fix-byte-order-marker 11 | # Check for files that would conflict in case-insensitive filesystems 12 | - id: check-case-conflict 13 | # This hook checks json files for parseable syntax. 14 | - id: check-json 15 | # Check for files that contain merge conflict strings. 16 | - id: check-merge-conflict 17 | # Checks for symlinks which do not point to anything. 18 | - id: check-symlinks 19 | # This hook checks toml files for parseable syntax. 20 | - id: check-toml 21 | # Ensures that links to vcs websites are permalinks. 22 | - id: check-vcs-permalinks 23 | # This hook checks xml files for parseable syntax. 24 | - id: check-xml 25 | # This hook checks yaml files for parseable syntax. 26 | - id: check-yaml 27 | # Detects symlinks which are changed to regular files with a content of a path which that symlink was pointing to. 28 | - id: destroyed-symlinks 29 | # Detects the presence of private keys 30 | - id: detect-private-key 31 | # Ensures that a file is either empty, or ends with one newline. 32 | - id: end-of-file-fixer 33 | exclude: README.md|CHANGELOG.md 34 | # Replaces or checks mixed line ending 35 | - id: mixed-line-ending 36 | args: ["--fix=lf"] 37 | description: Forces to replace line ending by the UNIX 'lf' character. 38 | 39 | # Optional. Conflicts with prettier. 40 | # - id: pretty-format-json 41 | # args: ["--autofix", "--indent", "2", "--no-sort-keys"] 42 | 43 | # This hook trims trailing whitespace. 44 | - id: trailing-whitespace 45 | 46 | # Prettier is an opinionated code formatter. 47 | # It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. 48 | - repo: https://github.com/pre-commit/mirrors-prettier 49 | rev: "v4.0.0-alpha.8" 50 | hooks: 51 | - id: prettier 52 | exclude: CHANGELOG.md 53 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "makefile.extensionOutputFolder": "./.vscode" 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/). 7 | 8 | ## [1.4.1](https://github.com/awslabs/aws-code-habits/compare/v1.4.0...v1.4.1) (2023-11-10) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * see https://github.com/terraform-linters/tflint/discussions/1680 ([c9fb076](https://github.com/awslabs/aws-code-habits/commit/c9fb0763aa299767fa70aa2e90af6ed664a010a7)) 14 | 15 | ## [1.4.0](https://github.com/awslabs/aws-code-habits/compare/v1.3.0...v1.4.0) (2023-03-07) 16 | 17 | 18 | ### Features 19 | 20 | * add cobra command ([3e64a1a](https://github.com/awslabs/aws-code-habits/commit/3e64a1ac6f3c5b01a0a9e9ae65efb4a94014d70e)) 21 | * add golang command ([ca9b531](https://github.com/awslabs/aws-code-habits/commit/ca9b5315d04e1e4ca5279cc3c2f17d6a9efcdcaa)) 22 | 23 | ## [1.3.0](https://github.com/awslabs/aws-code-habits/compare/v1.2.0...v1.3.0) (2023-02-15) 24 | 25 | 26 | ### Features 27 | 28 | * create rules to initialize pre-commit and .gitignore ([5dc7936](https://github.com/awslabs/aws-code-habits/commit/5dc79366f07aa2d9ac6e9d716883fcadca4280cd)) 29 | 30 | 31 | ### Bug Fixes 32 | 33 | * remove python target dependencies ([5219f21](https://github.com/awslabs/aws-code-habits/commit/5219f2170517652d6cb8843f98070a4afd29d7df)) 34 | * tflient.hcl correct path ([3fa8a05](https://github.com/awslabs/aws-code-habits/commit/3fa8a058bca6a589b92db7471838a1aaf428ef55)) 35 | 36 | ## [1.2.0](https://github.com/awslabs/aws-code-habits/compare/v1.1.0...v1.2.0) (2023-02-03) 37 | 38 | 39 | ### Features 40 | 41 | * make references optional ([09c1a79](https://github.com/awslabs/aws-code-habits/commit/09c1a79537dc00df567a4d9bc08aede14ba0bbe4)) 42 | 43 | ## [1.1.0](https://github.com/awslabs/aws-code-habits/compare/v1.0.0...v1.1.0) (2023-01-06) 44 | 45 | 46 | ### Features 47 | 48 | * add worfklow release-please ([f1856d8](https://github.com/awslabs/aws-code-habits/commit/f1856d8f185247ff3c0b60a8c20d74ebd7db62b7)) 49 | * create make target to install checkov ([457493b](https://github.com/awslabs/aws-code-habits/commit/457493b6c92cda0d51fab88eb5b4bfef49529cbe)) 50 | 51 | 52 | ### Bug Fixes 53 | 54 | * apply pre-commit rules ([0d5179e](https://github.com/awslabs/aws-code-habits/commit/0d5179ea3ed4ba6b03c29aeb0188915ac7d7df95)) 55 | * display terrascan version instead of gomplate ([4e34fa9](https://github.com/awslabs/aws-code-habits/commit/4e34fa9adb5818abcb69587ea63674577b4e7823)) 56 | * remove terraform-docs configuration ([953e886](https://github.com/awslabs/aws-code-habits/commit/953e8868f4c30093ff6abe2151fab6c83a63f293)) 57 | 58 | ## [v1.0.0] - 2022-10-27 59 | 60 | First release! 🚀 61 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 2 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 3 | opensource-codeofconduct@amazon.com with any additional questions or comments. 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | ## Reporting Bugs/Feature Requests 10 | 11 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 12 | 13 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 14 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 15 | 16 | - A reproducible test case or series of steps 17 | - The version of our code being used 18 | - Any modifications you've made relevant to the bug 19 | - Anything unusual about your environment or deployment 20 | 21 | ## Contributing via Pull Requests 22 | 23 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 24 | 25 | 1. You are working against the latest source on the _main_ branch. 26 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 27 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 28 | 29 | To send us a pull request, please: 30 | 31 | 1. Fork the repository. 32 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 33 | 3. Ensure local tests pass. 34 | 4. Commit to your fork using clear commit messages. 35 | 5. Send us a pull request, answering any default questions in the pull request interface. 36 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 37 | 38 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 39 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 40 | 41 | ## Finding contributions to work on 42 | 43 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 44 | 45 | ## Code of Conduct 46 | 47 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 48 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 49 | opensource-codeofconduct@amazon.com with any additional questions or comments. 50 | 51 | ## Security issue notifications 52 | 53 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 54 | 55 | ## Licensing 56 | 57 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export WORKSPACE=$(shell pwd) 2 | export HABITS = $(WORKSPACE) 3 | 4 | include $(WORKSPACE)/tools.env 5 | 6 | include $(HABITS)/lib/make/*/*.mk 7 | include $(HABITS)/lib/make/*.mk 8 | 9 | .PHONY: hygiene 10 | hygiene: doc/build pre-commit/run 11 | -------------------------------------------------------------------------------- /Makefile.md: -------------------------------------------------------------------------------- 1 | ## Make 2 | 3 | ``` 4 | Available targets: 5 | 6 | aws/cfn-lint/install Install AWS CloudFormation Linter 7 | aws/cli/install Install AWS Command Line Interface v2 8 | aws/cli/version Display AWS CLI version 9 | aws/cloudformation/create-change-set Creates a list of changes that will be applied to a stack so that you can review the changes before executing them. 10 | aws/cloudformation/create-change-set-without-parameters Creates a list of changes that will be applied to a stack so that you can review the changes before executing them. 11 | aws/cloudformation/create-stack Creates a stack as specified in the template. 12 | aws/cloudformation/create-stack-without-parameters Creates a stack as specified in the template. (don't pass --parameters flag) 13 | aws/cloudformation/create/service-linked-role Creates an IAM role that is linked to a specific Amazon Elasticsearch service. 14 | aws/cloudformation/delete-change-set Delete latest change-set created 15 | aws/cloudformation/delete-stack Delete CloudFormation Stack 16 | aws/cloudformation/delete/service-linked-role Deletes an IAM role that is linked to a specific Amazon Web Services service. 17 | aws/cloudformation/describe-stack Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created. 18 | aws/cloudformation/describe-stack-events Returns all stack related events for a specified stack in reverse chronological order. 19 | aws/cloudformation/detect-stack-drift Detects whether a stack's actual configuration differs, or has drifted , from it's expected configuration, as defined in the stack template and any values specified as template parameters. 20 | aws/cloudformation/estimate-template-cost Returns the estimated monthly cost of a template 21 | aws/cloudformation/execute-change-set Execute latest change-set 22 | aws/cloudformation/hygiene Execute CFN Lint and pre-commit rules 23 | aws/cloudformation/latest-change-set Display latest change-set 24 | aws/codeartifact/login Login into AWS CodeArtifact 25 | aws/config/init Initialize the AWS config file 26 | aws/ssm/install-plugin Install AWS SSM plugin 27 | aws/ssm/start-session Start session with AWS Systems Manager Session Manager 28 | aws/sso/login Login into AWS account 29 | aws/sts/get-caller-identity Returns details about the IAM user or role whose credentials are used to call the operation. 30 | doc/build Builds documentation 31 | doc/init Initialize documentation 32 | docker/remove-containers Remove all Docker containers 33 | docker/remove-images Remove all Docker images 34 | docker/remove-volumes Remove all Docker volumes 35 | git/config/init Initialize git configuration for project 36 | github/actions/init Initialize .github/actions directory 37 | github/issues/init Initialize .github/issues directory 38 | github/pull-request/init Initialize .github/pull-request directory 39 | github/workflows/init Initialize .github/workflows directory 40 | gitignore/init Create .gitignore file 41 | gitignore/install Install gitignore 42 | gitignore/list List all gitignore templates 43 | habits/check Performs checks 44 | habits/init Initialize gitignore, documentation, pre-commit, github workflows, issues and pull-request 45 | habits/install Install Habits dependencies 46 | habits/remove Uninstall Habits 47 | habits/update Update Habits 48 | help/clean Help screen 49 | nodejs/install Install NodeJS 50 | npm/install Install NPM 51 | pre-commit/hooks/install Install pre-commit hooks 52 | pre-commit/init Initialize .pre-commit-config.yaml to working directoy 53 | pre-commit/install Install pre-commit using Pip3 54 | pre-commit/remove Remove .pre-commit-config.yaml 55 | pre-commit/run Execute pre-commit hooks on all files 56 | pre-commit/update Update pre-commit-config.yaml with the latest version 57 | pre-commit/version Display pre-commit version 58 | python/install Install Python 3 59 | python/pip/install Install Python 3 Pip 60 | python/version Display Python & Pip version 61 | python/virtualenv/init Initialize a Python 3 virtualenv in the current directory 62 | python/virtualenv/install Install Python 3 virtualenv 63 | python/virtualenv/remove Remove Python 3 virtualenv in the current directory 64 | ubuntu/install-packages Install most common packages 65 | ubuntu/update Update and upgrade Ubuntu packages 66 | 67 | ``` 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | ![logo][logo] 11 | 12 | 13 | [![Test](https://github.com/awslabs/aws-code-habits/actions/workflows/test.yaml/badge.svg)](https://github.com/awslabs/aws-code-habits/actions/workflows/test.yaml)[![GitHub Issues](https://img.shields.io/github/issues/awslabs/aws-code-habits)](https://github.com/awslabs/aws-code-habits/issues)[![GitHub Stars](https://img.shields.io/github/stars/awslabs/aws-code-habits)](https://github.com/awslabs/aws-code-habits/stargazers)[![hygiene](https://github.com/awslabs/aws-code-habits/actions/workflows/hygiene.yaml/badge.svg)](https://github.com/awslabs/aws-code-habits/actions/workflows/hygiene.yaml) 14 | 15 | # AWS Code Habits 16 | 17 | A library with Make targets, Ansible playbooks, Jinja templates (and more) designed to boost common software development tasks and enhance governance. 18 | 19 | | ![screenshot-1](https://user-images.githubusercontent.com/3298422/198290134-fec4a14d-8542-4b92-9cbc-d33f476e7a74.gif) | 20 | |:--:| 21 | | *Installing AWS Code Habits* | 22 | 23 | 24 | ## Table of Contents 25 | 26 | - [Getting Started](#getting-started) 27 | 28 | - [Prerequisites](#prerequisites) 29 | 30 | 31 | - [Usage](#usage) 32 | 33 | - [How-Tos](#how-tos) 34 | - [How to initialize pre-commit config](#how-to-initialize-pre-commit-config) 35 | - [How to maintain documentation](#how-to-maintain-documentation) 36 | - [How to expand Habits commands](#how-to-expand-habits-commands) 37 | 38 | - [Testing](#testing) 39 | 40 | 41 | ## Getting Started 42 | 43 | AWS Code Habits was developed to be used as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). 44 | 45 | On a terminal, on your project's root directory, execute one of the following commands: 46 | 47 | ```bash 48 | git submodule add --name habits -b main https://github.com/awslabs/aws-code-habits.git habits 49 | ``` 50 | 51 | This will clone AWS Code Habits on a folder named `habits` and track against the `main` branch. 52 | Now, you will need to create, or add to your existing, `Makefile`. 53 | 54 | ```bash 55 | export WORKSPACE=$(shell pwd) 56 | export HABITS = $(WORKSPACE)/habits 57 | 58 | include $(WORKSPACE)/tools.env # pin the version of your tools 59 | 60 | include $(HABITS)/lib/make/*/*.mk 61 | include $(HABITS)/lib/make/*.mk 62 | ``` 63 | 64 | Remember, next time you need to clone your repository, you will need to include `--recurse-submodules` parameters. 65 | ```bash 66 | git clone --recurse-submodules ... 67 | ``` 68 | > If you already cloned the project and forgot `--recurse-submodules`, you can combine the `git submodule init` and `git submodule update` steps by running `git submodule update --init`. To also initialize, fetch and checkout any nested submodules, you can use the foolproof `git submodule update --init --recursive`. - [Git Tools Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) 69 | 70 | Check the [scripts](scripts/) directory, if you want to automate the initialization and installation of AWS Code Habits.` 71 | 72 | 73 | ## Prerequisites 74 | A list of things you need, or how to install them. 75 | > At this stage, we are only supporting Linux (Ubuntu) environments (which can be obtained via WSL (Windows) or DevContainers (Mac/Linux/Windows)) 76 | 77 | - [Python 3](https://www.python.org) - Whether you're new to programming or an experienced developer, it's easy to learn and use Python. 78 | - [Pip](https://pypi.org/project/pip/) - pip is the package installer for Python. 79 | 80 | 81 | 82 | ## Usage 83 | 84 | ```bash 85 | make [tab][tab] 86 | ``` 87 | 88 | ```bash 89 | make help 90 | ``` 91 | For more information about each [Make targets available](Makefile.md). 92 | 93 | ## How-Tos 94 | Below you can learn 95 | 96 | ### How to initialize pre-commit config 97 | ```bash 98 | make pre-commit/init 99 | ``` 100 | 101 | To run all `pre-commit` rules in all files, simply run: 102 | 103 | ```bash 104 | make pre-commit/run 105 | ``` 106 | 107 | ### How to maintain documentation 108 | 1. First initialize all documentation files: 109 | ```bash 110 | make doc/init 111 | ``` 112 | 113 | This will create a folder named `doc/` in the root directory of your project and create a file named `habits.yaml` inside of it. 114 | 115 | 2. Modify the contents of `doc/habits.yaml` accordingly and execute: 116 | 117 | ``` 118 | make doc/build 119 | ``` 120 | 121 | 3. `README.md` will be rendered. 122 | 123 | ### How to expand Habits commands 124 | You can use [Habits][habits] to meet your needs, in your `Makefile` you can add the following to ensure code and documentation hygiene: 125 | ```bash 126 | .PHONY: hygiene 127 | hygiene: doc/build pre-commit/run 128 | ``` 129 | 130 | Another example, if you want to perform several tasks with `AWS CloudFormation`: 131 | ```bash 132 | .PHONY: hygiene 133 | hygiene: aws/cloudformation/hygiene 134 | 135 | .PHONY: plan 136 | plan: aws/cloudformation/create-change-set 137 | 138 | .PHONY: discard 139 | discard: aws/cloudformation/delete-change-set 140 | 141 | .PHONY: apply 142 | apply: aws/cloudformation/execute-change-set 143 | ``` 144 | 145 | 146 | ## Testing 147 | To perform habits checks: 148 | ```bash 149 | make habits/check 150 | ``` 151 | 152 | 153 | 154 | ## References 155 | - [GNU Make](https://www.gnu.org/software/make/) - GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. 156 | - [Windows Subsystem for Linux (Ubuntu)](https://docs.microsoft.com/en-us/windows/wsl/install) - WSL enables you to use Linux tools, like Bash or Grep, completely integrated with Windows tools, like PowerShell or Visual Studio Code, with no need to dual-boot. 157 | - [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. 158 | - [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. 159 | - [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) - Submodules allow you to keep a Git repository as a subdirectory of another Git repository. 160 | - [Docker](https://www.docker.com/products/docker-desktop/) - The fastest way to containerize applications 161 | - [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. 162 | - [Visual Studio DevContainers](https://code.visualstudio.com/docs/devcontainers/containers) - The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. 163 | - [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. 164 | - [Ansible](https://www.ansible.com/) - Ansible is an open source community project sponsored by Red Hat, it's the simplest way to automate IT. 165 | - [Jinja2](https://docs.ansible.com/ansible/latest/user_guide/playbooks_templating.html) - Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts. 166 | 167 | 168 | ## License 169 | This project is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file. 170 | 171 | ## Copyright 172 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 173 | 174 | 175 | [repo]: https://github.com/awslabs/aws-code-habits 176 | [logo]: doc/logo.png 177 | 178 | [habits]: https://github.com/awslabs/aws-code-habits 179 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security 2 | 3 | We take the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations. 4 | If you believe you have found a security vulnerability in any AWS-owned repository, please raise an issue. 5 | 6 | Thank you! 7 | -------------------------------------------------------------------------------- /doc/habits.yaml: -------------------------------------------------------------------------------- 1 | url: https://github.com/awslabs/aws-code-habits 2 | 3 | logo: doc/logo.png 4 | 5 | badges: 6 | custom: 7 | - title: Test 8 | icon: https://github.com/awslabs/aws-code-habits/actions/workflows/test.yaml/badge.svg 9 | url: https://github.com/awslabs/aws-code-habits/actions/workflows/test.yaml 10 | - title: GitHub Issues 11 | icon: https://img.shields.io/github/issues/awslabs/aws-code-habits 12 | url: https://github.com/awslabs/aws-code-habits/issues 13 | - title: GitHub Stars 14 | icon: https://img.shields.io/github/stars/awslabs/aws-code-habits 15 | url: https://github.com/awslabs/aws-code-habits/stargazers 16 | workflows: 17 | - name: hygiene 18 | 19 | screenshots: 20 | - label: screenshot-1 21 | url: https://user-images.githubusercontent.com/3298422/198290134-fec4a14d-8542-4b92-9cbc-d33f476e7a74.gif 22 | caption: Installing AWS Code Habits 23 | 24 | title: AWS Code Habits 25 | 26 | description: A library with Make targets, Ansible playbooks, Jinja templates (and more) designed to boost common software development tasks and enhance governance. 27 | 28 | getting_started: |- 29 | AWS Code Habits was developed to be used as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). 30 | 31 | On a terminal, on your project's root directory, execute one of the following commands: 32 | 33 | ```bash 34 | git submodule add --name habits -b main https://github.com/awslabs/aws-code-habits.git habits 35 | ``` 36 | 37 | This will clone AWS Code Habits on a folder named `habits` and track against the `main` branch. 38 | Now, you will need to create, or add to your existing, `Makefile`. 39 | 40 | ```bash 41 | export WORKSPACE=$(shell pwd) 42 | export HABITS = $(WORKSPACE)/habits 43 | 44 | include $(WORKSPACE)/tools.env # pin the version of your tools 45 | 46 | include $(HABITS)/lib/make/*/*.mk 47 | include $(HABITS)/lib/make/*.mk 48 | ``` 49 | 50 | Remember, next time you need to clone your repository, you will need to include `--recurse-submodules` parameters. 51 | ```bash 52 | git clone --recurse-submodules ... 53 | ``` 54 | > If you already cloned the project and forgot `--recurse-submodules`, you can combine the `git submodule init` and `git submodule update` steps by running `git submodule update --init`. To also initialize, fetch and checkout any nested submodules, you can use the foolproof `git submodule update --init --recursive`. - [Git Tools Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) 55 | 56 | Check the [scripts](scripts/) directory, if you want to automate the initialization and installation of AWS Code Habits.` 57 | 58 | prerequisites: 59 | content: |- 60 | A list of things you need, or how to install them. 61 | > At this stage, we are only supporting Linux (Ubuntu) environments (which can be obtained via WSL (Windows) or DevContainers (Mac/Linux/Windows)) 62 | 63 | references: 64 | - name: Python 3 65 | description: Whether you're new to programming or an experienced developer, it's easy to learn and use Python. 66 | url: https://www.python.org 67 | - name: Pip 68 | description: pip is the package installer for Python. 69 | url: https://pypi.org/project/pip/ 70 | 71 | # required 72 | usage: |- 73 | 74 | ```bash 75 | make [tab][tab] 76 | ``` 77 | 78 | ```bash 79 | make help 80 | ``` 81 | For more information about each [Make targets available](Makefile.md). 82 | 83 | how_tos: 84 | - title: How to initialize pre-commit config 85 | content: |- 86 | ```bash 87 | make pre-commit/init 88 | ``` 89 | 90 | To run all `pre-commit` rules in all files, simply run: 91 | 92 | ```bash 93 | make pre-commit/run 94 | ``` 95 | 96 | - title: How to maintain documentation 97 | content: |- 98 | 1. First initialize all documentation files: 99 | ```bash 100 | make doc/init 101 | ``` 102 | 103 | This will create a folder named `doc/` in the root directory of your project and create a file named `habits.yaml` inside of it. 104 | 105 | 2. Modify the contents of `doc/habits.yaml` accordingly and execute: 106 | 107 | ``` 108 | make doc/build 109 | ``` 110 | 111 | 3. `README.md` will be rendered. 112 | 113 | - title: How to expand Habits commands 114 | content: |- 115 | You can use [Habits][habits] to meet your needs, in your `Makefile` you can add the following to ensure code and documentation hygiene: 116 | ```bash 117 | .PHONY: hygiene 118 | hygiene: doc/build pre-commit/run 119 | ``` 120 | 121 | Another example, if you want to perform several tasks with `AWS CloudFormation`: 122 | ```bash 123 | .PHONY: hygiene 124 | hygiene: aws/cloudformation/hygiene 125 | 126 | .PHONY: plan 127 | plan: aws/cloudformation/create-change-set 128 | 129 | .PHONY: discard 130 | discard: aws/cloudformation/delete-change-set 131 | 132 | .PHONY: apply 133 | apply: aws/cloudformation/execute-change-set 134 | ``` 135 | 136 | testing: |- 137 | To perform habits checks: 138 | ```bash 139 | make habits/check 140 | ``` 141 | 142 | references: 143 | - name: GNU Make 144 | description: GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. 145 | url: https://www.gnu.org/software/make/ 146 | - name: Windows Subsystem for Linux (Ubuntu) 147 | description: WSL enables you to use Linux tools, like Bash or Grep, completely integrated with Windows tools, like PowerShell or Visual Studio Code, with no need to dual-boot. 148 | url: https://docs.microsoft.com/en-us/windows/wsl/install 149 | - name: Visual Studio Code 150 | description: Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. 151 | url: https://code.visualstudio.com/ 152 | - name: VSCode Remote Development Extension Pack 153 | description: 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. 154 | url: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack 155 | - name: Git Submodules 156 | description: Submodules allow you to keep a Git repository as a subdirectory of another Git repository. 157 | url: https://git-scm.com/book/en/v2/Git-Tools-Submodules 158 | - name: Docker 159 | description: The fastest way to containerize applications 160 | url: https://www.docker.com/products/docker-desktop/ 161 | - name: Visual Studio Code 162 | description: Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. 163 | url: https://code.visualstudio.com/ 164 | - name: Visual Studio DevContainers 165 | description: The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. 166 | url: https://code.visualstudio.com/docs/devcontainers/containers 167 | - name: VSCode Remote Development Extension Pack 168 | description: 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. 169 | url: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack 170 | - name: Ansible 171 | description: Ansible is an open source community project sponsored by Red Hat, it's the simplest way to automate IT. 172 | url: https://www.ansible.com/ 173 | - name: Jinja2 174 | description: Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts. 175 | url: https://docs.ansible.com/ansible/latest/user_guide/playbooks_templating.html 176 | 177 | license: MIT-0 178 | 179 | copyright: Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 180 | 181 | anchors: 182 | - name: habits 183 | url: https://github.com/awslabs/aws-code-habits 184 | -------------------------------------------------------------------------------- /doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-code-habits/68db2a8a65c2653a1e53bb2f1c4f67509e8994c6/doc/logo.png -------------------------------------------------------------------------------- /doc/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 146 | 149 | 153 | 154 | 158 | 161 | 165 | 166 | 170 | 173 | 177 | 178 | 180 | 182 | 184 | 186 | 188 | 190 | 192 | 194 | 196 | 198 | 200 | 202 | 204 | 206 | 208 | 234 | -------------------------------------------------------------------------------- /files/aws/cloudformation/parameters.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ParameterKey": "", 4 | "ParameterValue": "" 5 | } 6 | ] 7 | -------------------------------------------------------------------------------- /files/aws/cloudformation/template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: "2010-09-09" 3 | 4 | # A text string that describes the template. This section must always follow the template format version section. 5 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-description-structure.html 6 | Description: String 7 | 8 | # Objects that provide additional information about the template. 9 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html 10 | Metadata: template metadata 11 | 12 | # Values to pass to your template at runtime (when you create or update a stack). You can refer to parameters from the Resources and Outputs sections of the template. 13 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html 14 | Parameters: set of parameters 15 | 16 | # Validates a parameter or a combination of parameters passed to a template during a stack creation or stack update. 17 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/rules-section-structure.html 18 | Rules: set of rules 19 | 20 | # A mapping of keys and associated values that you can use to specify conditional parameter values, similar to a lookup table. 21 | # You can match a key to a corresponding value by using the Fn::FindInMap intrinsic function in the Resources and Outputs sections. 22 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html 23 | Mappings: set of mappings 24 | 25 | # Conditions that control whether certain resources are created or whether certain resource properties are assigned a value during stack creation or update. 26 | # For example, you could conditionally create a resource that depends on whether the stack is for a production or test environment. 27 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html 28 | Conditions: set of conditions 29 | 30 | # For serverless applications (also referred to as Lambda-based applications), specifies the version of the AWS Serverless Application Model (AWS SAM) to use. 31 | # When you specify a transform, you can use AWS SAM syntax to declare resources in your template. 32 | # The model defines the syntax that you can use and how it's processed. 33 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html 34 | Transform: set of transforms 35 | 36 | # Specifies the stack resources and their properties, such as an Amazon Elastic Compute Cloud instance or an Amazon Simple Storage Service bucket. 37 | # You can refer to resources in the Resources and Outputs sections of the template. 38 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html 39 | Resources: set of resources 40 | 41 | # Describes the values that are returned whenever you view your stack's properties. 42 | # For example, you can declare an output for an S3 bucket name and then call the aws cloudformation describe-stacks AWS CLI command to view the name. 43 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html 44 | Outputs: set of outputs 45 | -------------------------------------------------------------------------------- /files/pre-commit/.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: "^$" 2 | fail_fast: false 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.3.0 6 | hooks: 7 | - id: check-added-large-files 8 | args: ["--maxkb=1024"] 9 | # forbid files which have a UTF-8 byte-order marker 10 | - id: fix-byte-order-marker 11 | # Check for files that would conflict in case-insensitive filesystems 12 | - id: check-case-conflict 13 | # This hook checks json files for parseable syntax. 14 | - id: check-json 15 | # Check for files that contain merge conflict strings. 16 | - id: check-merge-conflict 17 | # Checks for symlinks which do not point to anything. 18 | - id: check-symlinks 19 | # This hook checks toml files for parseable syntax. 20 | - id: check-toml 21 | # Ensures that links to vcs websites are permalinks. 22 | - id: check-vcs-permalinks 23 | # This hook checks xml files for parseable syntax. 24 | - id: check-xml 25 | # This hook checks yaml files for parseable syntax. 26 | - id: check-yaml 27 | # Detects symlinks which are changed to regular files with a content of a path which that symlink was pointing to. 28 | - id: destroyed-symlinks 29 | # Detects the presence of private keys 30 | - id: detect-private-key 31 | # Ensures that a file is either empty, or ends with one newline. 32 | - id: end-of-file-fixer 33 | exclude: README.md 34 | # Replaces or checks mixed line ending 35 | - id: mixed-line-ending 36 | args: ["--fix=lf"] 37 | description: Forces to replace line ending by the UNIX 'lf' character. 38 | 39 | # Optional. Conflicts with prettier. 40 | # - id: pretty-format-json 41 | # args: ["--autofix", "--indent", "2", "--no-sort-keys"] 42 | 43 | # This hook trims trailing whitespace. 44 | - id: trailing-whitespace 45 | 46 | # Prettier is an opinionated code formatter. 47 | # It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. 48 | - repo: https://github.com/pre-commit/mirrors-prettier 49 | rev: "v2.7.1" 50 | hooks: 51 | - id: prettier 52 | -------------------------------------------------------------------------------- /files/terraform/.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: "^$" 2 | fail_fast: false 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.3.0 6 | hooks: 7 | - id: check-added-large-files 8 | args: ["--maxkb=1024"] 9 | # forbid files which have a UTF-8 byte-order marker 10 | - id: fix-byte-order-marker 11 | # Check for files that would conflict in case-insensitive filesystems 12 | - id: check-case-conflict 13 | # This hook checks json files for parseable syntax. 14 | - id: check-json 15 | # Check for files that contain merge conflict strings. 16 | - id: check-merge-conflict 17 | # Checks for symlinks which do not point to anything. 18 | - id: check-symlinks 19 | # This hook checks toml files for parseable syntax. 20 | - id: check-toml 21 | # Ensures that links to vcs websites are permalinks. 22 | - id: check-vcs-permalinks 23 | # This hook checks xml files for parseable syntax. 24 | - id: check-xml 25 | # This hook checks yaml files for parseable syntax. 26 | - id: check-yaml 27 | # Detects symlinks which are changed to regular files with a content of a path which that symlink was pointing to. 28 | - id: destroyed-symlinks 29 | # Detects the presence of private keys 30 | - id: detect-private-key 31 | # Ensures that a file is either empty, or ends with one newline. 32 | - id: end-of-file-fixer 33 | # Replaces or checks mixed line ending 34 | - id: mixed-line-ending 35 | args: ["--fix=lf"] 36 | description: Forces to replace line ending by the UNIX 'lf' character. 37 | - id: pretty-format-json 38 | args: ["--autofix", "--indent", "2", "--no-sort-keys"] 39 | # This hook trims trailing whitespace. 40 | - id: trailing-whitespace 41 | 42 | - repo: https://github.com/antonbabenko/pre-commit-terraform 43 | rev: v1.76.0 44 | hooks: 45 | # Rewrites all Terraform configuration files to a canonical format. 46 | - id: terraform_fmt 47 | # Validates all Terraform configuration files. 48 | - id: terraform_validate 49 | # Validates all Terraform configuration files with TFLint. 50 | - id: terraform_tflint 51 | # TFSec static analysis of terraform templates to spot potential security issues. 52 | - id: terraform_tfsec 53 | # checkov static analysis of terraform templates to spot potential security issues. 54 | #- id: terraform_checkov 55 | # terrascan Detect compliance and security violations. 56 | #- id: terrascan 57 | -------------------------------------------------------------------------------- /files/terraform/.tflint.hcl: -------------------------------------------------------------------------------- 1 | plugin "terraform" { 2 | enabled = true 3 | preset = "recommended" 4 | } 5 | 6 | plugin "aws" { 7 | enabled = true 8 | version = "TFLINT_AWS_RULESET_VERSION" 9 | source = "github.com/terraform-linters/tflint-ruleset-aws" 10 | } 11 | -------------------------------------------------------------------------------- /lib/ansible/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = hosts 3 | -------------------------------------------------------------------------------- /lib/ansible/files/aws/config: -------------------------------------------------------------------------------- 1 | [profile default] 2 | sso_start_url=https://d-xxxxxxxxxx.awsapps.com/start 3 | sso_region=us-east-1 4 | sso_account_id=xxxxxxxxxxxx 5 | sso_role_name=xxxxxxxxxxxx 6 | region=us-east-1 7 | output=json 8 | 9 | [profile developer] 10 | region=ap-southeast-1 11 | source_profile=default 12 | role_arn=arn:aws:iam::xxxxxxxxxxxx:role/my-role 13 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [Unreleased] 9 | 10 | ## [1.0.0] - 2017-06-20 11 | 12 | ### Added 13 | 14 | - New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). 15 | 16 | ### Changed 17 | 18 | - Start using "changelog" over "change log" since it's the common usage. 19 | 20 | ### Removed 21 | 22 | - Section about "changelog" vs "CHANGELOG". 23 | 24 | ### Fixed 25 | 26 | - Fix typos in recent README changes. 27 | - Update outdated unreleased diff link. 28 | 29 | [unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD 30 | [1.0.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.0 31 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | > A code of conduct is a set of rules outlining the norms, rules, and responsibilities or proper practices of an individual party or an organization. [Wikipedia][wikipedia] 4 | 5 | Please refer to [open-source-code-of-conduct][open-source-code-of-conduct]. 6 | 7 | [wikipedia]: https://en.wikipedia.org/wiki/Code_of_conduct 8 | [open-source-code-of-conduct]: https://opensource.guide/code-of-conduct 9 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | ## Reporting Bugs/Feature Requests 10 | 11 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 12 | 13 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 14 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 15 | 16 | - A reproducible test case or series of steps 17 | - The version of our code being used 18 | - Any modifications you've made relevant to the bug 19 | - Anything unusual about your environment or deployment 20 | 21 | ## Contributing via Pull Requests 22 | 23 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 24 | 25 | 1. You are working against the latest source on the _main_ branch. 26 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 27 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 28 | 29 | To send us a pull request, please: 30 | 31 | 1. Fork the repository. 32 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 33 | 3. Ensure local tests pass. 34 | 4. Commit to your fork using clear commit messages. 35 | 5. Send us a pull request, answering any default questions in the pull request interface. 36 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 37 | 38 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 39 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 40 | 41 | ## Finding contributions to work on 42 | 43 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 44 | 45 | ## Code of Conduct 46 | 47 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 48 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 49 | opensource-codeofconduct@amazon.com with any additional questions or comments. 50 | 51 | ## Security issue notifications 52 | 53 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 54 | 55 | ## Licensing 56 | 57 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 58 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security 2 | 3 | We take the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations. 4 | If you believe you have found a security vulnerability in any AWS-owned repository, please raise an issue. 5 | 6 | Thank you! 7 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/habits.yaml: -------------------------------------------------------------------------------- 1 | url: https:// # required 2 | logo: https://via.placeholder.com/1280x640 # required 3 | 4 | # optional 5 | # badges: 6 | # # optional 7 | # custom: 8 | # - title: lorem # required 9 | # icon: https:// # required 10 | # url: https:// # required 11 | # # optional 12 | # workflows: 13 | # - name: hygiene # optional, needs to match filename on .github/workflows/ 14 | 15 | title: The project name # required 16 | 17 | # required 18 | description: |- 19 | The project description 20 | 21 | # optional 22 | screenshots: 23 | - label: placeholder # required 24 | caption: Placeholder # required 25 | url: https://via.placeholder.com/150 # required 26 | 27 | # optional 28 | getting_started: |- 29 | This is an example of how you may give instructions on setting up your project locally. 30 | To get a local copy up and running follow these simple example steps. 31 | 32 | ```bash 33 | echo 'hello world' 34 | ``` 35 | 36 | # required 37 | prerequisites: 38 | # required 39 | content: |- 40 | A list of things you need, or how to install them. 41 | 42 | ```bash 43 | npm install npm@latest -g 44 | ``` 45 | 46 | # optional 47 | references: 48 | - name: PreRequisite 1 49 | description: Description about the prerequisite 50 | url: https://github.com/ 51 | 52 | # optional 53 | installation: |- 54 | Below is an example of how you can instruct your audience on installing and setting up your app. 55 | 56 | 1. Get a free API Key at [GitHub][project] 57 | 58 | 2. Clone the repo 59 | ```bash 60 | git clone https://github.com/your_username_/Project-Name.git 61 | ``` 62 | 63 | 3. Install NPM packages 64 | ```bash 65 | npm install 66 | ``` 67 | 68 | 4. Enter your API in config.js 69 | ```bash 70 | const API_KEY = 'ENTER YOUR API'; 71 | ``` 72 | 73 | # required 74 | usage: |- 75 | Use this space to show useful examples of how a project can be used. 76 | Additional screenshots, code examples and demos work well in this space. 77 | You may also link to more resources. 78 | 79 | # optional 80 | # how_tos: 81 | # - title: How to import environment variables 82 | # content: |- 83 | # Lorem ipsum dolor 84 | 85 | # optional 86 | testing: |- 87 | Explain how to test the project 88 | 89 | ```bash 90 | pytest test_assert1.py 91 | ``` 92 | 93 | # optional 94 | deployment: |- 95 | Explain how the project is being deployed 96 | 97 | # optional 98 | contacts: 99 | - name: Jon Doe # required 100 | email: email@email.com # required 101 | 102 | # optional 103 | references: 104 | - name: lorem # required 105 | description: Lorem ipsum dolor sit amet # required 106 | url: https:// # required 107 | 108 | # optional 109 | # license: MIT-0 110 | 111 | # optional 112 | #copyright: Copyright . All Rights Reserved. 113 | 114 | # string [yes|no] | optional 115 | trademark: no 116 | 117 | # optional 118 | anchors: 119 | - name: sample # required 120 | url: https:// # required 121 | -------------------------------------------------------------------------------- /lib/ansible/files/doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-code-habits/68db2a8a65c2653a1e53bb2f1c4f67509e8994c6/lib/ansible/files/doc/logo.png -------------------------------------------------------------------------------- /lib/ansible/files/github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: Create a new ticket for a bug. 4 | labels: bug 5 | --- 6 | 7 | 8 | 9 | - Version: 10 | - Local OS Version: 11 | - Local chip architecture: 12 | - Reproduces in: 13 | 14 | Steps to Reproduce: 15 | 16 | 1. 17 | 2. 18 | -------------------------------------------------------------------------------- /lib/ansible/files/github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 💡 Feature Request 3 | about: Create a new ticket for a new feature request 4 | labels: enhancement 5 | --- 6 | 7 | Type your idea here. 8 | -------------------------------------------------------------------------------- /lib/ansible/files/github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ❔ Question 3 | about: What is your question about? 4 | labels: question 5 | --- 6 | 7 | Add more context here. 8 | -------------------------------------------------------------------------------- /lib/ansible/files/github/actions/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-code-habits/68db2a8a65c2653a1e53bb2f1c4f67509e8994c6/lib/ansible/files/github/actions/.keep -------------------------------------------------------------------------------- /lib/ansible/files/github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## 🧠 Pull Request 2 | 3 | ### Changes 4 | 5 | 6 | 7 | ### Type of change 8 | 9 | 16 | 17 | ## Why 18 | 19 | 20 | 21 | ## How (Optional) 22 | 23 | 24 | 25 | ## Checklist 26 | 27 | 28 | 29 | 30 | - [ ] Jest unit tests (as needed) 31 | - [ ] Integration tests (as needed) 32 | - [ ] Storybook stories (as needed) 33 | - [ ] Run storybook locally 34 | - [ ] Acceptance Criteria met 35 | - [ ] Screenshot added to Summary for UI ticket 36 | - [ ] Check test coverage of new or updated components (Reduce Banlist) 37 | 38 | 43 | -------------------------------------------------------------------------------- /lib/ansible/files/github/workflows/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-code-habits/68db2a8a65c2653a1e53bb2f1c4f67509e8994c6/lib/ansible/files/github/workflows/.keep -------------------------------------------------------------------------------- /lib/ansible/hosts: -------------------------------------------------------------------------------- 1 | [localhost] 2 | 127.0.0.1 ansible_connection=local 3 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/aws/config/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (aws/config/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create ~/.aws directory 7 | file: 8 | path: "~/.aws" 9 | state: directory 10 | 11 | # TODO: use Jinja template 12 | - name: Copy AWS Config 13 | copy: 14 | src: "{{habits}}/lib/ansible/files/aws/config" 15 | dest: ~/.aws/config 16 | mode: "0644" 17 | force: no 18 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/aws/config/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (aws/config/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove AWS Config 7 | file: 8 | path: ~/.aws/config 9 | state: absent 10 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/doc/build.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (doc/build) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Manage README.md 7 | template: src={{habits}}/lib/ansible/templates/readme.j2 dest={{workspace}}/README.md 8 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/doc/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (doc/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create doc/ directory 7 | file: 8 | path: "{{workspace}}/doc" 9 | state: directory 10 | 11 | - name: Copy habits.yaml template to doc/ 12 | template: src={{habits}}/lib/ansible/files/doc/habits.yaml dest={{workspace}}/doc/habits.yaml mode=644 13 | 14 | - name: Copy CONTRIBUTING.md 15 | copy: 16 | src: "{{habits}}/lib/ansible/files/doc/CONTRIBUTING.md" 17 | dest: "{{workspace}}/CONTRIBUTING.md" 18 | mode: "0644" 19 | 20 | - name: Copy CHANGELOG.md 21 | copy: 22 | src: "{{habits}}/lib/ansible/files/doc/CHANGELOG.md" 23 | dest: "{{workspace}}/CHANGELOG.md" 24 | mode: "0644" 25 | 26 | - name: Copy CODE_OF_CONDUCT.md 27 | copy: 28 | src: "{{habits}}/lib/ansible/files/doc/CODE_OF_CONDUCT.md" 29 | dest: "{{workspace}}/CODE_OF_CONDUCT.md" 30 | mode: "0644" 31 | 32 | - name: Copy SECURITY.md 33 | copy: 34 | src: "{{habits}}/lib/ansible/files/doc/SECURITY.md" 35 | dest: "{{workspace}}/SECURITY.md" 36 | mode: "0644" 37 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/doc/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (doc/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove doc/habits.yaml 7 | file: 8 | path: "{{workspace}}/doc/habits.yaml" 9 | state: absent 10 | 11 | - name: Remove doc/logo.jpg 12 | file: 13 | path: "{{workspace}}/doc/logo.jpg" 14 | state: absent 15 | 16 | - name: Remove CONTRIBUTING.md 17 | file: 18 | path: "{{workspace}}/CONTRIBUTING.md" 19 | state: absent 20 | 21 | - name: Remove CHANGELOG.md 22 | file: 23 | path: "{{workspace}}/CHANGELOG.md" 24 | state: absent 25 | 26 | - name: Remove CODE_OF_CONDUCT.md 27 | file: 28 | path: "{{workspace}}/CODE_OF_CONDUCT.md" 29 | state: absent 30 | 31 | - name: Remove SECURITY.md 32 | file: 33 | path: "{{workspace}}/SECURITY.md" 34 | state: absent 35 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/actions/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/actions/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create .github directory 7 | file: 8 | path: "{{workspace}}/.github" 9 | state: directory 10 | 11 | - name: Create .github/actions directory 12 | file: 13 | path: "{{workspace}}/.github/actions" 14 | state: directory 15 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/actions/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/actions/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove .github/actions 7 | file: 8 | path: "{{workspace}}/.github/actions" 9 | state: absent 10 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/issues/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/issues/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create .github directory 7 | file: 8 | path: "{{workspace}}/.github" 9 | state: directory 10 | 11 | - name: Create .github/ISSUE_TEMPLATE directory 12 | file: 13 | path: "{{workspace}}/.github/ISSUE_TEMPLATE" 14 | state: directory 15 | 16 | - name: Copy ISSUE_TEMPLATE/bug_report.md 17 | copy: 18 | src: "{{habits}}/lib/ansible/files/github/ISSUE_TEMPLATE/bug_report.md" 19 | dest: "{{workspace}}/.github/ISSUE_TEMPLATE/bug_report.md" 20 | mode: "0644" 21 | 22 | - name: Copy ISSUE_TEMPLATE/feature_request.md 23 | copy: 24 | src: "{{habits}}/lib/ansible/files/github/ISSUE_TEMPLATE/feature_request.md" 25 | dest: "{{workspace}}/.github/ISSUE_TEMPLATE/feature_request.md" 26 | mode: "0644" 27 | 28 | - name: Copy ISSUE_TEMPLATE/question.md 29 | copy: 30 | src: "{{habits}}/lib/ansible/files/github/ISSUE_TEMPLATE/question.md" 31 | dest: "{{workspace}}/.github/ISSUE_TEMPLATE/question.md" 32 | mode: "0644" 33 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/issues/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/issues/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove ISSUE_TEMPLATE/bug_report.md 7 | file: 8 | path: "{{workspace}}/.github/ISSUE_TEMPLATE/bug_report.md" 9 | state: absent 10 | 11 | - name: Remove ISSUE_TEMPLATE/feature_request.md 12 | file: 13 | path: "{{workspace}}/.github/ISSUE_TEMPLATE/feature_request.md" 14 | state: absent 15 | 16 | - name: Remove ISSUE_TEMPLATE/question.md 17 | file: 18 | path: "{{workspace}}/.github/ISSUE_TEMPLATE/question.md" 19 | state: absent 20 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/pull-request/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/templates/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create .github directory 7 | file: 8 | path: "{{workspace}}/.github" 9 | state: directory 10 | 11 | - name: Copy .github/pull_request_template.md 12 | copy: 13 | src: "{{habits}}/lib/ansible/files/github/pull_request_template.md" 14 | dest: "{{workspace}}/.github/pull_request_template.md" 15 | mode: "0644" 16 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/pull-request/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/templates/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove .github/pull_request_template.md 7 | file: 8 | path: "{{workspace}}/.github/pull_request_template.md" 9 | state: absent 10 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/workflows/init.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/workflows/init) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Create .github directory 7 | file: 8 | path: "{{workspace}}/.github" 9 | state: directory 10 | 11 | - name: Create .github/workflows directory 12 | file: 13 | path: "{{workspace}}/.github/workflows" 14 | state: directory 15 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/github/workflows/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (github/workflows/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove github/workflows 7 | file: 8 | path: "{{workspace}}/.github/workflows" 9 | state: absent 10 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/habits/remove.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (habits/remove) 3 | hosts: localhost 4 | gather_facts: yes 5 | tasks: 6 | - name: Remove Habits from Makefile (1/4) 7 | lineinfile: 8 | dest: "{{ workspace }}/Makefile" 9 | state: absent 10 | line: "export WORKSPACE=$(shell pwd)" 11 | 12 | - name: Remove Habits from Makefile (2/4) 13 | lineinfile: 14 | dest: "{{ workspace }}/Makefile" 15 | state: absent 16 | line: "export HABITS = $(WORKSPACE)/habits" 17 | 18 | - name: Remove Habits from Makefile (3/4) 19 | lineinfile: 20 | dest: "{{ workspace }}/Makefile" 21 | state: absent 22 | line: "include $(HABITS)/lib/make/Makefile" 23 | 24 | - name: Remove Habits from Makefile (4/4) 25 | lineinfile: 26 | dest: "{{ workspace }}/Makefile" 27 | state: absent 28 | line: "include $(HABITS)/lib/make/*/Makefile" 29 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/ubuntu/install.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (ubuntu/install) 3 | hosts: localhost 4 | gather_facts: yes 5 | become: yes 6 | tasks: 7 | - name: Install a list of packages 8 | ansible.builtin.apt: 9 | pkg: 10 | - bash-completion 11 | - ca-certificates 12 | - curl 13 | - expect 14 | - figlet 15 | - gawk 16 | - git 17 | - gnupg 18 | - gnupg2 19 | - jq 20 | - less 21 | - make 22 | - nodejs 23 | - openssh-server 24 | - pre-commit 25 | - python3-pip 26 | - software-properties-common 27 | - ssh 28 | - tree 29 | - tzdata 30 | - unzip 31 | - vim 32 | - wget 33 | -------------------------------------------------------------------------------- /lib/ansible/playbooks/ubuntu/update.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ansible Playbook (ubuntu/update) 3 | hosts: localhost 4 | gather_facts: yes 5 | become: yes 6 | tasks: 7 | - name: Update all packages to their latest version 8 | apt: 9 | name: "*" 10 | state: latest 11 | 12 | - name: Upgrade the OS (apt-get dist-upgrade) 13 | apt: 14 | upgrade: dist 15 | 16 | - name: Remove useless packages from the cache 17 | apt: 18 | autoclean: yes 19 | 20 | - name: Remove dependencies that are no longer required 21 | apt: 22 | autoremove: yes 23 | 24 | - name: Run the equivalent of "apt-get clean" as a separate step 25 | apt: 26 | clean: yes 27 | -------------------------------------------------------------------------------- /lib/ansible/templates/readme.j2: -------------------------------------------------------------------------------- 1 | 9 | 10 | ![logo][logo] 11 | 12 | {% if badges is defined %} 13 | 14 | {% if badges.custom is defined %}{% for badge in badges.custom %}[![{{ badge.title }}]({{ badge.icon }})]({{ badge.url }}){% endfor %}{% endif %} 15 | {% if badges.workflows is defined %}{% for workflow in badges.workflows %}[![{{ workflow.name }}]({{ url }}/actions/workflows/{{ workflow.name }}.yaml/badge.svg)]({{url}}/actions/workflows/{{ workflow.name }}.yaml){% endfor %}{% endif %} 16 | 17 | {% endif %} 18 | 19 | # {{ title }} 20 | 21 | {{ description }} 22 | 23 | {% if screenshots is defined %} 24 | {% for screenshot in screenshots %} 25 | | ![{{ screenshot.label }}]({{ screenshot.url }}) | 26 | |:--:| 27 | | *{{ screenshot.caption }}* | 28 | 29 | {% endfor %} 30 | {% endif %} 31 | 32 | ## Table of Contents 33 | 34 | {% if getting_started is defined %} 35 | - [Getting Started](#getting-started) 36 | {% endif %} 37 | 38 | {% if prerequisites is defined %} 39 | - [Prerequisites](#prerequisites) 40 | {% endif %} 41 | 42 | {% if installation is defined %} 43 | - [Installation](#installation) 44 | {% endif %} 45 | 46 | {% if usage is defined %} 47 | - [Usage](#usage) 48 | {% endif %} 49 | 50 | {% if how_tos is defined %} 51 | - [How-Tos](#how-tos) 52 | {% for how_to in how_tos %} 53 | - [{{ how_to.title }}](#{{ how_to.title | lower | replace(" ", "-") | indent(width=4) }}) 54 | {% endfor %} 55 | {% endif %} 56 | 57 | {% if testing is defined %} 58 | - [Testing](#testing) 59 | {% endif %} 60 | 61 | {% if deployment is defined %} 62 | - [Deployment](#deployment) 63 | {% endif %} 64 | 65 | {% if getting_started is defined %} 66 | ## Getting Started 67 | 68 | {{ getting_started }} 69 | 70 | {% endif %} 71 | 72 | ## Prerequisites 73 | {{ prerequisites.content }} 74 | 75 | {% if prerequisites is defined %} 76 | {% if prerequisites.references is defined %} 77 | {% for reference in prerequisites.references %} 78 | - [{{ reference.name }}]({{ reference.url }}) - {{ reference.description }} 79 | {% endfor %} 80 | {% endif %} 81 | {% endif %} 82 | 83 | 84 | {% if installation is defined %} 85 | ## Installation 86 | {{ installation }} 87 | 88 | {% endif %} 89 | 90 | ## Usage 91 | {{ usage }} 92 | 93 | {% if how_tos is defined %} 94 | ## How-Tos 95 | Below you can learn 96 | 97 | {% for how_to in how_tos %} 98 | ### {{ how_to.title }} 99 | {{ how_to.content }} 100 | 101 | {% endfor %} 102 | {% endif %} 103 | 104 | {% if testing is defined %} 105 | ## Testing 106 | {{ testing }} 107 | {% endif %} 108 | 109 | {% if deployment is defined %} 110 | ## Deployment 111 | {{ deployment }} 112 | {% endif %} 113 | 114 | {% if contacts is defined %} 115 | ## Contact 116 | {% for contact in contacts %} 117 | - [{{ contact.name }}](mailto:{{ contact.email }}) 118 | {% endfor %} 119 | 120 | {% endif %} 121 | 122 | {% if references is defined %} 123 | ## References 124 | {% for reference in references %} 125 | - [{{ reference.name }}]({{ reference.url }}) - {{ reference.description }} 126 | {% endfor %} 127 | {% endif %} 128 | 129 | 130 | {% if license is defined %} 131 | ## License 132 | This project is licensed under the {{ license }} License. See the [LICENSE](LICENSE) file. 133 | {% endif %} 134 | 135 | {% if copyright is defined %} 136 | ## Copyright 137 | {{ copyright }} 138 | {% endif %} 139 | 140 | {% if trademark is defined and trademark == "yes" %} 141 | ## Trademarks 142 | All other trademarks referenced herein are the property of their respective owners. 143 | {% endif %} 144 | 145 | [repo]: {{ url }} 146 | [logo]: {{ logo }} 147 | 148 | {% if anchors is defined %} 149 | {% for anchor in anchors %} 150 | [{{ anchor.name }}]: {{ anchor.url }} 151 | {% endfor %} 152 | {% endif %} 153 | -------------------------------------------------------------------------------- /lib/make/ansible.mk: -------------------------------------------------------------------------------- 1 | .PHONY: ansible/install 2 | ## Install Ansible 3 | ansible/install: 4 | @sudo apt update 5 | @sudo apt install --yes software-properties-common 6 | @sudo add-apt-repository --yes --update ppa:ansible/ansible 7 | @sudo apt install --yes ansible 8 | 9 | .PHONY: ansible/playbooks/aws/config/init 10 | ansible/playbooks/aws/config/init: 11 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/aws/config/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 12 | 13 | .PHONY: ansible/playbooks/aws/config/remove 14 | ansible/playbooks/aws/config/remove: 15 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/aws/config/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 16 | 17 | .PHONY: ansible/playbooks/doc/init 18 | ansible/playbooks/doc/init: 19 | cd $(HABITS)/lib/ansible && ansible-playbook playbooks/doc/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 20 | 21 | .PHONY: ansible/playbooks/doc/build 22 | ansible/playbooks/doc/build: 23 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/doc/build.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" --extra-vars=@$(WORKSPACE)/doc/habits.yaml 24 | 25 | .PHONY: ansible/playbooks/doc/remove 26 | ansible/playbooks/doc/remove: 27 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/doc/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 28 | 29 | .PHONY: ansible/playbooks/github/actions/init 30 | ansible/playbooks/github/actions/init: 31 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/actions/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 32 | 33 | .PHONY: ansible/playbooks/github/actions/remove 34 | ansible/playbooks/github/actions/remove: 35 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/actions/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 36 | 37 | .PHONY: ansible/playbooks/github/issues/init 38 | ansible/playbooks/github/issues/init: 39 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/issues/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 40 | 41 | .PHONY: ansible/playbooks/github/issues/remove 42 | ansible/playbooks/github/issues/remove: 43 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/issues/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 44 | 45 | .PHONY: ansible/playbooks/habits/remove 46 | ansible/playbooks/habits/remove: 47 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/habits/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 48 | 49 | .PHONY: ansible/playbooks/github/pull-request/init 50 | ansible/playbooks/github/pull-request/init: 51 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/pull-request/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 52 | 53 | .PHONY: ansible/playbooks/github/pull-request/remove 54 | ansible/playbooks/github/pull-request/remove: 55 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/pull-request/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 56 | 57 | .PHONY: ansible/playbooks/github/workflows/init 58 | ansible/playbooks/github/workflows/init: 59 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/workflows/init.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 60 | 61 | .PHONY: ansible/playbooks/github/workflows/remove 62 | ansible/playbooks/github/workflows/remove: 63 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/github/workflows/remove.yaml --extra-vars="workspace=$(WORKSPACE) habits=$(HABITS)" 64 | 65 | .PHONY: ansible/playbooks/ubuntu/install 66 | ansible/playbooks/ubuntu/install: 67 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/ubuntu/install.yaml 68 | 69 | .PHONY: ansible/playbooks/ubuntu/update 70 | ansible/playbooks/ubuntu/update: 71 | @cd $(HABITS)/lib/ansible && ansible-playbook playbooks/ubuntu/update.yaml --ask-become-pass 72 | -------------------------------------------------------------------------------- /lib/make/aws/amplify.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/amplify/install 2 | ## Install AWS Amplify CLI on Ubuntu 22.04 3 | aws/amplify/install: 4 | sudo apt-get update 5 | sudo apt-get install -y nodejs npm 6 | sudo npm install -g @aws-amplify/cli 7 | 8 | .PHONY: aws/amplify/init 9 | ## Initialize a new Amplify project 10 | aws/amplify/init: 11 | amplify init 12 | 13 | .PHONY: aws/amplify/add-analytics 14 | ## Add an AWS resource to the project 15 | aws/amplify/add-analytics: 16 | amplify add analytics 17 | .PHONY: aws/amplify/add-api 18 | 19 | aws/amplify/add-api: 20 | amplify add api 21 | .PHONY: aws/amplify/add-auth 22 | 23 | aws/amplify/add-auth: 24 | amplify add auth 25 | .PHONY: aws/amplify/add-hosting 26 | 27 | aws/amplify/add-hosting: 28 | amplify add hosting 29 | .PHONY: aws/amplify/add-storage 30 | 31 | aws/amplify/add-storage: 32 | amplify add storage 33 | 34 | .PHONY: aws/amplify/push 35 | ## Push local changes to the Amplify environment 36 | aws/amplify/push: 37 | amplify push 38 | 39 | .PHONY: aws/amplify/deploy 40 | ## Deploy amplify hosting resources 41 | aws/amplify/deploy: 42 | amplify hosting deploy 43 | 44 | .PHONY: aws/amplify/remove 45 | ## Remove Amplify resources 46 | aws/amplify/remove: 47 | amplify remove 48 | 49 | .PHONY: aws/amplify/console 50 | ## Open the Amplify Console for the project 51 | aws/amplify/console: 52 | amplify console 53 | 54 | .PHONY: aws/amplify/status 55 | ## Check the status of the Amplify project 56 | aws/amplify/status: 57 | amplify status 58 | 59 | .PHONY: aws/amplify/list 60 | ## List available Amplify resources in the project 61 | aws/amplify/list: 62 | amplify status 63 | 64 | .PHONY: aws/amplify/codegen 65 | ## Generate code for the Amplify resources 66 | aws/amplify/codegen: 67 | amplify codegen 68 | 69 | .PHONY: aws/amplify/configure 70 | ## Configure Amplify project settings 71 | aws/amplify/configure: 72 | amplify configure 73 | 74 | .PHONY: aws/amplify/edit 75 | ## View or edit the current Amplify project 76 | aws/amplify/edit: 77 | amplify edit 78 | 79 | .PHONY: aws/amplify/docs 80 | ## Open the Amplify documentation 81 | aws/amplify/docs: 82 | @python -m webbrowser -t https://docs.amplify.aws 83 | 84 | .PHONY: aws/amplify/clean 85 | ## Clean up any generated files or build artifacts 86 | aws/amplify/clean: 87 | rm -rf amplify/.temp 88 | rm -rf src/generated-models 89 | rm -rf src/generated-graphql 90 | rm -rf dist 91 | -------------------------------------------------------------------------------- /lib/make/aws/cdk.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/cdk/bootstrap 2 | aws/cdk/bootstrap: 3 | cd packages/infra && npx cdk bootstrap --verbose 4 | 5 | .PHONY: aws/cdk/destroy-bootstrap 6 | aws/cdk/destroy-bootstrap: 7 | aws cloudformation delete-stack --stack-name CDKToolkit 8 | 9 | .PHONY: aws/cdk/install 10 | aws/cdk/install: 11 | npm install -g aws-cdk 12 | -------------------------------------------------------------------------------- /lib/make/aws/cfn-lint.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/cfn-lint/install 2 | ## Install AWS CloudFormation Linter 3 | aws/cfn-lint/install: 4 | @pip install cfn-lint 5 | -------------------------------------------------------------------------------- /lib/make/aws/cli.mk: -------------------------------------------------------------------------------- 1 | # aws-sso-creds-helper: 2 | # When using aws sso login on AWS CLI v2 as of July 27th, 2020, 3 | # the credentials are stored so they will work with the CLI itself (v2) but don't work on the AWS SDKs and other tools that expect credentials to be readable from ~/.aws/credentials (v1). 4 | # This package aims to streamline updating the AWS credentials file for AWS SSO users by updating/creating the corresponding profile section in ~/.aws/credentials with temporary role credentials. 5 | 6 | .PHONY: aws/cli/install 7 | ## Install AWS Command Line Interface v2 8 | aws/cli/install: aws/cli/install/v2 aws/cli/autocomplete 9 | 10 | .PHONY:aws/cli/install/v2 11 | aws/cli/install/v2: 12 | @mkdir -p /tmp/awscli ;\ 13 | cd /tmp/awscli ;\ 14 | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" --silent -o "awscliv2.zip" ;\ 15 | unzip -qq awscliv2.zip ;\ 16 | sudo ./aws/install ;\ 17 | rm -rf /tmp/awscli ;\ 18 | 19 | .PHONY: aws/cli/autocomplete 20 | aws/cli/autocomplete: 21 | @echo "complete -C '/usr/local/bin/aws_completer' aws" | tee --append ~/.bashrc 22 | @echo "complete -C '/usr/local/bin/aws_completer' aws" | tee --append ~/.zshrc 23 | 24 | .PHONY: aws/cli/install/sso-creds-helper 25 | aws/cli/install/sso-creds-helper: 26 | npm install -g aws-sso-creds-helper 27 | 28 | .PHONY: aws/cli/version 29 | ## Display AWS CLI version 30 | aws/cli/version: 31 | @echo "--- AWS CLI ---" 32 | @aws --version 33 | -------------------------------------------------------------------------------- /lib/make/aws/cloudformation.mk: -------------------------------------------------------------------------------- 1 | # Expected folder structure 2 | # └── infrastructure 3 | # └── mystack 4 | # ├── parameters 5 | # │   └── dev.json 6 | # └── template.yml 7 | 8 | .PHONY: aws/cloudformation/create-folder-structure 9 | ## Create a folder structure for CloudFormation projects 10 | aws/cloudformation/create-folder-structure: 11 | $(call assert-set,STACK_NAME_PREFIX) 12 | @mkdir -p infrastructure/$(STACK_NAME_PREFIX)/parameters 13 | 14 | .PHONY: aws/cloudformation/create-template-yaml 15 | ## Copy a CloudFormation template to be used as example 16 | aws/cloudformation/create-template-yaml: 17 | $(call assert-set,STACK_NAME_PREFIX) 18 | @cp $(HABITS)/files/aws/cloudformation/template.yml infrastructure/$(STACK_NAME_PREFIX)/template.yml 19 | 20 | .PHONY: aws/cloudformation/create-parameters 21 | ## Copy a CloudFormation parameters to be used as example 22 | aws/cloudformation/create-parameters: 23 | $(call assert-set,STACK_NAME_PREFIX) 24 | $(call assert-set,ENVIRONMENT) 25 | @cp $(HABITS)/files/aws/cloudformation/parameters.json infrastructure/$(STACK_NAME_PREFIX)/parameters/$(ENVIRONMENT).json 26 | 27 | .PHONY: aws/cloudformation/create-project 28 | ## Create a CloudFormation project structure 29 | aws/cloudformation/create-project: \ 30 | aws/cloudformation/create-folder-structure \ 31 | aws/cloudformation/create-template-yaml \ 32 | aws/cloudformation/create-parameters 33 | 34 | STACK_ENVIRONMENT_NAME ?= $(STACK_NAME_PREFIX)-$(ENVIRONMENT) 35 | 36 | # Generate random unique 4-letter identifier 37 | CHANGE_SET_ID:=$(shell openssl rand -hex 4) 38 | CHANGE_SET_NAME ?= $(STACK_ENVIRONMENT_NAME)-$(CHANGE_SET_ID) 39 | 40 | .PHONY: aws/cloudformation/assert/variables 41 | aws/cloudformation/assert/variables: 42 | $(call assert-set,INFRASTRUCTURE) 43 | $(call assert-set,TEMPLATE) 44 | $(call assert-set,STACK_NAME_PREFIX) 45 | $(call assert-set,ENVIRONMENT) 46 | $(call assert-set,PARAMETERS) 47 | @echo "-------------------------" 48 | @echo "INFRASTRUCTURE: $(INFRASTRUCTURE)" 49 | @echo "TEMPLATE: $(TEMPLATE)" 50 | @echo "STACK_NAME_PREFIX: $(STACK_NAME_PREFIX)" 51 | @echo "ENVIRONMENT: $(ENVIRONMENT)" 52 | @echo "PARAMETERS: $(PARAMETERS)" 53 | @echo "STACK_ENVIRONMENT_NAME: $(STACK_ENVIRONMENT_NAME)" 54 | @echo "-------------------------" 55 | 56 | .PHONY: aws/cloudformation/assert/variables-without-parameters 57 | aws/cloudformation/assert/variables-without-parameters: 58 | $(call assert-set,INFRASTRUCTURE) 59 | $(call assert-set,TEMPLATE) 60 | $(call assert-set,STACK_NAME_PREFIX) 61 | $(call assert-set,ENVIRONMENT) 62 | @echo "-------------------------" 63 | @echo "INFRASTRUCTURE: $(INFRASTRUCTURE)" 64 | @echo "TEMPLATE: $(TEMPLATE)" 65 | @echo "STACK_NAME_PREFIX: $(STACK_NAME_PREFIX)" 66 | @echo "ENVIRONMENT: $(ENVIRONMENT)" 67 | @echo "STACK_ENVIRONMENT_NAME: $(STACK_ENVIRONMENT_NAME)" 68 | @echo "-------------------------" 69 | 70 | .PHONY: aws/cloudformation/create-stack 71 | ## Creates a stack as specified in the template. 72 | aws/cloudformation/create-stack: aws/cloudformation/assert/variables 73 | @echo "Creating Stack $(STACK_ENVIRONMENT_NAME)" 74 | @aws --profile $(AWS_PROFILE) --profile $(AWS_PROFILE) --profile $(AWS_PROFILE) cloudformation create-stack \ 75 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 76 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 77 | --parameters file://infrastructure/$(INFRASTRUCTURE)/params/$(PARAMETERS).json \ 78 | --capabilities CAPABILITY_IAM 79 | @echo "Waiting for stack $(STACK_ENVIRONMENT_NAME) to be created ..." 80 | @aws --profile $(AWS_PROFILE) cloudformation wait stack-create-complete --stack-name $(STACK_ENVIRONMENT_NAME) 81 | @echo "CloudFormation stack $(STACK_ENVIRONMENT_NAME) created successfully" 82 | @$(MAKE) --no-print-directory aws/cloudformation/display-stack-events 83 | 84 | .PHONY: aws/cloudformation/display-stack-events 85 | aws/cloudformation/display-stack-events: 86 | $(call assert-set,AWS_PROFILE) 87 | $(call assert-set,STACK_ENVIRONMENT_NAME) 88 | $(call assert-set,AWS_DEFAULT_REGION) 89 | $(call assert-set,STACK_ID) 90 | $(eval STACK_ID := $(shell aws --profile $(AWS_PROFILE) cloudformation describe-stacks --stack-name $(STACK_ENVIRONMENT_NAME) --query 'Stacks[*].[StackId]' --output text)) 91 | @echo "-------------------------" 92 | @echo -e '\e]8;;https://$(AWS_DEFAULT_REGION).console.aws.amazon.com/cloudformation/home?region=$(AWS_DEFAULT_REGION)#/stacks/events?stackId=$(STACK_ID)&filteringStatus=active&filteringText=&viewNested=true&hideStacks=true\aView Stack Events\e]8;;\a' 93 | 94 | .PHONY: aws/cloudformation/create-stack-without-parameters 95 | ## Creates a stack as specified in the template. (don't pass --parameters flag) 96 | aws/cloudformation/create-stack-without-parameters: aws/cloudformation/assert/variables-without-parameters 97 | @echo "Creating Stack $(STACK_ENVIRONMENT_NAME)" 98 | @aws --profile $(AWS_PROFILE) cloudformation create-stack \ 99 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 100 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 101 | --capabilities CAPABILITY_IAM 102 | @echo "Waiting for stack $(STACK_ENVIRONMENT_NAME) to be created ..." 103 | @aws --profile $(AWS_PROFILE) cloudformation wait stack-create-complete --stack-name $(STACK_ENVIRONMENT_NAME) 104 | @echo "CloudFormation stack $(STACK_ENVIRONMENT_NAME) created successfully" 105 | @$(MAKE) --no-print-directory aws/cloudformation/display-stack-events 106 | 107 | .PHONY: aws/cloudformation/create/service-linked-role 108 | ## Creates an IAM role that is linked to a specific Amazon Elasticsearch service. 109 | aws/cloudformation/create/service-linked-role: 110 | $(call assert-set,SERVICE_NAME) 111 | @aws iam create-service-linked-role --aws-service-name $(SERVICE_NAME) 112 | 113 | .PHONY: aws/cloudformation/describe-stack-events 114 | ## Returns all stack related events for a specified stack in reverse chronological order. 115 | aws/cloudformation/describe-stack-events: aws/cloudformation/assert/variables 116 | @aws --profile $(AWS_PROFILE) cloudformation describe-stack-events --stack-name $(STACK_ENVIRONMENT_NAME) 117 | 118 | .PHONY: aws/cloudformation/describe-stack 119 | ## Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created. 120 | aws/cloudformation/describe-stack: aws/cloudformation/assert/variables 121 | @aws --profile $(AWS_PROFILE) cloudformation describe-stacks --stack-name $(STACK_ENVIRONMENT_NAME) 122 | 123 | .PHONY: aws/cloudformation/delete/service-linked-role 124 | ## Deletes an IAM role that is linked to a specific Amazon Web Services service. 125 | aws/cloudformation/delete/service-linked-role: 126 | $(call assert-set,SERVICE_NAME) 127 | @aws iam delete-service-linked-role --role-name $(SERVICE_NAME) 128 | 129 | .PHONY: aws/cloudformation/hygiene 130 | ## Execute CFN Lint and pre-commit rules 131 | aws/cloudformation/hygiene: 132 | $(call assert-set,INFRASTRUCTURE) 133 | @cfn-lint infrastructure/$(INFRASTRUCTURE)/*.yml 134 | @$(MAKE) --no-print-directory pre-commit/run 135 | 136 | .PHONY: aws/cloudformation/create-change-set 137 | ## Creates a list of changes that will be applied to a stack so that you can review the changes before executing them. 138 | aws/cloudformation/create-change-set: aws/cloudformation/assert/variables 139 | @echo "Creating Change Set $(CHANGE_SET_NAME)" 140 | $(eval CHANGE_SET := $(shell aws --profile $(AWS_PROFILE) cloudformation create-change-set \ 141 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 142 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 143 | --parameters file://infrastructure/$(INFRASTRUCTURE)/params/$(PARAMETERS).json \ 144 | --capabilities CAPABILITY_IAM \ 145 | --change-set-name $(CHANGE_SET_NAME) \ 146 | --output text \ 147 | )) 148 | @sleep 5 149 | @echo "Waiting for Change Set $(CHANGE_SET_NAME) to be created" 150 | @aws --profile $(AWS_PROFILE) cloudformation wait change-set-create-complete \ 151 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 152 | --change-set-name $(CHANGE_SET_NAME) 153 | @echo "Change Set $(CHANGE_SET_NAME) created successfully" 154 | @echo "-------------------------" 155 | $(eval STACK_ID := $(shell echo $(CHANGE_SET) | awk '{print $$2}')) 156 | $(eval CHANGE_SET_ID := $(shell echo $(CHANGE_SET) | awk '{print $$1}')) 157 | @echo -e '\e]8;;https://$(AWS_DEFAULT_REGION).console.aws.amazon.com/cloudformation/home?region=$(AWS_DEFAULT_REGION)#/stacks/changesets/changes?stackId=$(STACK_ID)&changeSetId=$(CHANGE_SET_ID)\aView Change Set\e]8;;\a' 158 | 159 | .PHONY: aws/cloudformation/show-latest-change-set 160 | aws/cloudformation/show-latest-change-set: 161 | $(call assert-set,AWS_DEFAULT_REGION) 162 | $(call assert-set,STACK_ID) 163 | $(call assert-set,CHANGE_SET_ID) 164 | $(eval STACK_ID := $(shell grep '"StackId":' /tmp/change-set | awk '{print $$2}' | sed s/,//g | sed s,\",,g)) 165 | $(eval CHANGE_SET_ID := $(shell grep '"Id":' /tmp/change-set | awk '{print $$2}' | sed s/,//g | sed s,\",,g)) 166 | @echo "-------------------------" 167 | @echo -e '\e]8;;https://$(AWS_DEFAULT_REGION).console.aws.amazon.com/cloudformation/home?region=$(AWS_DEFAULT_REGION)#/stacks/changesets/changes?stackId=$(STACK_ID)&changeSetId=$(CHANGE_SET_ID)\aView Change Set\e]8;;\a' 168 | 169 | .PHONY: aws/cloudformation/create-change-set-without-parameters 170 | ## Creates a list of changes that will be applied to a stack so that you can review the changes before executing them. 171 | aws/cloudformation/create-change-set-without-parameters: aws/cloudformation/assert/variables-without-parameters 172 | @echo "Creating Change Set $(CHANGE_SET_NAME)" 173 | @aws --profile $(AWS_PROFILE) cloudformation create-change-set \ 174 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 175 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 176 | --capabilities CAPABILITY_IAM \ 177 | --change-set-name $(CHANGE_SET_NAME) 178 | @echo "Waiting for Change Set $(CHANGE_SET_NAME) to be created" 179 | @aws --profile $(AWS_PROFILE) cloudformation wait change-set-create-complete \ 180 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 181 | --change-set-name $(CHANGE_SET_NAME) 182 | @echo "Change Set $(CHANGE_SET_NAME) created successfully" 183 | 184 | .PHONY: aws/cloudformation/delete-change-set 185 | ## Delete latest change-set created 186 | aws/cloudformation/delete-change-set: aws/cloudformation/assert/variables 187 | @echo "Deleting latest Change Set" 188 | @$(MAKE) --no-print-directory aws/cloudformation/latest-change-set \ 189 | | xargs aws --profile $(AWS_PROFILE) cloudformation delete-change-set --stack-name $(STACK_ENVIRONMENT_NAME) --change-set-name 190 | 191 | .PHONY: aws/cloudformation/execute-change-set 192 | ## Execute latest change-set 193 | aws/cloudformation/execute-change-set: aws/cloudformation/assert/variables 194 | @echo "Executing latest Change Set" 195 | $(eval CHANGE_SET_NAME := $(shell $(MAKE) --no-print-directory aws/cloudformation/latest-change-set)) 196 | @aws --profile $(AWS_PROFILE) cloudformation execute-change-set --stack-name $(STACK_ENVIRONMENT_NAME) --change-set-name $(CHANGE_SET_NAME) 197 | @$(MAKE) --no-print-directory aws/cloudformation/display-stack-events 198 | 199 | .PHONY: aws/cloudformation/latest-change-set 200 | ## Display latest change-set 201 | aws/cloudformation/latest-change-set: 202 | $(call assert-set,AWS_PROFILE) 203 | $(call assert-set,STACK_ENVIRONMENT_NAME) 204 | @aws --profile $(AWS_PROFILE) cloudformation list-change-sets \ 205 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 206 | --query 'Summaries[*].[CreationTime, ChangeSetName]' \ 207 | --output text | sort -rk1 | head -n 1 | awk '{print $$2}' 208 | 209 | .PHONY: aws/cloudformation/estimate-template-cost 210 | ## Returns the estimated monthly cost of a template 211 | aws/cloudformation/estimate-template-cost: aws/cloudformation/assert/variables 212 | @echo "Template Cost Estimation" 213 | @aws --profile $(AWS_PROFILE) cloudformation estimate-template-cost \ 214 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 215 | --parameters file://infrastructure/$(INFRASTRUCTURE)/params/$(PARAMETERS).json \ 216 | 217 | .PHONY: aws/cloudformation/detect-stack-drift 218 | ## Detects whether a stack's actual configuration differs, or has drifted , from it's expected configuration, as defined in the stack template and any values specified as template parameters. 219 | aws/cloudformation/detect-stack-drift: aws/cloudformation/assert/variables 220 | @aws/cloudformation/aws --profile $(AWS_PROFILE) cloudformation detect-stack-drift \ 221 | --stack-name $(STACK_ENVIRONMENT_NAME) \ 222 | 223 | .PHONY: aws/cloudformation/validate-template 224 | aws/cloudformation/validate-template: 225 | $(call assert-set,AWS_PROFILE) 226 | $(call assert-set,INFRASTRUCTURE) 227 | $(call assert-set,TEMPLATE) 228 | @echo "Validate Template" 229 | @aws --profile $(AWS_PROFILE) cloudformation validate-template \ 230 | --template-body file://infrastructure/$(INFRASTRUCTURE)/$(TEMPLATE).yml \ 231 | --output yaml 232 | 233 | .PHONY: aws/cloudformation/delete-stack 234 | ## Delete CloudFormation Stack 235 | aws/cloudformation/delete-stack: aws/cloudformation/assert/variables-without-parameters 236 | @echo "Delete Stack $(STACK_ENVIRONMENT_NAME)" 237 | @echo Warning: Continue? [Y/n] 238 | @read line; if [ $$line = "n" ]; then echo aborting; exit 1 ; fi 239 | @aws --profile $(AWS_PROFILE) cloudformation delete-stack --stack-name $(STACK_ENVIRONMENT_NAME) 240 | @sleep 5 241 | @echo "Waiting for stack $(STACK_ENVIRONMENT_NAME) to be deleted ..." 242 | @aws --profile $(AWS_PROFILE) cloudformation wait stack-delete-complete --stack-name $(STACK_ENVIRONMENT_NAME) 243 | -------------------------------------------------------------------------------- /lib/make/aws/cloudwatch.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/cloudwatch/logs/delete-log-groups-prefix 2 | aws/cloudwatch/logs/delete-log-groups-prefix: 3 | $(call assert-set,AWS_REGION) 4 | $(call assert-set,AWS_ACCOUNT_ID) 5 | @aws logs describe-log-groups --log-group-name-prefix '/aws/lambda/ul-dev-' --query 'logGroups[*].logGroupName' --output text | tr '\t' '\n' | while read log_group; do \ 6 | aws logs delete-log-group --log-group-name $$log_group; \ 7 | done 8 | -------------------------------------------------------------------------------- /lib/make/aws/code-artifact.mk: -------------------------------------------------------------------------------- 1 | # Don't forget to export the following environment variables 2 | # export AWS_CODE_ARTIFACT_REPOSITORY= 3 | # export AWS_CODE_ARTIFACT_OWNER= 4 | # export AWS_CODE_ARTIFACT_DOMAIN= 5 | 6 | .PHONY: aws/codeartifact/login 7 | ## Login into AWS CodeArtifact 8 | aws/codeartifact/login: 9 | $(call assert-set,AWS_PROFILE) 10 | $(call assert-set,AWS_CODE_ARTIFACT_REPOSITORY) 11 | $(call assert-set,AWS_CODE_ARTIFACT_OWNER) 12 | $(call assert-set,AWS_CODE_ARTIFACT_DOMAIN) 13 | @aws --profile $(AWS_PROFILE) codeartifact login --tool npm --repository $(AWS_CODE_ARTIFACT_REPOSITORY) --domain $(AWS_CODE_ARTIFACT_DOMAIN) --domain-owner $(AWS_CODE_ARTIFACT_OWNER) 14 | -------------------------------------------------------------------------------- /lib/make/aws/cognito.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/cognito/list-user-pools 2 | aws/cognito/list-user-pools: 3 | @aws cognito-idp list-user-pools --max-results 10 4 | 5 | .PHONY: aws/cognito/delete-user-pools 6 | aws/cognito/delete-user-pools: 7 | @. .venv/bin/activate && python3 $(WORKSPACE)/scripts/aws/aws-cognito-delete-user-pools.py 8 | 9 | .PHONY: aws/cognito/describe-user-pool 10 | aws/cognito/describe-user-pool: 11 | @aws cognito-idp describe-user-pool --user-pool-id $(AWS_COGNITO_USER_POOL_ID) 12 | 13 | .PHONY: aws/cognito/list-identity-pools 14 | aws/cognito/list-identity-pools: 15 | @aws cognito-identity list-identity-pools --max-results 10 16 | 17 | .PHONY: aws/cognito/user-pool/list-users 18 | aws/cognito/user-pool/list-users: 19 | @aws cognito-idp list-users --user-pool-id $(AWS_COGNITO_USER_POOL_ID) 20 | -------------------------------------------------------------------------------- /lib/make/aws/config.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/config/init 2 | # TODO: use Jinja template 3 | aws/config/init: ansible/playbooks/aws/config/init 4 | -------------------------------------------------------------------------------- /lib/make/aws/dynamodb.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/dynamodb/list-tables 2 | aws/dynamodb/list-tables: 3 | aws dynamodb list-tables 4 | -------------------------------------------------------------------------------- /lib/make/aws/sigv4-proxy.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/sigv4-proxy/build 2 | aws/sigv4-proxy/build: 3 | ifeq ("$(wildcard /tmp/aws-sigv4-proxy)", "") 4 | git clone https://github.com/awslabs/aws-sigv4-proxy.git /tmp/aws-sigv4-proxy 5 | endif 6 | cd /tmp/aws-sigv4-proxy ;\ 7 | docker build . -t aws-sigv4-proxy 8 | 9 | .PHONY: aws/sigv4-proxy/run 10 | aws/sigv4-proxy/run: 11 | $(call assert-set,AWS_PROFILE) 12 | docker run --rm -ti -v ~/.aws:/root/.aws -p 8080:8080 -e 'AWS_SDK_LOAD_CONFIG=true' -e 'AWS_PROFILE=$(AWS_PROFILE)' aws-sigv4-proxy -v 13 | 14 | .PHONY: aws/sigv4-proxy/run-service-region 15 | aws/sigv4-proxy/run-service-region: 16 | $(call assert-set,AWS_PROFILE) 17 | $(call assert-set,AWS_SERVICE) 18 | $(call assert-set,AWS_DEFAULT_REGION) 19 | docker run --rm -ti -v ~/.aws:/root/.aws -p 8080:8080 -e 'AWS_SDK_LOAD_CONFIG=true' -e 'AWS_PROFILE=$(AWS_PROFILE)' aws-sigv4-proxy -v --name $(AWS_SERVICE) --port :9200 20 | -------------------------------------------------------------------------------- /lib/make/aws/sso.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/sso/login 2 | ## Login into AWS account and export credentials to ~/.aws/credentials 3 | aws/sso/login: 4 | $(call assert-set,AWS_PROFILE) 5 | @aws sso login --profile $(AWS_PROFILE) 6 | @sleep 2 7 | @ssocreds -p $(AWS_PROFILE) 8 | -------------------------------------------------------------------------------- /lib/make/aws/sts.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/sts/get-caller-identity 2 | ## Get caller identity 3 | aws/sts/get-caller-identity: 4 | aws sts get-caller-identity 5 | 6 | .PHONY: aws/sts/assume-role 7 | ## Assume role 8 | aws/sts/assume-role: 9 | aws sts assume-role --role-arn --role-session-name 10 | 11 | .PHONY: aws/sts/get-session-token 12 | ## Get session token 13 | aws/sts/get-session-token: 14 | aws sts get-session-token --duration-seconds 15 | 16 | .PHONY: aws/sts/refresh-session-token 17 | ## Refresh session token 18 | aws/sts/refresh-session-token: 19 | aws sts refresh-session-token --duration-seconds --serial-number --token-code 20 | 21 | .PHONY: aws/sts/delete-session-token 22 | ## Delete session token 23 | aws/sts/delete-session-token: 24 | aws sts delete-session-token 25 | 26 | .PHONY: aws/sts/describe-caller-identity 27 | ## Describe caller identity 28 | aws/sts/describe-caller-identity: 29 | aws sts get-caller-identity --output json 30 | -------------------------------------------------------------------------------- /lib/make/aws/systems-manager.mk: -------------------------------------------------------------------------------- 1 | .PHONY: aws/ssm/install-plugin 2 | ## Install AWS SSM plugin 3 | aws/ssm/install-plugin: 4 | mkdir -p /tmp/download \ 5 | && cd /tmp/download \ 6 | && curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb" \ 7 | && sudo dpkg -i session-manager-plugin.deb \ 8 | && rm -rf /tmp/download 9 | 10 | .PHONY: aws/ssm/start-session 11 | ## Start session with AWS Systems Manager Session Manager 12 | aws/ssm/start-session: 13 | $(call assert-set,INSTANCE_ID) 14 | aws --profile $(AWS_PROFILE) ssm start-session --target $(INSTANCE_ID) 15 | 16 | .PHONY: aws/ssm/port-forwarding 17 | aws/ssm/port-forwarding: 18 | $(call assert-set,INSTANCE_ID) 19 | $(call assert-set,ENDPOINT) 20 | $(call assert-set,REMOTE_PORT) 21 | $(call assert-set,LOCAL_PORT) 22 | aws --profile $(AWS_PROFILE) ssm start-session --target $(INSTANCE_ID) --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "{\"host\":[\"$(ENDPOINT)\"],\"portNumber\":[\"$(REMOTE_PORT)\"],\"localPortNumber\":[\"$(LOCAL_PORT)\"]}" 23 | 24 | .PHONY: aws/ssm/list-bastion-instances 25 | aws/ssm/list-bastion-instances: 26 | aws --profile $(AWS_PROFILE) ec2 describe-instances \ 27 | --filter "Name=tag:bastion,Values=true" \ 28 | --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" \ 29 | --output text 30 | -------------------------------------------------------------------------------- /lib/make/checkov.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | .PHONY: checkov/run 5 | ## Run Checkov 6 | checkov/run: 7 | checkov --directory . 8 | 9 | .PHONY: checkov/install 10 | ## Install Checkov 11 | checkov/install: 12 | @pip3 install --upgrade --user checkov 13 | 14 | .PHONY: checkov/version 15 | ## Display checkov version 16 | checkov/version: 17 | @echo "--- CHECKOV ---" 18 | @checkov --version 19 | -------------------------------------------------------------------------------- /lib/make/cobra.mk: -------------------------------------------------------------------------------- 1 | .PHONY: cobra/install 2 | ## Install cobra's cli 3 | cobra/install: 4 | go install github.com/spf13/cobra-cli@latest 5 | 6 | .PHONY: cobra/add 7 | ## Add a cobra command 8 | cobra/add: 9 | $(call assert-set,COMMAND) 10 | cobra-cli add $(COMMAND) 11 | 12 | .PHONY: cobra/del 13 | ## Delete a Cobra command 14 | cobra/del: 15 | $(call assert-set,COMMAND) 16 | rm -f cmd/$(COMMAND).go 17 | -------------------------------------------------------------------------------- /lib/make/devcontainer.mk: -------------------------------------------------------------------------------- 1 | .PHONY: devcontainer/init 2 | devcontainer/init: 3 | @sudo apt update 4 | @sudo apt install --yes make 5 | @$(MAKE) --no-print-directory \ 6 | ansible/install \ 7 | ansible/playbooks/ubuntu/install 8 | @sudo update-ca-certificates 9 | 10 | .PHONY: devcontainer/terraform/init 11 | devcontainer/terraform/init: devcontainer/init 12 | @$(MAKE) --no-print-directory \ 13 | aws/cli/install/v2 \ 14 | aws/cli/autocomplete \ 15 | terraform/install \ 16 | terraform-docs/install \ 17 | checkov/install \ 18 | tflint/install \ 19 | tfsec/install \ 20 | tfswitch/install \ 21 | terrascan/install 22 | -------------------------------------------------------------------------------- /lib/make/doc.mk: -------------------------------------------------------------------------------- 1 | .PHONY: doc/init 2 | ## Initialize documentation 3 | doc/init: ansible/playbooks/doc/init 4 | 5 | .PHONY: doc/build 6 | ## Builds documentation 7 | doc/build: ansible/playbooks/doc/build 8 | -------------------------------------------------------------------------------- /lib/make/docker.mk: -------------------------------------------------------------------------------- 1 | .PHONY:docker/remove-containers 2 | ## Remove all Docker containers 3 | docker/remove-containers: 4 | docker container stop $(shell docker container ls -aq) 5 | docker container rm $(shell docker container ls -aq) 6 | 7 | .PHONY:docker/remove-images 8 | ## Remove all Docker images 9 | docker/remove-images: 10 | docker image prune --force 11 | docker images --quiet | xargs docker rmi 12 | 13 | .PHONY:docker/remove-volumes 14 | ## Remove all Docker volumes 15 | docker/remove-volumes: 16 | docker volume prune --force 17 | docker volumes ls | xargs docker volume rm 18 | 19 | .PHONY: docker/prune 20 | ## Remove unused images and all stopped containers 21 | docker/prune: 22 | docker system df 23 | docker image prune --force 24 | docker container prune --force 25 | -------------------------------------------------------------------------------- /lib/make/git.mk: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: git/config/init 3 | ## Initialize git configuration for project 4 | git/config/init: 5 | git config init.defaultBranch main 6 | git config branch.main.mergeOptions "--squash" 7 | -------------------------------------------------------------------------------- /lib/make/github.mk: -------------------------------------------------------------------------------- 1 | .PHONY: github/actions/init 2 | ## Initialize .github/actions directory 3 | github/actions/init: ansible/playbooks/github/actions/init 4 | 5 | .PHONY: github/issues/init 6 | ## Initialize .github/issues directory 7 | github/issues/init: ansible/playbooks/github/issues/init 8 | 9 | .PHONY: github/pull-request/init 10 | ## Initialize .github/pull-request directory 11 | github/pull-request/init: ansible/playbooks/github/pull-request/init 12 | 13 | .PHONY: github/workflows/init 14 | ## Initialize .github/workflows directory 15 | github/workflows/init: ansible/playbooks/github/workflows/init 16 | -------------------------------------------------------------------------------- /lib/make/gitignore.mk: -------------------------------------------------------------------------------- 1 | # default gitignore template rules 2 | GITIGNORE?=macos,windows,linux,visualstudiocode,python,node 3 | 4 | .PHONY: gitignore/install 5 | ## Install gitignore 6 | gitignore/install: 7 | @sudo cp $(HABITS)/lib/scripts/gitignore.sh /usr/local/bin/gitignore 8 | @sudo chmod +x /usr/local/bin/gitignore 9 | 10 | .PHONY: gitignore/list 11 | ## List all gitignore templates 12 | gitignore/list: 13 | @gitignore list 14 | 15 | .PHONY: gitignore/init 16 | ## Create .gitignore file 17 | gitignore/init: 18 | @gitignore $(GITIGNORE) > .gitignore 19 | -------------------------------------------------------------------------------- /lib/make/go.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | .PHONY: go/install 5 | ## Install Golang 6 | go/install: 7 | sudo apt-get -qq install --yes golang 8 | 9 | .PHONY: go/version 10 | ## Display Go version 11 | go/version: 12 | @echo "--- GO ---" 13 | @go version 14 | 15 | .PHONY: go/env 16 | ## Print Go environment information 17 | go/env: 18 | @go env 19 | 20 | .PHONY: go/app/build 21 | ## Compile packages and dependencies 22 | go/app/build: 23 | $(call assert-set,OUTPUT) 24 | @mkdir -p build 25 | @go build -o $(OUTPUT) 26 | 27 | .PHONY: go/app/install 28 | ## Compile and install packages and dependencies 29 | go/app/install: 30 | @go install 31 | 32 | .PHONY: go/app/run 33 | ## Compile and run Go program 34 | go/app/run: 35 | @go run main.go 36 | 37 | .PHONY: go/app/fmt 38 | ## gofmt (reformat) package sources 39 | go/app/fmt: 40 | @go fmt ./... 41 | @gofmt -s -w . 42 | 43 | .PHONY: go/app/generate 44 | ## Generate Go files by processing source 45 | go/app/generate: 46 | @go generate ./... 47 | 48 | .PHONY: go/app/mod/tidy 49 | ## Add missing and remove unused modules 50 | go/app/mod/tidy: 51 | @go mod tidy 52 | 53 | .PHONY: go/app/get 54 | ## Add dependencies to current module and install them 55 | go/app/get: 56 | @go get ./... 57 | 58 | .PHONY: go/app/clean 59 | ## Remove object files and cached files 60 | go/app/clean: 61 | @go clean -cache -modcache -i -r 62 | 63 | .PHONY: go/app/list 64 | ## List packages or modules 65 | go/app/list: 66 | $(call assert-set,PACKAGE) 67 | @go list -m -versions $(PACKAGE) 68 | -------------------------------------------------------------------------------- /lib/make/gomplate.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | GOMPLATE_VERSION?=3.10.0 5 | 6 | .PHONY: gomplate/install 7 | gomplate/install: 8 | @mkdir -p /tmp/download \ 9 | && wget https://github.com/hairyhenderson/gomplate/releases/download/v$(GOMPLATE_VERSION)/gomplate_linux-amd64-slim -O /tmp/download/gomplate --quiet --no-check-certificate \ 10 | && chmod +x /tmp/download/gomplate \ 11 | && sudo mv /tmp/download/gomplate /usr/local/bin/ \ 12 | && rm -rf /tmp/download 13 | @echo "gomplate installed successfully!" 14 | @$(MAKE) --no-print-directory gomplate/version 15 | 16 | .PHONY: gomplate/version 17 | ## Display Gomplate version 18 | gomplate/version: 19 | @echo "--- GOMPLATE ---" 20 | @gomplate --version 21 | -------------------------------------------------------------------------------- /lib/make/habits.mk: -------------------------------------------------------------------------------- 1 | .PHONY: habits/install 2 | ## Install Habits dependencies 3 | habits/install: \ 4 | gitignore/install \ 5 | python/pip/install \ 6 | ansible/install \ 7 | pre-commit/install 8 | 9 | .PHONY: habits/init 10 | ## Initialize gitignore, documentation, pre-commit, github workflows, issues and pull-request 11 | habits/init: \ 12 | gitignore/init \ 13 | doc/init \ 14 | pre-commit/init \ 15 | github/actions/init \ 16 | github/issues/init \ 17 | github/pull-request/init \ 18 | github/workflows/init 19 | 20 | .PHONY: habits/update 21 | ## Update Habits 22 | habits/update: 23 | @git submodule update --remote --merge 24 | 25 | .PHONY: habits/remove 26 | ## Uninstall Habits 27 | habits/remove: \ 28 | ansible/playbooks/aws/config/remove \ 29 | ansible/playbooks/doc/remove \ 30 | pre-commit/remove \ 31 | ansible/playbooks/github/actions/remove \ 32 | ansible/playbooks/github/issues/remove \ 33 | ansible/playbooks/github/pull-request/remove \ 34 | ansible/playbooks/github/workflows/remove \ 35 | ansible/playbooks/habits/remove \ 36 | habits/submodule/remove \ 37 | python/virtualenv/remove 38 | 39 | .PHONY: habits/submodule/remove 40 | habits/submodule/remove: 41 | -git submodule deinit --force habits 42 | -git rm --cached habits/ 43 | @rm -rf habits 44 | 45 | .PHONY: habits/check 46 | ## Performs checks 47 | habits/check: 48 | ifeq ("$(wildcard doc)", "") 49 | @echo "Directory doc/ not found. To fix, run: make doc/init" && exit 1 50 | endif 51 | ifeq ("$(wildcard doc/habits.yaml)", "") 52 | @echo "File doc/habits.yaml not found. To fix, run: make doc/init" && exit 1 53 | endif 54 | ifeq ("$(wildcard CHANGELOG.md)", "") 55 | @echo "File CHANGELOG.md not found. To fix, run: make doc/init" && exit 1 56 | endif 57 | ifeq ("$(wildcard CODE_OF_CONDUCT.md)", "") 58 | @echo "File CODE_OF_CONDUCT.md not found. To fix, run: make doc/init" && exit 1 59 | endif 60 | ifeq ("$(wildcard CONTRIBUTING.md)", "") 61 | @echo "File CONTRIBUTING.md not found. To fix, run: make doc/init" && exit 1 62 | endif 63 | ifeq ("$(wildcard SECURITY.md)", "") 64 | @echo "File SECURITY.md not found. To fix, run: make doc/init" && exit 1 65 | endif 66 | ifeq ("$(wildcard README.md)", "") 67 | @echo "File README.md not found. To fix, run: make doc/build" && exit 1 68 | endif 69 | ifeq ("$(wildcard .pre-commit-config.yaml)", "") 70 | @echo "File .pre-commit-config.yaml not found. To fix, run: make pre-commit/init" && exit 1 71 | endif 72 | ifeq ("$(wildcard .gitignore)", "") 73 | @echo "File .gitignore not found. To fix, run: make gitignore/install gitignore/init" && exit 1 74 | endif 75 | ifeq ("$(wildcard .github/actions)", "") 76 | @echo "Directory .github/actions not found. To fix, run: make github/actions/init" && exit 1 77 | endif 78 | ifeq ("$(wildcard .github/workflows)", "") 79 | @echo "Directory .github/workflows not found. To fix, run: make github/workflows/init" && exit 1 80 | endif 81 | ifeq ("$(wildcard .github/ISSUE_TEMPLATE)", "") 82 | @echo "Directory .github/ISSUE_TEMPLATE not found. To fix, run: make github/issues/init" && exit 1 83 | endif 84 | ifeq ("$(wildcard .github/pull_request_template.md)", "") 85 | @echo "File .github/pull_request_template.md not found. To fix, run: make github/pull-request/init" && exit 1 86 | endif 87 | @echo "perform habits checks....................................................Passed" 88 | -------------------------------------------------------------------------------- /lib/make/make/helpers.mk: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := help 2 | 3 | SHELL = /bin/bash 4 | 5 | export SELF ?= $(MAKE) 6 | export EDITOR ?= vim 7 | 8 | green = $(shell echo -e '\x1b[32;01m$1\x1b[0m') 9 | yellow = $(shell echo -e '\x1b[33;01m$1\x1b[0m') 10 | red = $(shell echo -e '\x1b[33;31m$1\x1b[0m') 11 | 12 | .PHONY: help 13 | help: help/clean 14 | @exit 0 15 | 16 | HELP_FILTER ?= .*help 17 | 18 | ## Help screen 19 | help/clean: 20 | @printf "Available targets:\n\n" 21 | @$(MAKE) -s help/generate | grep -v -E "\w($(HELP_FILTER))" 22 | 23 | ## Display help for all targets 24 | help/all: 25 | @printf "All Available targets:\n\n" 26 | @$(MAKE) -s help/generate 27 | 28 | # Generate help output from MAKEFILE_LIST 29 | help/generate: 30 | @awk '/^[-a-zA-Z_0-9%:\\\.\/]+:/ { \ 31 | helpMessage = match(lastLine, /^## (.*)/); \ 32 | if (helpMessage) { \ 33 | helpCommand = $$1; \ 34 | helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ 35 | gsub("\\\\", "", helpCommand); \ 36 | gsub(":+$$", "", helpCommand); \ 37 | printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \ 38 | } \ 39 | } \ 40 | { lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u 41 | @printf "\n" 42 | 43 | # Generate all help documents in MARDOWN 44 | help/doc: 45 | @printf "## Make\n\n" > Makefile.md 46 | @printf '```' >> Makefile.md 47 | @printf "\nAvailable targets:\n\n" >> Makefile.md 48 | @$(MAKE) -s help/generate-no-colour | grep -v -E "\w($(HELP_FILTER))" >> Makefile.md 49 | @printf '```' >> Makefile.md 50 | 51 | # Generate help output from MAKEFILE_LIST 52 | help/generate-no-colour: 53 | @awk '/^[-a-zA-Z_0-9%:\\\.\/]+:/ { \ 54 | helpMessage = match(lastLine, /^## (.*)/); \ 55 | if (helpMessage) { \ 56 | helpCommand = $$1; \ 57 | helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ 58 | gsub("\\\\", "", helpCommand); \ 59 | gsub(":+$$", "", helpCommand); \ 60 | printf " %-35s %s\n", helpCommand, helpMessage; \ 61 | } \ 62 | } \ 63 | { lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u 64 | @printf "\n" 65 | 66 | .PHONY: fix/makefiles 67 | ## Find all Makefile files and display their contents 68 | fix/makefiles: 69 | @find . -name "Makefile" -exec cat -e -t -v {} \; 70 | @find . -name "*.mk" -exec cat -e -t -v {} \; 71 | -------------------------------------------------------------------------------- /lib/make/make/test.mk: -------------------------------------------------------------------------------- 1 | # Ensures that a variable is defined and non-empty 2 | define assert-set 3 | @$(if $($(1)),,$(error $(1) not defined in $(@))) 4 | endef 5 | 6 | # Ensures that a variable is undefined 7 | define assert-unset 8 | @$(if $($1),$(error $(1) should not be defined in $(@)),) 9 | endef 10 | 11 | test/assert-set: 12 | $(call assert-set,PATH) 13 | @echo assert-set PASS 14 | 15 | test/assert-unset: 16 | $(call assert-unset,PATH) 17 | @echo assert-unset PASS 18 | 19 | test/assert: test/assert-set test/assert-unset 20 | @exit 0 21 | -------------------------------------------------------------------------------- /lib/make/nodejs.mk: -------------------------------------------------------------------------------- 1 | .PHONY: nodejs/install/v16 2 | ## Install NodeJS v16 3 | nodejs/install/v16: 4 | @curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh 5 | @sudo bash /tmp/nodesource_setup.sh 6 | @sudo apt-get update 7 | @sudo apt-get install --yes nodejs 8 | 9 | .PHONY: nodejs/install/v18 10 | ## Install NodeJS v18 11 | nodejs/install/v18: 12 | @curl -sL https://deb.nodesource.com/setup_18.x -o /tmp/nodesource_setup.sh 13 | @sudo bash /tmp/nodesource_setup.sh 14 | @sudo apt-get update 15 | @sudo apt-get install --yes nodejs 16 | 17 | .PHONY: nodejs/install/v20 18 | ## Install NodeJS v20 19 | nodejs/install/v20: 20 | @curl -sL https://deb.nodesource.com/setup_20.x -o /tmp/nodesource_setup.sh 21 | @sudo bash /tmp/nodesource_setup.sh 22 | @sudo apt-get update 23 | @sudo apt-get install --yes nodejs 24 | 25 | .PHONY: nodejs/install 26 | ## Install NodeJS 27 | nodejs/install: nodejs/install/v18 28 | 29 | .PHONY: nodejs/version 30 | ## Show NodeJS version 31 | nodejs/version: 32 | @node --version 33 | -------------------------------------------------------------------------------- /lib/make/npm.mk: -------------------------------------------------------------------------------- 1 | .PHONY: npm/install 2 | ## Install NPM 3 | npm/install: 4 | @sudo apt-get update 5 | @sudo apt-get install --yes npm 6 | 7 | .PHONY: npm/version 8 | ## Show NPM version 9 | npm/version: 10 | @npm --version 11 | 12 | .PHONY: npm/install-global 13 | # Set npm global for current user 14 | npm/install-global: 15 | mkdir -p ~/.npm-global 16 | npm config set prefix '~/.npm-global' 17 | 18 | .PHONY: npm/update-path 19 | npm/update-path: 20 | echo 'export PATH=~/.npm-global/bin:$$PATH' >> ~/.bashrc 21 | source ~/.bashrc 22 | 23 | .PHONY: npm/update 24 | ## Update packages to the latest version 25 | npm/update: 26 | npm update 27 | 28 | .PHONY: npm/outdated 29 | ## List outdated packages 30 | npm/outdated: 31 | npm outdated 32 | 33 | .PHONY: npm/audit 34 | ## Run security audit 35 | npm/audit: 36 | npm audit 37 | 38 | .PHONY: npm/clean-cache 39 | ## Clean npm cache 40 | npm/clean-cache: 41 | npm cache clean --force 42 | -------------------------------------------------------------------------------- /lib/make/nuke.mk: -------------------------------------------------------------------------------- 1 | .PHONY: nuke/install 2 | nuke/install: 3 | $(call assert-set,AWS_NUKE_VERSION) 4 | wget https://github.com/rebuy-de/aws-nuke/releases/download/$(AWS_NUKE_VERSION)/aws-nuke-$(AWS_NUKE_VERSION)-linux-amd64.tar.gz 5 | tar -xzf aws-nuke-$(AWS_NUKE_VERSION)-linux-amd64.tar.gz 6 | sudo mv aws-nuke-$(AWS_NUKE_VERSION)-linux-amd64 /usr/local/bin/aws-nuke 7 | rm -rf aws-nuke-$(AWS_NUKE_VERSION)-linux-amd64.tar.gz 8 | 9 | .PHONY: nuke/version 10 | nuke/version: 11 | aws-nuke version 12 | 13 | .PHONY: nuke/list-resource-types 14 | nuke/list-resource-types: 15 | aws-nuke resource-types 16 | 17 | .PHONY: nuke/run 18 | nuke/run: 19 | aws-nuke --config $(WORKSPACE)/packages/infra/nuke-config.yaml --no-dry-run --force --force-sleep 3 20 | 21 | .PHONY: nuke/dry-run 22 | nuke/dry-run: 23 | aws-nuke --config $(WORKSPACE)/packages/infra/nuke-config.yaml 24 | -------------------------------------------------------------------------------- /lib/make/nvm.mk: -------------------------------------------------------------------------------- 1 | NVM_VERSION ?= v0.39.3 2 | 3 | .PHONY: nvm/install 4 | ## Install nvm 5 | nvm/install: 6 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$(NVM_VERSION)/install.sh | bash 7 | 8 | .PHONY: nvm/use 9 | ## Use a specific Node.js version 10 | nvm/use: 11 | nvm use $(version) 12 | 13 | .PHONY: nvm/list-versions 14 | ## List installed Node.js versions 15 | nvm/list-versions: 16 | nvm ls 17 | -------------------------------------------------------------------------------- /lib/make/pnpm.mk: -------------------------------------------------------------------------------- 1 | .PHONY: pnpm/install 2 | ## Install a package with pnpm 3 | pnpm/install: 4 | sudo npm install -g pnpm 5 | 6 | .PHONY: pnpm/update 7 | ## Update packages to the latest version with pnpm 8 | pnpm/update: 9 | pnpm update 10 | 11 | .PHONY: pnpm/outdated 12 | ## List outdated packages with pnpm 13 | pnpm/outdated: 14 | pnpm outdated 15 | 16 | .PHONY: pnpm/audit 17 | ## Run security audit with pnpm 18 | pnpm/audit: 19 | pnpm audit 20 | 21 | .PHONY: pnpm/clean-cache 22 | ## Clean pnpm cache 23 | pnpm/clean-cache: 24 | pnpm store prune 25 | -------------------------------------------------------------------------------- /lib/make/pre-commit.mk: -------------------------------------------------------------------------------- 1 | .PHONY: pre-commit/install 2 | ## Install pre-commit using Pip3 3 | pre-commit/install: 4 | @pip3 install --progress-bar off --upgrade --user pre-commit 5 | 6 | .PHONY: pre-commit/hooks/install 7 | ## Install pre-commit hooks 8 | pre-commit/hooks/install: pre-commit/install 9 | @pre-commit install 10 | 11 | .PHONY: pre-commit/update 12 | ## Update pre-commit-config.yaml with the latest version 13 | pre-commit/update: 14 | @pre-commit autoupdate 15 | 16 | .PHONY: pre-commit/run 17 | ## Execute pre-commit hooks on all files 18 | pre-commit/run: 19 | @pre-commit run --all-files 20 | 21 | .PHONY: pre-commit/init 22 | ## Initialize .pre-commit-config.yaml to working directoy 23 | pre-commit/init: 24 | @cp $(HABITS)/files/pre-commit/.pre-commit-config.yaml ./ 25 | 26 | .PHONY: pre-commit/remove 27 | ## Remove .pre-commit-config.yaml 28 | pre-commit/remove: 29 | @rm $(WORKSPACE)/.pre-commit-config.yaml 30 | 31 | .PHONY: pre-commit/version 32 | ## Display pre-commit version 33 | pre-commit/version: 34 | echo "--- PRE-COMMIT ---" 35 | @pre-commit --version 36 | -------------------------------------------------------------------------------- /lib/make/prettier.mk: -------------------------------------------------------------------------------- 1 | .PHONY: prettier/install 2 | prettier/install: 3 | npm install -g prettier 4 | 5 | .PHONY: prettier/run 6 | prettier/run: 7 | prettier --write . 8 | 9 | .PHONY: prettier/check 10 | prettier/check: 11 | prettier --check . 12 | 13 | .PHONY: prettier/version 14 | prettier/version: 15 | prettier --version 16 | -------------------------------------------------------------------------------- /lib/make/python.mk: -------------------------------------------------------------------------------- 1 | .PHONY: python/install 2 | ## Install Python 3 3 | python/install: 4 | @sudo apt-get update 5 | @sudo apt-get install --yes python3 6 | 7 | .PHONY: python/pip/install 8 | ## Install Python 3 Pip 9 | python/pip/install: python/install 10 | @sudo apt-get install --yes python3-pip 11 | @pip install --upgrade pip 12 | 13 | .PHONY: python/virtualenv/install 14 | ## Install Python 3 virtualenv 15 | python/virtualenv/install: python/install python/pip/install 16 | @sudo apt-get install --yes python3-venv 17 | 18 | .PHONY: python/virtualenv/init 19 | ## Initialize a Python 3 virtualenv in the current directory 20 | python/virtualenv/init: 21 | ifeq ("$(wildcard .venv)", "") 22 | @python3 -m venv .venv 23 | else 24 | @echo "Skipping virtual environment creation since .venv directory already exists." 25 | endif 26 | 27 | .PHONY: python/virtualenv/remove 28 | ## Remove Python 3 virtualenv in the current directory 29 | python/virtualenv/remove: 30 | @rm -rf .venv 31 | 32 | .PHONY: python/version 33 | ## Display Python & Pip version 34 | python/version: 35 | @echo "--- PYTHON 3 ---" 36 | @python3 --version 37 | @echo "--- PIP ---" 38 | @pip --version 39 | @pip freeze 40 | -------------------------------------------------------------------------------- /lib/make/terraform-docs.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | TERRAFORM_DOCS_VERSION?=0.16.0 5 | 6 | .PHONY: terraform-docs/install 7 | ## Install terraform-docs 8 | terraform-docs/install: 9 | @mkdir -p /tmp/download /tmp/extract \ 10 | && wget https://github.com/terraform-docs/terraform-docs/releases/download/v$(TERRAFORM_DOCS_VERSION)/terraform-docs-v$(TERRAFORM_DOCS_VERSION)-linux-amd64.tar.gz -O /tmp/download/terraform-docs-$(TERRAFORM_DOCS_VERSION)-linux-amd64.tar.gz --quiet --no-check-certificate \ 11 | && tar -C /tmp/extract -xzf /tmp/download/terraform-docs-$(TERRAFORM_DOCS_VERSION)-linux-amd64.tar.gz \ 12 | && sudo mv /tmp/extract/terraform-docs /usr/local/bin/ \ 13 | && rm -rf /tmp/download /tmp/extract 14 | @echo "terraform-docs installed successfully!" 15 | @$(MAKE) --no-print-directory terraform-docs/version 16 | 17 | .PHONY: terraform-docs/build 18 | ## Build doc/terraform-docs.md with Terraform Docs 19 | terraform-docs/build: 20 | ifneq ($(wildcard *.tf),) 21 | @echo "# Terraform" > Terraform.md 22 | @terraform-docs markdown . >> Terraform.md 23 | endif 24 | 25 | .PHONY: terraform-docs/version 26 | ## Display Terraform Docs version 27 | terraform-docs/version: 28 | @echo "--- TERRAFORM DOCS ---" 29 | @terraform-docs --version 30 | -------------------------------------------------------------------------------- /lib/make/terraform.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | .PHONY: terraform/install 5 | ## Install Terraform latest version 6 | terraform/install: 7 | wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg >/dev/null 8 | echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(shell lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list 9 | sudo apt-get update && sudo apt-get -qq install --no-install-recommends --yes terraform terraform-ls 10 | @$(MAKE) --no-print-directory terraform/version 11 | 12 | .PHONY: terraform/init 13 | ## Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. 14 | terraform/init: tfswitch/run terraform/fmt tflint/run 15 | terraform init 16 | 17 | .PHONY: terraform/init/backend 18 | ## Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. 19 | terraform/init/backend: tfswitch/run terraform/fmt 20 | terraform init -backend-config="backend.hcl" 21 | 22 | .PHONY: terraform/fmt 23 | ## Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise. 24 | terraform/fmt: 25 | terraform fmt 26 | terraform fmt -check=true 27 | 28 | .PHONY: terraform/validate 29 | ## Validate the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc. 30 | terraform/validate: 31 | terraform validate 32 | 33 | .PHONY: terraform/plan 34 | ## Generates an execution plan for Terraform 35 | terraform/plan: tfswitch/run terraform/fmt terraform/validate 36 | terraform plan 37 | 38 | .PHONY: terraform/apply 39 | ## Builds or changes infrastructure according to Terraform configuration files in DIR 40 | terraform/apply: tfswitch/run terraform/fmt terraform/validate 41 | terraform apply -auto-approve 42 | 43 | .PHONY: terraform/destroy 44 | ## Destroy Terraform-managed infrastructure. 45 | terraform/destroy: tfswitch/run terraform/fmt terraform/validate 46 | terraform destroy -auto-approve 47 | 48 | .PHONY: terraform/clean 49 | ## Remove temporary files and directories 50 | terraform/clean: 51 | rm -rf .terraform 52 | rm -f .terraform.lock.hcl 53 | rm -f *.tfstate* 54 | rm -f *.tar.gz 55 | rm -f *.log 56 | 57 | .PHONY: terraform/version 58 | ## Display Terraform version 59 | terraform/version: 60 | @echo "--- TERRAFORM ---" 61 | @terraform --version 62 | 63 | .PHONY: terraform/pre-commit/init 64 | terraform/pre-commit/init: 65 | @cp $(HABITS)/files/terraform/.pre-commit-config.yaml ./ 66 | 67 | .PHONY: terraform/gitignore/init 68 | terraform/gitignore/init: GITIGNORE=macos,windows,linux,visualstudiocode,terraform 69 | terraform/gitignore/init: gitignore/install gitignore/init 70 | -------------------------------------------------------------------------------- /lib/make/terrascan.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | TERRASCAN_VERSION?=1.13.2 5 | 6 | .PHONY: terrascan/install 7 | ## Install terrascan 8 | terrascan/install: 9 | @mkdir -p /tmp/download /tmp/extract \ 10 | && wget https://github.com/accurics/terrascan/releases/download/v$(TERRASCAN_VERSION)/terrascan_$(TERRASCAN_VERSION)_Linux_x86_64.tar.gz -O /tmp/download/terrascan_$(TERRASCAN_VERSION)_Linux_x86_64.tar.gz --quiet --no-check-certificate \ 11 | && sha256sum /tmp/download/terrascan_$(TERRASCAN_VERSION)_Linux_x86_64.tar.gz \ 12 | && tar -C /tmp/extract -xzf /tmp/download/terrascan_$(TERRASCAN_VERSION)_Linux_x86_64.tar.gz \ 13 | && sudo mv /tmp/extract/terrascan /usr/local/bin/ \ 14 | && rm -rf /tmp/download /tmp/extract 15 | @echo "terrascan installed successfully!" 16 | @$(MAKE) --no-print-directory terrascan/version 17 | 18 | .PHONY: terrascan/run 19 | ## Run Terrascan 20 | terrascan/run: 21 | @terrascan scan 22 | 23 | .PHONY: terrascan/version 24 | ## Display Terrascan version 25 | terrascan/version: 26 | @echo "--- TERRASCAN ---" 27 | @terrascan version 28 | -------------------------------------------------------------------------------- /lib/make/tflint.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | TFLINT_AWS_RULESET_VERSION?=0.21.2 5 | 6 | .PHONY: tflint/install 7 | ## Install TFLINT 8 | tflint/install: 9 | @curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash 10 | @echo "tflint installed successfully!" 11 | @$(MAKE) --no-print-directory tflint/version 12 | 13 | .PHONY: tflint/init 14 | ## Init AWS TFLINT 15 | tflint/init: 16 | ifeq ($(wildcard $(WORKSPACE)/.tflint.hcl),) 17 | @cp $(HABITS)/files/terraform/.tflint.hcl $(WORKSPACE)/.tflint.hcl 18 | @sed -i "s,TFLINT_AWS_RULESET_VERSION,$(TFLINT_AWS_RULESET_VERSION),g" $(WORKSPACE)/.tflint.hcl 19 | @tflint --init 20 | endif 21 | 22 | .PHONY: tflint/init/force 23 | ## Init AWS TFLINT, overwrites the current configuration 24 | tflint/init/force: 25 | @cp $(HABITS)/files/terraform/.tflint.hcl $(WORKSPACE)/.tflint.hcl 26 | @sed -i "s,TFLINT_AWS_RULESET_VERSION,$(TFLINT_AWS_RULESET_VERSION),g" $(WORKSPACE)/.tflint.hcl 27 | @tflint --init 28 | 29 | .PHONY: tflint/run 30 | ## Run TFLINT 31 | tflint/run: 32 | @tflint 33 | 34 | .PHONY: tflint/version 35 | ## Display TFLINT version 36 | tflint/version: 37 | @echo "--- TFLINT ---" 38 | @tflint --version 39 | -------------------------------------------------------------------------------- /lib/make/tfsec.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | TFSEC_VERSION?=1.15.2 5 | 6 | .PHONY: tfsec/install 7 | ## Install TFSEC 8 | tfsec/install: 9 | @mkdir -p /tmp/download \ 10 | && wget https://github.com/aquasecurity/tfsec/releases/download/v$(TFSEC_VERSION)/tfsec-linux-amd64 -O /tmp/download/tfsec --quiet --no-check-certificate \ 11 | && chmod +x /tmp/download/tfsec \ 12 | && sudo mv /tmp/download/tfsec /usr/local/bin/ \ 13 | && rm -rf /tmp/download 14 | @echo "tfsec installed successfully!" 15 | @$(MAKE) --no-print-directory tfsec/version 16 | 17 | .PHONY: tfsec/run 18 | ## Run TFSEC 19 | tfsec/run: 20 | @tfsec . 21 | 22 | .PHONY: tfsec/version 23 | ## Display TFSEC version 24 | tfsec/version: 25 | @echo "--- TFSEC ---" 26 | @tfsec --version 27 | -------------------------------------------------------------------------------- /lib/make/tfswitch.mk: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | .PHONY: tfswitch/install 5 | ## Install tfswitch 6 | tfswitch/install: 7 | @curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | sudo bash 8 | @echo "tfswitch installed successfully!" 9 | @$(MAKE) --no-print-directory tfswitch/version 10 | 11 | 12 | .PHONY: tfswitch/run 13 | ## Execute tfswitch 14 | tfswitch/run: 15 | @tfswitch 16 | @terraform -version 17 | 18 | .PHONY: tfswitch/version 19 | ## Display tfswitch version 20 | tfswitch/version: 21 | @echo "--- TFSWITCH ---" 22 | @tfswitch --version 23 | -------------------------------------------------------------------------------- /lib/make/ubuntu.mk: -------------------------------------------------------------------------------- 1 | .PHONY: ubuntu/install 2 | ## Install most common packages 3 | ubuntu/install: ansible/playbooks/ubuntu/install 4 | 5 | .PHONY: ubuntu/update 6 | ## Update and upgrade Ubuntu packages 7 | ubuntu/update: ansible/playbooks/ubuntu/update 8 | 9 | .PHONY: ubuntu/version 10 | ubuntu/version: 11 | @lsb_release -a 12 | -------------------------------------------------------------------------------- /lib/scripts/banner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | clear && printf "\e[0;32mAWS AWS Code Habits: $(shell basename $(CURDIR))\e[0m\n" 4 | -------------------------------------------------------------------------------- /lib/scripts/gitignore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl -sL "https://www.toptal.com/developers/gitignore/api/$@" 4 | -------------------------------------------------------------------------------- /lib/scripts/post-start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o pipefail 3 | 4 | # HABITS:001:Default git branch should always be 'main' 5 | sudo su - vscode -c 'git config init.defaultBranch main' 6 | 7 | # HABITS:002:Squash commits on merge 8 | sudo su - vscode -c 'git config branch.main.mergeOptions "--squash"' 9 | -------------------------------------------------------------------------------- /lib/scripts/python/aws/sigv4-test.py: -------------------------------------------------------------------------------- 1 | """ 2 | The following example code establishes a secure connection to the specified OpenSearch Service 3 | domain and indexes a single document. 4 | """ 5 | 6 | import os 7 | from opensearchpy import OpenSearch, RequestsHttpConnection 8 | from requests_aws4auth import AWS4Auth 9 | import boto3 10 | 11 | HOST = "localhost" # Run aws/sso/login aws/ssm/port-forwarding 12 | REGION = "" 13 | SERVICE = "" 14 | 15 | profile_name=os.getenv('AWS_PROFILE') 16 | 17 | session = boto3.Session(profile_name=profile_name) 18 | client = session.client("sts") 19 | 20 | print(client.get_caller_identity()) 21 | 22 | credentials = session.get_credentials() 23 | awsauth = AWS4Auth( 24 | credentials.access_key, 25 | credentials.secret_key, 26 | REGION, 27 | SERVICE, 28 | session_token=credentials.token, 29 | ) 30 | 31 | search = OpenSearch( 32 | hosts=[{"host": HOST, "port": 9200}], 33 | http_auth=awsauth, 34 | use_ssl=True, 35 | verify_certs=False, 36 | ssl_assert_hostname=False, 37 | ssl_show_warn=False, 38 | connection_class=RequestsHttpConnection, 39 | ) 40 | 41 | # To display cluster's information 42 | print(search.info()) 43 | 44 | # To create an index 45 | # document = { 46 | # "title": "Moneyball", 47 | # "director": "Bennett Miller", 48 | # "year": "2011" 49 | # } 50 | # search.index(index="movies", id="5", body=document) 51 | 52 | # To get and print index 53 | # print(search.get(index="movies", id="5")) 54 | 55 | # To delete the index created above 56 | # print(search.delete(index="movies", id="5")) 57 | -------------------------------------------------------------------------------- /lib/scripts/python/aws/take-snapshot-opensearch.py: -------------------------------------------------------------------------------- 1 | import os 2 | import boto3 3 | import requests 4 | from requests_aws4auth import AWS4Auth 5 | 6 | host = '' # e.g. https://localhost:8080/ 7 | region = '' # e.g. us-west-1 8 | service = '' # es 9 | 10 | profile_name=os.getenv('AWS_PROFILE') 11 | credentials = boto3.Session(profile_name=profile_name).get_credentials() 12 | awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token) 13 | 14 | 15 | # Register repository 16 | 17 | bucket_name='' 18 | role_arn='' 19 | 20 | def register_repository(): 21 | path = f'_snapshot/{bucket_name}' # the OpenSearch API endpoint 22 | url = host + path 23 | 24 | payload = { 25 | "type": "s3", 26 | "settings": { 27 | "bucket": f'{bucket_name}', 28 | "region": f'{region}', 29 | "role_arn": f'{role_arn}' 30 | } 31 | } 32 | 33 | headers = {"Content-Type": "application/json"} 34 | 35 | r = requests.put(url, auth=awsauth, json=payload, headers=headers, verify=False) 36 | 37 | print(r.status_code) 38 | print(r.text) 39 | 40 | from datetime import datetime 41 | snapshot_name = datetime.today().strftime('%Y-%m-%d') 42 | 43 | # Take snapshot 44 | def take_snapshot(): 45 | path = f'_snapshot/{bucket_name}/{snapshot_name}' 46 | url = host + path 47 | 48 | r = requests.put(url, auth=awsauth, verify=False) 49 | print(r.text) 50 | 51 | # Restore snapshot (all indexes except Dashboards and fine-grained access control) 52 | def restore_snapshot(): 53 | path = f'_snapshot/{bucket_name}/{snapshot_name}/_restore' 54 | url = host + path 55 | 56 | payload = { 57 | "indices": "-.kibana*,-.opendistro_security", 58 | "include_global_state": False 59 | } 60 | 61 | headers = {"Content-Type": "application/json"} 62 | r = requests.post(url, auth=awsauth, json=payload, headers=headers, verify=False) 63 | print(r.text) 64 | 65 | def list_all_indices(): 66 | path = f'_cat/indices' 67 | url = host + path 68 | 69 | r = requests.get(url, auth=awsauth, verify=False) 70 | print(r.text) 71 | 72 | # register_repository() 73 | # take_snapshot() 74 | # restore_snapshot() 75 | list_all_indices() 76 | -------------------------------------------------------------------------------- /scripts/Makefile: -------------------------------------------------------------------------------- 1 | export WORKSPACE=$(shell pwd) 2 | export HABITS = $(WORKSPACE)/habits 3 | 4 | #include $(WORKSPACE)/tools.env # pin the version of your tools 5 | #include $(WORKSPACE)/dev.env # don't store secrets in git 6 | #include $(WORKSPACE)/dev.secrets.env # remember to add *.secrets.env to .gitignore 7 | 8 | include $(HABITS)/lib/make/Makefile 9 | include $(HABITS)/lib/make/*/Makefile 10 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | The following scripts can help you install, or initialize AWS Code Habits. 4 | 5 | ## 1. Remote (using Git Submodules, initialize all files) 6 | 7 | ```bash 8 | curl -sL https://raw.githubusercontent.com/awslabs/aws-code-habits/main/scripts/remote/init.sh | bash 9 | ``` 10 | 11 | ## 2. Remote (using Git Submodules, installation only) 12 | 13 | ```bash 14 | curl -sL https://raw.githubusercontent.com/awslabs/aws-code-habits/main/scripts/remote/install.sh | bash 15 | ``` 16 | 17 | ## 3. Standalone (without Git Submodules, initialize all files) 18 | If you are not a big fan of Git Submodule: 19 | 20 | ```bash 21 | curl -sL https://raw.githubusercontent.com/awslabs/aws-code-habits/main/scripts/standalone/init.sh | bash 22 | ``` 23 | 24 | ## 4. Standalone (without Git Submodules, installation only) 25 | If you are not a big fan of Git Submodule: 26 | 27 | ```bash 28 | curl -sL https://raw.githubusercontent.com/awslabs/aws-code-habits/main/scripts/standalone/install.sh | bash 29 | ``` -------------------------------------------------------------------------------- /scripts/remote/init.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -u 5 | set -o pipefail 6 | 7 | git submodule add --name habits -b main https://github.com/awslabs/aws-code-habits.git habits 8 | cp habits/scripts/Makefile Makefile 9 | make habits/install habits/init 10 | echo "AWS Code Habits installed successfully!" 11 | -------------------------------------------------------------------------------- /scripts/remote/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -u 5 | set -o pipefail 6 | 7 | git submodule add --name habits -b main https://github.com/awslabs/aws-code-habits.git habits 8 | cp habits/scripts/Makefile Makefile 9 | make habits/install 10 | echo "AWS Code Habits installed successfully!" 11 | -------------------------------------------------------------------------------- /scripts/standalone/init.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -u 5 | set -o pipefail 6 | 7 | git clone --branch=main --depth=1 https://github.com/awslabs/aws-code-habits.git habits 8 | rm -rf habits/.git 9 | cp habits/scripts/Makefile Makefile 10 | make habits/install habits/init 11 | echo 'habits/' >> .gitignore 12 | echo "AWS Code Habits installed successfully!" 13 | -------------------------------------------------------------------------------- /scripts/standalone/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -u 5 | set -o pipefail 6 | 7 | git clone --branch=main --depth=1 https://github.com/awslabs/aws-code-habits.git habits 8 | rm -rf habits/.git 9 | cp habits/scripts/Makefile Makefile 10 | make habits/install 11 | echo 'habits/' >> .gitignore 12 | echo "AWS Code Habits installed successfully!" 13 | -------------------------------------------------------------------------------- /tools.env: -------------------------------------------------------------------------------- 1 | AWS_NUKE_VERSION=v2.25.0 2 | GOMPLATE_VERSION=3.11.3 3 | TERRAFORM_DOCS_VERSION=0.16.0 4 | --------------------------------------------------------------------------------