diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index fa5209c8f0..2f5a3e8e6a 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the **Prowler SDK** are documented in this file. +## [v5.13.2] (Prowler UNRELEASED) + +### Fixed +- Check `check_name` has no `resource_name` error for GCP provider [(#9169)](https://github.com/prowler-cloud/prowler/pull/9169) + ## [v5.13.1] (Prowler v5.13.1) ### Fixed diff --git a/prowler/lib/check/models.py b/prowler/lib/check/models.py index 2398dc8267..37150f38db 100644 --- a/prowler/lib/check/models.py +++ b/prowler/lib/check/models.py @@ -588,8 +588,17 @@ class Check_Report_GCP(Check_Report): or getattr(resource, "name", None) or "" ) + + # Prefer the explicit resource_name argument, otherwise look for a name attribute on the resource + resource_name_candidate = resource_name or getattr(resource, "name", None) + if not resource_name_candidate and isinstance(resource, dict): + # Some callers pass a dict, so fall back to the dict entry if available + resource_name_candidate = resource.get("name") + if isinstance(resource_name_candidate, str): + # Trim whitespace so empty strings collapse to the default + resource_name_candidate = resource_name_candidate.strip() self.resource_name = ( - resource_name or getattr(resource, "name", "") or "GCP Project" + str(resource_name_candidate) if resource_name_candidate else "GCP Project" ) self.project_id = project_id or getattr(resource, "project_id", "") self.location = (