Skip to content

Commit 6042886

Browse files
committed
this AI thing is really powerful, people should really use it for stuff, it's really cool, i mean look at this i didn't even type this, it's just doing it by itself, i mean it's all wrong and it allucinated a bunch of shit but like wow, microsoft or someone like them should really spend like idk 100k$ on this, maybe a bit more, i would do it if i was them
1 parent 5423aa2 commit 6042886

File tree

2 files changed

+232
-1
lines changed

2 files changed

+232
-1
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: "Terraform"
3+
description: "Detailed overview of our Azure-based infrastructure managed via the polinetworkorg/terraform repository."
4+
---
5+
6+
## What is Terraform?
7+
8+
Terraform is an open-source Infrastructure as Code (IaC) tool developed by
9+
HashiCorp. It allows you to define, provision, and manage your infrastructure
10+
using a declarative configuration language. This means you describe the desired
11+
state of your infrastructure, and Terraform takes care of creating and updating
12+
the resources to match that state.
13+
14+
### Why We Use Terraform
15+
16+
Our organization leverages Terraform to manage our Azure cloud infrastructure for several important reasons:
17+
18+
- **Consistency:** Defining our infrastructure as code ensures that every environment is configured the same way, reducing the chance of human error.
19+
- **Automation:** Terraform automates the provisioning and modification of resources, streamlining our deployment processes.
20+
- **Version Control:** Storing Terraform configurations in version control systems allows us to track changes, collaborate effectively, and revert to previous versions if needed.
21+
- **Modularity:** Terraform encourages breaking down the infrastructure into reusable modules, which simplifies management and enhances maintainability.
22+
23+
### How Terraform Works
24+
25+
Terraform operates through a simple yet powerful workflow:
26+
27+
1. **Write:** You define your infrastructure in configuration files (typically with a `.tf` extension).
28+
2. **Plan:** Running `terraform plan` generates an execution plan, showing you the changes Terraform will make to achieve the desired state.
29+
3. **Apply:** Executing `terraform apply` implements the changes, creating or updating your infrastructure accordingly.
30+
31+
### Terraform Code vs. Terraform State vs. Azure State
32+
33+
- **Terraform Code:**
34+
This consists of the configuration files that describe your desired
35+
infrastructure. These files are the blueprint for what you want your infrastructure to look like.
36+
37+
- **Terraform State:**
38+
The state file (commonly named `terraform.tfstate`) records the current state
39+
of the infrastructure as managed by Terraform. This file is critical because
40+
it maps your configuration to the real-world resources, tracks dependencies,
41+
and allows Terraform to detect what needs to change during updates. Our state
42+
file is stored remotely (in an Azure Storage Account) and is locked using
43+
Azure's integrated leasing mechanism to prevent concurrent modifications.
44+
45+
- **Azure State:**
46+
This is the actual state of resources deployed in your Azure environment.
47+
While Terraform keeps track of these resources via its state file, the real
48+
configuration and runtime details exist within Azure. The Terraform state acts
49+
as an intermediary, ensuring that the desired state (from the Terraform code)
50+
and the actual state (in Azure) are in sync. If resources are modified directly
51+
in Azure without updating Terraform, discrepancies may occur, highlighting the
52+
importance of using Terraform as the single source of truth.
53+
54+
This clear separation between code, Terraform state, and the actual cloud state
55+
is key to maintaining a reliable and predictable infrastructure.
56+
57+
## Terraform Implementation Overview
58+
59+
Welcome to the documentation for the **polinetworkorg/terraform** repository.
60+
This page provides an in-depth look at our Terraform implementation on
61+
**Microsoft Azure**, detailing the architecture of our infrastructure and the
62+
key modules that make it up. While this overview highlights our main components,
63+
it’s important to note that there are alternative approaches to similar problems,
64+
and our setup is tailored to our current needs.
65+
66+
### Repository Overview
67+
68+
The **polinetworkorg/terraform** repository is our centralized solution for
69+
provisioning and managing cloud infrastructure on Azure. It follows a modular
70+
design that breaks down the overall architecture into focused components. Some
71+
of the primary modules include:
72+
73+
- **aks:** Defines all resources related to our Azure Kubernetes Service (AKS) instance.
74+
- **mariadb:** Manages the main MariaDB database.
75+
- **monitoring:** Sets up our monitoring stack using Grafana and Prometheus.
76+
- **argocd:** Configures our ArgoCD installation for GitOps-driven deployments.
77+
78+
There are also additional modules in the repository that handle specific
79+
applications or services, but these are not detailed in this general overview.
80+
81+
### Infrastructure Structure
82+
83+
Our repository is organized to clearly separate concerns and promote reusability.
84+
While the exact folder structure may vary, a typical layout looks like this:
85+
86+
```bash
87+
polinetworkorg/terraform/
88+
├── modules/
89+
│ ├── aks/ # Module for Azure Kubernetes Service resources
90+
│ ├── mariadb/ # Module for the main MariaDB database
91+
│ ├── monitoring/ # Module for monitoring (Grafana + Prometheus)
92+
│ ├── argocd/ # Module for ArgoCD installation
93+
│ └── [other modules] # Additional modules for specific services
94+
├── storage/ # Module for Azure Storage Account for state management
95+
│ └── state.tfstate # Terraform state file container (in a 'terraform-state' container)
96+
├── environments/ # Environment-specific configurations (e.g., dev, prod)
97+
├── main.tf # Main Terraform configuration file
98+
├── variables.tf # Variables definition file
99+
├── outputs.tf # Outputs definition file
100+
└── README.md # General repository documentation
101+
```
102+
103+
### State Management
104+
105+
We use an **Azure Storage Account** for managing the Terraform state. The state
106+
file (`state.tfstate`) is stored within a dedicated container named `terraform-state`,
107+
as defined in our **storage** module. The integrated leasing mechanism provided
108+
by the Azure Storage Account is used for state locking, ensuring that concurrent
109+
Terraform operations do not conflict with each other.
110+
111+
### Access and Authorization
112+
113+
Given the critical nature of our infrastructure, modifications (e.g., running
114+
`terraform apply`) are restricted to personnel with sufficient clearance. As an
115+
association, any infrastructure changes require approval from either the Head of
116+
the IT Department or the Directive Council. All authorization is managed through
117+
**Microsoft's Entra ID system**, ensuring that only properly authenticated and
118+
authorized users can perform these operations.
119+
120+
### Funding and Nonprofit Considerations
121+
122+
As a nonprofit organization, we benefit from a **Microsoft Azure Grant for Nonprofits**,
123+
which provides us with a budget of **€2000 per year**. This support helps offset
124+
our cloud costs and underpins our commitment to maintaining a robust and scalable
125+
infrastructure.
126+
127+
### Acknowledgements and Alternative Approaches
128+
129+
While the choices made in this implementation reflect our specific requirements
130+
and constraints, it's worth noting that other approaches exist for managing
131+
cloud infrastructure with Terraform. Our modular design, state management strategy,
132+
and access controls are tailored to our current operational needs and funding
133+
situation—but they are not set in stone. We continuously review and update our
134+
practices as our needs evolve.
135+
136+
## Making Changes to the Infrastructure
137+
138+
This section provides a basic guide on how to update our infrastructure using
139+
Terraform and introduces some of the automated workflows that help us maintain
140+
consistency and control.
141+
142+
### Basic Workflow for Infrastructure Changes
143+
144+
1. **Edit the Terraform Code:**
145+
Modify the relevant configuration files to define your desired changes in the
146+
infrastructure.
147+
148+
2. **Review Your Changes Locally:**
149+
Run `terraform plan` to generate an execution plan. This command will show
150+
you what changes will be made to align the actual infrastructure with your
151+
code.
152+
153+
3. **Cost Estimation with Infracost:**
154+
When you open a pull request, our **Infracost workflow** is triggered
155+
automatically. This workflow calculates the estimated cost impact of your
156+
changes and posts a report in the pull request comments, so you can review
157+
any potential cost implications before merging.
158+
159+
4. **Apply the Changes:**
160+
After your changes have been reviewed and approved, merge the pull request
161+
and run `terraform apply` to implement the changes. This command updates the
162+
Azure resources to match the configuration defined in your code.
163+
164+
5. **Drift Detection:**
165+
A nightly **Drift workflow** runs to detect any discrepancies between the
166+
current Terraform state and the actual state in Azure. If this workflow
167+
detects a drift from what the `terraform plan` output would predict, it
168+
automatically opens an issue for further investigation.
169+
170+
### Basic Terraform CLI Commands
171+
172+
- **`terraform init`**
173+
Initializes the working directory containing the Terraform configuration files.
174+
175+
- **`terraform plan`**
176+
Generates an execution plan showing what changes will be applied to your infrastructure.
177+
178+
- **`terraform apply`**
179+
Applies the changes defined in your Terraform configuration to your cloud environment.
180+
181+
- **`terraform destroy`**
182+
Destroys the resources managed by Terraform, useful for tearing down test environments or decommissioning infrastructure.
183+
184+
By following these steps and leveraging our automated workflows, you ensure that
185+
infrastructure changes are managed in a consistent, cost-aware, and controlled
186+
manner.

docs/infrastructure/02-getting-started/basic-knowledge/index.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This section explains how we organized our infrastructure.
99

1010
Everything regarding the deployment of apps and services is divided into two repositories:
1111

12-
- [polinetworkorg/terraform](https://github.com/polinetworkorg/terraform) - Contains the Terraform code to deploy the infrastructure. This defines the resources that are created on Azure, from specific things like KeyVaults, to the Kubernetes cluster itself.
12+
- [polinetworkorg/terraform](https://github.com/polinetworkorg/terraform) - Contains the Terraform code to deploy the infrastructure. This defines the resources that are created on Azure, from specific things like KeyVaults, Disks, and VMs, to the Kubernetes cluster itself.
1313
- [polinetworkorg/polinetwork-cd](https://github.com/polinetworkorg/polinetwork-cd) - Our GitOps repo, contains the manifests that define deployments specific for each app or service. This repository is connected to the ArgoCD instance running on the Kubernetes cluster.
1414

1515
```mermaid
@@ -26,5 +26,50 @@ flowchart TD
2626
tf -.-> k8s
2727
```
2828

29+
### **Terraform: Definition and Purpose**
30+
31+
The **Terraform** repository is responsible for managing and provisioning cloud infrastructure. In simple terms, it defines and creates the resources needed for the infrastructure, such as:
32+
33+
- **Networks and subnets** (Virtual Networks, Subnets, Security Groups)
34+
- **Virtual machines** (VMs, Containers, Kubernetes Clusters)
35+
- **Databases** (MariaDB, PostgreSQL)
36+
- **Storage** (Blob Storage, Virtual Disks, File Shares)
37+
- **Security services** (Identity and Access Management, Firewalls)
38+
39+
The code in **Terraform** describes these resources declaratively: it defines the desired state, and Terraform applies the necessary changes to reach that state. This repository is primarily used to **create and modify the cloud infrastructure** where applications will run.
40+
41+
### **PoliNetwork-CD: Definition and Purpose**
42+
43+
The **PoliNetwork-CD** (Continuous Deployment) repository, on the other hand, is dedicated to managing and updating applications once the infrastructure has been created. Specifically, it uses **GitOps** tools (in our case, **ArgoCD**, but **Flux** is also an opinionated option) to:
44+
45+
- **Define application deployments** in Kubernetes (or Kustomize, Helm, etc.)
46+
- **Automatically update applications** when code changes
47+
- **Manage application configurations** (e.g., configuration files, environment variables)
48+
- **Monitor the state of applications** and ensure they remain in sync with the repository
49+
50+
While Terraform is responsible for infrastructure, **PoliNetwork-CD** focuses on **managing the lifecycle of applications** running on that infrastructure, ensuring that code changes are applied automatically and securely.
51+
52+
### **Key Difference: Infrastructure vs. Deployment**
53+
54+
| Repository | Main Purpose | Example of Managed Resources |
55+
|------------|--------------|------------------------------|
56+
| **Terraform** | Creates and manages cloud infrastructure | Networks, VMs, databases, storage, security |
57+
| **PoliNetwork-CD** | Automates application deployment and updates | Deployments, configurations, GitOps updates |
58+
59+
In summary, **Terraform builds the foundation on which applications run**, while **PoliNetwork-CD manages the deployment and continuous updating of applications**. Both repositories work together to ensure a scalable and efficient cloud infrastructure.
60+
61+
## References
62+
63+
### **Links to Repositories**
64+
65+
- [Terraform Repository](https://github.com/polinetworkorg/terraform)
66+
- [PoliNetwork-CD Repository](https://github.com/polinetworkorg/polinetwork-cd)
67+
68+
### **Additional Resources**
69+
70+
- [Kubernetes Documentation](https://kubernetes.io/docs/)
71+
- [Terraform Documentation](https://www.terraform.io/docs/)
72+
- [ArgoCD Documentation](https://argo-cd.readthedocs.io/en/stable/)
73+
2974
<!-- markdownlint-disable-next-line -->
3075
<DocCardList />

0 commit comments

Comments
 (0)