{"id":22229635,"url":"https://github.com/dsb-norge/terraform-template-project","last_synced_at":"2025-03-25T08:43:46.627Z","repository":{"id":100710282,"uuid":"486624489","full_name":"dsb-norge/terraform-template-project","owner":"dsb-norge","description":"Template project for terraform featuring scripted scaffolding and bootstrapping of remote state","archived":false,"fork":false,"pushed_at":"2024-12-13T14:11:32.000Z","size":75,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-19T13:46:47.084Z","etag":null,"topics":["dsb-template-repo"],"latest_commit_sha":null,"homepage":"https://www.dsb.no","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dsb-norge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-28T14:18:33.000Z","updated_at":"2024-12-13T14:11:35.000Z","dependencies_parsed_at":"2024-12-03T01:11:44.385Z","dependency_job_id":"2fde614c-4827-4c9a-b250-a9e21930d079","html_url":"https://github.com/dsb-norge/terraform-template-project","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsb-norge%2Fterraform-template-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsb-norge%2Fterraform-template-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsb-norge%2Fterraform-template-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsb-norge%2Fterraform-template-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsb-norge","download_url":"https://codeload.github.com/dsb-norge/terraform-template-project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245431708,"owners_count":20614182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsb-template-repo"],"created_at":"2024-12-03T01:11:41.437Z","updated_at":"2025-03-25T08:43:46.602Z","avatar_url":"https://github.com/dsb-norge.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- cSpell:ignore realpath chdir mapfile pushd popd apim strg terraformstate mktemp tflint --\u003e\n# terraform-template-project\n\nTemplate project for terraform featuring scripted scaffolding and bootstrapping of remote state.\n\nThis project simplifies multiple processes:\n\n1. Create scaffolding for a new terraform project, including config for multiple environments.\n2. Bootstrap terraform remote state in Azure for all environments.\n   - The remote state is handled in a separate \"environment\" called \"_terraform-state\", see `envs/_terraform-state/README.md` after scaffolding for more details.\n\n\u003c!-- omit in toc --\u003e\n## Table of Contents\n\n- [Prerequisites](#prerequisites)\n- [How to](#how-to)\n- [Resulting project structure](#resulting-project-structure)\n- [Maintainer documentation](#maintainer-documentation)\n\n## Prerequisites\n\nThe following tooling must be installed in order for scaffolding and bootstrapping to succeed:\n\n- jq - command-line JSON processor\n  - `sudo apt-get update \u0026\u0026 sudo apt-get install -y jq`\n- Azure CLI - \u003chttps://docs.microsoft.com/en-us/cli/azure/install-azure-cli\u003e\n- Terraform - \u003chttps://www.terraform.io/downloads\u003e\n\n## How to\n\nThis is how you scaffold and bootstrap this project into an empty terraform project:\n\n1. Log in to yor Azure tenant using `az login`\n2. From the root of the project run `step_1_scaffold.sh`\n   - Supply information about environments and Azure subscriptions as requested.\n   - The script will now generate a project structure for you based on the information given.\n3. After the script completes edit the `env.ENV.tfvars` files as stated by the script execution output.\n   - NOTE: the information you supply in the `env.ENV.tfvars` files are used for creating Azure resources for terraform state. The information is NOT used for creating project resources.\n     - TIP: you can have terraform state for multiple environments in the same Azure subscription, just specify the same subscription for all environments.\n4. From the root of the project run `step_2_bootstrap.sh`\n   - The script will now create all configuration and Azure resources necessary for you project to have remote terraform state in Azure (using the azurerm backend provider) for the specified environments.\n   - **NOTE:** the script WILL actually deploy resources to your Azure tenant as part of the bootstrapping project!\n   - The script will update the README files with example commands to use during project development and maintenance.\n     - TIP: The current contents of this file will be replaced.\n5. From the root of the project run `step_3_remove_init_scripts.sh`\n   - The script will remove all remaining files from the scaffolding and bootstrapping process.\n   - Update this README with relevant information, tip: search for TODO.\n\n## Resulting project structure\n\nExample of resulting project structure (scaffolded for environments `env1` and `env2`):\n\n```text\n.\n├── README.md\n├── envs\n│   ├── README.md\n│   ├── _terraform-state\n│   │   ├── README.md\n│   │   ├── backend-config.env1.hcl\n│   │   ├── backend-config.env2.hcl\n│   │   ├── backend.tf\n│   │   ├── env.env1.tfvars\n│   │   ├── env.env2.tfvars\n│   │   ├── main.tf\n│   │   ├── outputs.tf\n│   │   └── variables.tf\n│   ├── env1\n│   │   ├── .az-subscription\n│   │   ├── README.md\n│   │   ├── backend.tf\n│   │   ├── main.tf\n│   │   ├── outputs.tf\n│   │   ├── providers.tf\n│   │   ├── variables.tf\n│   │   └── versions.tf\n│   └── env2\n│       ├── .az-subscription\n│       ├── ...\n├── main\n│   ├── README.md\n│   ├── main.tf\n│   ├── outputs.tf\n│   ├── providers.tf\n│   └── variables.tf\n└── modules\n    └── README.md\n```\n\n## Maintainer documentation\n\nSome of the scripts supports a \"test mode\". Here is how to dry run the project:\n\n```bash\n#!/usr/bin/env bash\n\n# create a temporary directory and store its path in a variable\ntemp_dir=$(mktemp -d)\n\n# copy the contents of the current directory to the temporary directory\ncp -r . $temp_dir\n\n# change to the temporary directory\npushd $temp_dir\n\n# run step 1\n$(pwd)/step_1_scaffold.sh debug\n\n# read json\ncat bootstrap.json | jq\n\n# run step 2\n$(pwd)/step_2_bootstrap.sh debug\n\n# open temp project in vscode\ncode $temp_dir\n\n# change back to the original directory\npopd\n\n# remove the temporary directory\nrm -rf $temp_dir\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsb-norge%2Fterraform-template-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsb-norge%2Fterraform-template-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsb-norge%2Fterraform-template-project/lists"}