https://github.com/pagopa/terraform-infrastructure-template
Terraform template repository for infrastructures projects
https://github.com/pagopa/terraform-infrastructure-template
infrastructure template
Last synced: 17 days ago
JSON representation
Terraform template repository for infrastructures projects
- Host: GitHub
- URL: https://github.com/pagopa/terraform-infrastructure-template
- Owner: pagopa
- Created: 2021-05-17T09:31:03.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-07T11:55:01.000Z (about 2 years ago)
- Last Synced: 2024-12-10T17:12:43.920Z (2 months ago)
- Topics: infrastructure, template
- Language: HCL
- Homepage:
- Size: 83 KB
- Stars: 6
- Watchers: 11
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# terraform-infrastructure-template
Terraform template repository for infrastructures projects
## How to use this template
### Change the template name
In this template we use `devopslab` or `dvopla` to define ours project, but you need to change all the information, to be complaint with your project
Inside:
* src\
* .env\
* terraform.tfvarsChange this informations
```ts
# general
env_short = "d"
env = "dev"
prefix = "dvopla"
location = "northeurope"
location_short = "neu"tags = {
CreatedBy = "Terraform"
Environment = "DEV"
Owner = "DevOps"
Source = "https://github.com/pagopa/devopslab-infra"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
}
```And change all the occurency of `devopslab` of his prefix with yours prefix.
In the folders core, pillar and k8s
Change the occurrence `devopslab` with the name of your project or the name that is better for you.
### Terraform folders name convention
Inside the folder src we have this folders, that contains the terraform files. Here you can find the meaning of the folders
* pillar: contains all the basic infrastructure that must be created before to support other layers, and cannot be destroyed every time.
* for example we can find the dns, vnet or monitoring
* core: here you can find all the business infrastructure objects, use data to load the objects created in pillar.
* k8s: here you can find the setup of your cluster k8s/aks
* for example ingress, secrets, rbac or service accounts## Requirements
### 1. terraform
In order to manage the suitable version of terraform it is strongly recommended to install the following tool:
* [tfenv](https://github.com/tfutils/tfenv): **Terraform** version manager inspired by rbenv.
Once these tools have been installed, install the terraform version shown in:
* .terraform-version
After installation install terraform:
```sh
tfenv install
```## Terraform modules
As PagoPA we build our standard Terraform modules, check available modules:
* [PagoPA Terraform modules](https://github.com/search?q=topic%3Aterraform-modules+org%3Apagopa&type=repositories)
## Apply changes
To apply changes follow the standard terraform lifecycle once the code in this repository has been changed:
```sh
terraform.sh init [dev|uat|prod]terraform.sh plan [dev|uat|prod]
terraform.sh apply [dev|uat|prod]
```## Terraform lock.hcl
We have both developers who work with your Terraform configuration on their Linux, macOS or Windows workstations and automated systems that apply the configuration while running on Linux.
So we need to specify this in terraform lock providers:
```sh
terraform initrm .terraform.lock.hcl
terraform providers lock \
-platform=windows_amd64 \
-platform=darwin_amd64 \
-platform=darwin_arm64 \
-platform=linux_amd64
```## Precommit checks
Check your code before commit.
```sh
pre-commit run -a
```Install the pre-commit hook globally
```sh
DIR=~/.git-template
git config --global init.templateDir ${DIR}
pre-commit init-templatedir -t pre-commit ${DIR}
```