Skip to content

Commit f16d6ac

Browse files
feat: PAYMCLOUD-231 argocd now use v4 module (#161)
* creazione modulo argocd * minor fix * update modulo * update versione * completed argocd module * completed argocd module * rollback * added tags configuration * updated terraform to version 1.12 * added module for argocd entra * added tags to argocd entra apps * added tags to argocd entra apps * reorder data * updated module and provider for azurerm v4 * changed module to version v4 * disabled velero * updated aks module to minor fix * argocd use remote model * aks: added missing properties * keda updated to 2.17.2 * pre-commit fixs * updated static analysis * removed temp module * Potential fix for code scanning alert no. 7: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 6: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * pre-commit fixs --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 7ecbb51 commit f16d6ac

32 files changed

+532
-528
lines changed
Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: Static Analysis
1+
name: 🔍 Static Analysis MA
2+
permissions:
3+
contents: read
24

35
on:
46
push:
@@ -7,10 +9,92 @@ on:
79

810
jobs:
911
static_analysis:
10-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-latest
13+
env:
14+
TF_PLUGIN_CACHE_DIR: /tmp/.terraform.d/plugin-cache
1115

1216
steps:
13-
- name: Static Analysis
14-
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@59c12b7a846423d62c27c9905686a7a1fd71c003 # v1.7.0
17+
- name: ⚡ Checkout code
18+
uses: actions/checkout@v4.1.1
19+
20+
- name: 📖 Read Terraform version
21+
run: |
22+
echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> $GITHUB_ENV
23+
24+
- name: 🔨 Setup Terraform
25+
uses: hashicorp/setup-terraform@v3.1.0
26+
with:
27+
terraform_version: "${{ env.TERRAFORM_VERSION }}"
28+
29+
- name: 💾 Cache Terraform plugins
30+
uses: actions/cache@v4
1531
with:
16-
precommit_version: 'v1.99.0@sha256:73239e93f97c005ed16189f3ca523f78d666af0902f3621a1eff8db22b7bb18c'
32+
path: $TF_PLUGIN_CACHE_DIR
33+
key: ${{ runner.os }}-terraform-${{ env.TERRAFORM_VERSION }}-${{ hashFiles('**/.terraform.lock.hcl') }}
34+
restore-keys: |
35+
${{ runner.os }}-terraform-${{ env.TERRAFORM_VERSION }}-
36+
${{ runner.os }}-terraform-
37+
38+
- name: 🔧 Setup Terraform plugin cache
39+
run: |
40+
mkdir -p $TF_PLUGIN_CACHE_DIR
41+
echo 'plugin_cache_dir = "/tmp/.terraform.d/plugin-cache"' > ~/.terraformrc
42+
43+
- name: 🏁 Init Terraform folders
44+
shell: bash
45+
run: |
46+
echo "📢 Show space"
47+
df -h
48+
49+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-"
50+
echo "+ 🏁 INIT TERRAFORM FOLDERS 🏁 +"
51+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n"
52+
53+
# Generate a unique list of folders containing `.tf` files, excluding the 90_aws folder
54+
FOLDERS=$(find . -type f -name "*.tf" ! -path "*/.terraform/*" ! -path "*/90_aws/*" -exec dirname {} \; | sort -u)
55+
echo "FOLDERS=${FOLDERS}"
56+
57+
for f in $FOLDERS; do
58+
echo -e "\n📂 Processing: ${f}"
59+
(
60+
cd "${f}" || exit
61+
# Check for any necessary changes to backend configurations
62+
if [[ -f "99_main.tf" ]]; then
63+
sed -i -e 's/ backend "azurerm" {}//g' 99_main.tf || true
64+
fi
65+
# Initialize Terraform and lock providers for all platforms
66+
terraform init -upgrade -lockfile=true &&
67+
terraform providers lock \
68+
-platform=darwin_arm64 \
69+
-platform=darwin_amd64 \
70+
-platform=linux_amd64 \
71+
-platform=linux_arm64
72+
) || echo "⚠️ Initialization failed for ${f}"
73+
done
74+
75+
- name: Show precommit version
76+
shell: bash
77+
run: |
78+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
79+
echo "+ 1️⃣ SHOW PRECOMMIT VERSION 1️⃣ +"
80+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
81+
82+
TAG=v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758
83+
docker run --rm --entrypoint cat ghcr.io/antonbabenko/pre-commit-terraform:$TAG /usr/bin/tools_versions_info
84+
85+
- name: 🚨 Run precommit
86+
shell: bash
87+
run: |
88+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
89+
echo "+- 🚨 PRECOMMIT TERRAFORM 🚨 -+"
90+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
91+
92+
TARGET_FILES=$(find . -type f -name "*.tf" ! -path "*/.terraform/*" ! -path "./src/90_aws/*")
93+
94+
TAG=v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758
95+
docker run \
96+
-v "$(pwd)":/lint \
97+
-v /tmp/.terraform.d/plugin-cache:/tmp/.terraform.d/plugin-cache \
98+
-w /lint \
99+
ghcr.io/antonbabenko/pre-commit-terraform:$TAG \
100+
run --files $TARGET_FILES --show-diff-on-failure
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: Static Analysis PR
1+
name: 🛃 Static Analysis PR
2+
permissions:
3+
contents: read
24

35
on:
46
push:
@@ -7,19 +9,31 @@ on:
79

810
jobs:
911
static_analysis:
10-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-latest
1113

1214
steps:
15+
- run: |
16+
rm -rf *
17+
1318
- name: 🔨 Get Modified Paths
1419
id: get-paths
15-
uses: pagopa/eng-github-actions-iac-template/global/get-modifed-folders@6cc78fc1c578c0fdfc8ba739bef634b21e8e35b4 # v1.19.0
20+
uses: pagopa/eng-github-actions-iac-template/global/get-modifed-folders@f10814b649ecd6e5d97c489084d2a107e2f1b2ee #v1.22.3
1621
with:
22+
ignore_patterns: ".github,.devops,.vscode,.terraform-version,90_aws"
1723
start_folder: "src"
18-
default_end_folder_depth: 3
19-
include_patterns: "src,domains"
24+
include_folders: "tag_config"
25+
include_patterns: "src"
26+
stopper_folders: "env,tests,api,api_product,helm,argocd,secrets"
27+
28+
- name: 👀 See folders downloaded
29+
if: env.dir_changes_detected == 'true'
30+
id: see
31+
shell: bash
32+
run: |
33+
tree -R -d -a .
2034
2135
- name: Static Analysis
2236
if: env.dir_changes_detected == 'true'
23-
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@6b8192a09750c44dde5a9a8d9ed72648547071c5 # v1.14.1
37+
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@159289e1e23d0783533d1dd83e1b7cf0a5a565d9 #v1.24.0
2438
with:
25-
precommit_version: 'v1.99.0@sha256:73239e93f97c005ed16189f3ca523f78d666af0902f3621a1eff8db22b7bb18c'
39+
precommit_version: 'v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758'

.terraform-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.10.5
1+
1.12.2

src/0_entra/01_tags.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module "tag_config" {
2+
source = "../tag_config"
3+
domain = var.domain
4+
environment = var.env
5+
}

src/0_entra/10_argocd_entra.tf

Lines changed: 17 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,18 @@
1-
# ⚠️
2-
# ⚠️ The grant admin for pagopa.it consent step must be performed manually in the Azure Portal after applying this configuration.
3-
# ⚠️ In App > API permissions > Microsoft Graph > User.Read > Grant admin consent for pagopa.it
4-
# ⚠️
5-
6-
# -----------------------------------------------------------------------------
7-
# Application Registration & Service Principal
8-
# -----------------------------------------------------------------------------
9-
10-
resource "azuread_application" "argocd" {
11-
display_name = "${var.prefix}-${var.env}-argocd"
12-
owners = data.azuread_users.argocd_application_owners.object_ids
13-
14-
web {
15-
redirect_uris = ["https://${local.argocd_hostname}/auth/callback"]
16-
logout_url = "https://${local.argocd_hostname}/logout"
17-
}
18-
19-
# This configures the "Mobile and desktop applications" platform in Entra ID.
20-
public_client {
21-
redirect_uris = ["http://localhost:8085/auth/callback"]
22-
}
23-
24-
group_membership_claims = [
25-
"ApplicationGroup"
26-
]
27-
28-
# MODIFICATION: Explicitly define ALL required delegated permissions for the OIDC flow.
29-
required_resource_access {
30-
resource_app_id = data.azuread_service_principal.graph.client_id
31-
32-
# Permission: User.Read
33-
resource_access {
34-
# Allows the app to sign in users and read their basic profile.
35-
id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" # User.Read
36-
type = "Scope"
37-
}
38-
}
39-
40-
optional_claims {
41-
id_token {
42-
name = "groups"
43-
essential = true
44-
source = null
45-
}
46-
}
47-
}
48-
49-
resource "azuread_service_principal" "sp_argocd" {
50-
client_id = azuread_application.argocd.client_id
51-
owners = data.azuread_users.argocd_application_owners.object_ids
52-
}
53-
54-
# -----------------------------------------------------------------------------
55-
# Permissions and Consent
56-
# -----------------------------------------------------------------------------
57-
58-
# The claim_values list must now match all the permissions defined above.
59-
resource "azuread_service_principal_delegated_permission_grant" "argocd_user_read_consent" {
60-
# The Object ID of the Service Principal receiving the grant.
61-
service_principal_object_id = azuread_service_principal.sp_argocd.object_id
62-
63-
# The Object ID of the API being granted access to (Microsoft Graph).
64-
resource_service_principal_object_id = data.azuread_service_principal.graph.object_id
65-
66-
# The list of permissions (scopes) to grant. Must match what was requested.
67-
claim_values = ["User.Read"]
68-
69-
# The Object ID of the user/principal granting the consent.
70-
user_object_id = data.azurerm_client_config.current.object_id
71-
}
72-
73-
# Assigns the specified Entra ID groups to the ArgoCD Enterprise Application.
74-
# This is required because 'group_membership_claims' is set to 'ApplicationGroup'.
75-
resource "azuread_app_role_assignment" "argocd_group_assignments" {
76-
for_each = data.azuread_group.argocd_groups
77-
78-
app_role_id = "00000000-0000-0000-0000-000000000000"
79-
principal_object_id = each.value.object_id
80-
resource_object_id = azuread_service_principal.sp_argocd.object_id
81-
}
82-
83-
# -----------------------------------------------------------------------------
84-
# Workload Identity Federation
85-
# -----------------------------------------------------------------------------
86-
87-
resource "azuread_application_federated_identity_credential" "argocd" {
88-
application_id = azuread_application.argocd.id
89-
display_name = "${local.project}-argocd-server-federated-credential"
90-
description = "Federated credential for the ArgoCD server service account"
91-
audiences = ["api://AzureADTokenExchange"]
92-
issuer = data.azurerm_kubernetes_cluster.aks.oidc_issuer_url
93-
subject = "system:serviceaccount:${local.argocd_namespace}:${local.argocd_service_account_name}"
94-
}
95-
96-
# -----------------------------------------------------------------------------
97-
# Key Vault Secrets
98-
# -----------------------------------------------------------------------------
99-
100-
resource "azurerm_key_vault_secret" "argocd_entra_app_client_id" {
101-
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
102-
name = "argocd-entra-app-workload-client-id"
103-
value = azuread_application.argocd.client_id
104-
}
105-
106-
resource "azurerm_key_vault_secret" "argocd_entra_app_service_account_name" {
107-
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
108-
name = "argocd-entra-app-workload-service-account-name"
109-
value = local.argocd_service_account_name
1+
// ⚠️ Manual step required after apply:
2+
// App > API permissions > Microsoft Graph > User.Read > Grant admin consent
3+
4+
module "argocd_entra" {
5+
source = "git::https://github.com/pagopa/terraform-azurerm-v4.git//kubernetes_argocd_entra?ref=PAYMCLOUD-231-argocd-creazione-modulo"
6+
7+
name_identifier = local.project
8+
argocd_hostname = local.argocd_hostname
9+
entra_app_owners_object_ids = data.azuread_users.argocd_application_owners.object_ids
10+
entra_group_display_names = var.argocd_entra_groups_allowed
11+
aks_name = local.kubernetes_cluster_name
12+
aks_resource_group_name = local.kubernetes_cluster_resource_group_name
13+
argocd_namespace = local.argocd_namespace
14+
argocd_service_account_name = local.argocd_service_account_name
15+
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
16+
17+
tags = module.tag_config.tags
11018
}

src/0_entra/99_main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ terraform {
33
required_providers {
44
azuread = {
55
source = "hashicorp/azuread"
6-
version = "<= 3.4.0"
6+
version = "~> 3"
77
}
88
azurerm = {
99
source = "hashicorp/azurerm"
10-
version = "<= 4.38.0"
10+
version = "~> 4"
1111
}
1212
}
1313

src/0_entra/99_variables.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ variable "lock_enable" {
5858
description = "Apply locks to block accedentaly deletions."
5959
}
6060

61-
variable "tags" {
62-
type = map(any)
63-
default = {
64-
CreatedBy = "Terraform"
65-
}
66-
}
67-
6861
# Definizione della variabile per i nomi dei gruppi Entra ID
6962
variable "argocd_entra_groups_allowed" {
7063
type = list(string)

src/0_entra/README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,20 @@ Re-enable all the resource, commented before to complete the procedure
2929
| Name | Version |
3030
|------|---------|
3131
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.8.0 |
32-
| <a name="requirement_azuread"></a> [azuread](#requirement\_azuread) | <= 3.4.0 |
33-
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | <= 4.38.0 |
32+
| <a name="requirement_azuread"></a> [azuread](#requirement\_azuread) | ~> 3 |
33+
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~> 4 |
3434

3535
## Modules
3636

37-
No modules.
37+
| Name | Source | Version |
38+
|------|--------|---------|
39+
| <a name="module_argocd_entra"></a> [argocd\_entra](#module\_argocd\_entra) | git::https://github.com/pagopa/terraform-azurerm-v4.git//kubernetes_argocd_entra | PAYMCLOUD-231-argocd-creazione-modulo |
40+
| <a name="module_tag_config"></a> [tag\_config](#module\_tag\_config) | ../tag_config | n/a |
3841

3942
## Resources
4043

4144
| Name | Type |
4245
|------|------|
43-
| [azuread_app_role_assignment.argocd_group_assignments](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
44-
| [azuread_application.argocd](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application) | resource |
45-
| [azuread_application_federated_identity_credential.argocd](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential) | resource |
46-
| [azuread_service_principal.sp_argocd](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal) | resource |
47-
| [azuread_service_principal_delegated_permission_grant.argocd_user_read_consent](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal_delegated_permission_grant) | resource |
48-
| [azurerm_key_vault_secret.argocd_entra_app_client_id](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
49-
| [azurerm_key_vault_secret.argocd_entra_app_service_account_name](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
5046
| [azuread_group.argocd_groups](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/group) | data source |
5147
| [azuread_service_principal.graph](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/service_principal) | data source |
5248
| [azuread_users.argocd_application_owners](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/users) | data source |
@@ -68,7 +64,6 @@ No modules.
6864
| <a name="input_location_westeurope"></a> [location\_westeurope](#input\_location\_westeurope) | n/a | `string` | n/a | yes |
6965
| <a name="input_lock_enable"></a> [lock\_enable](#input\_lock\_enable) | Apply locks to block accedentaly deletions. | `bool` | `false` | no |
7066
| <a name="input_prefix"></a> [prefix](#input\_prefix) | n/a | `string` | `"cstar"` | no |
71-
| <a name="input_tags"></a> [tags](#input\_tags) | n/a | `map(any)` | <pre>{<br/> "CreatedBy": "Terraform"<br/>}</pre> | no |
7267

7368
## Outputs
7469

src/0_entra/env/itn-dev/terraform.tfvars

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,4 @@ location = "italynorth"
77
location_short = "itn"
88
location_westeurope = "westeurope"
99

10-
tags = {
11-
CreatedBy = "Terraform"
12-
Environment = "Dev"
13-
Owner = "DevOps"
14-
Source = "https://github.com/pagopa/devopslab-infra"
15-
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
16-
}
17-
18-
1910
argocd_entra_groups_allowed = ["dvopla-d-adgroup-admin", "dvopla-d-adgroup-developers", "dvopla-d-adgroup-externals"]

0 commit comments

Comments
 (0)