Skip to content

2025/06

Os presento inventariographdrawio: De vuestro Azure a un Diagrama, Automáticamente

¡Hola a todos! Como muchos profesionales que trabajáis día a día con la nube, seguro que os habéis enfrentado al mismo reto que yo una y otra vez: mantener una documentación visual de la infraestructura que sea fiel a la realidad. Dibujar diagramas a mano es tedioso y, peor aún, quedan obsoletos casi al instante.

Cansado de esta tarea manual y de la eterna duda de si un diagrama reflejaba o no el estado real de los recursos, decidí que tenía que haber una forma mejor de hacerlo.

Por eso, hoy quiero presentaros con mucha ilusión un proyecto personal en el que he estado trabajando: inventariographdrawio.

¿Qué es inventariographdrawio?

Es una herramienta de línea de comandos que he creado para solucionar este problema de raíz. Se conecta a una suscripción de Microsoft Azure, analiza los recursos que tienes desplegados y genera automáticamente un diagrama limpio y organizado en formato Draw.io (diagrams.net).

En pocas palabras, es mi solución para pasar de la infraestructura real en Azure a un diagrama editable, sin esfuerzo y en segundos.

¿Por qué lo creé? (Mis Objetivos Principales)

Cuando empecé a desarrollar esta herramienta, tenía varios objetivos en mente:

  1. Ahorrar tiempo: Mi primer objetivo era eliminar las horas que todos perdemos en tareas de documentación repetitivas. Quería que el análisis y el dibujo lo hiciera una máquina, para poder dedicar mi tiempo a lo que de verdad importa: diseñar y mejorar la arquitectura.
  2. Tener una fuente de la verdad: Necesitaba un diagrama en el que pudiera confiar. Con inventariographdrawio, el resultado es un reflejo exacto de lo que hay desplegado, perfecto para auditorías, revisiones o para explicarle la arquitectura a un nuevo compañero.
  3. Mejorar la visibilidad: A veces, en el portal de Azure es difícil ver el "big picture". Representar los recursos de forma gráfica me ayuda a entender las dependencias y la estructura general de un solo vistazo.
  4. Enfocarme en Azure: Decidí centrarme exclusivamente en Azure para poder ofrecer un buen nivel de detalle y precisión en los recursos y servicios específicos de la plataforma, que es donde trabajo principalmente.

¿Cómo podéis empezar a usarlo?

He intentado que sea lo más sencillo posible. Solo tenéis que seguir estos pasos:

  1. Clonar el repositorio:

    git clone https://github.com/rfernandezdo/inventariographdrawio.git
    cd inventariographdrawio
    
  2. Instalar las dependencias: La herramienta tiene unas pocas dependencias que podéis instalar fácilmente (revisad el fichero README.md para las instrucciones exactas).

  3. Configurar el acceso a Azure: Aseguraos de tener vuestra sesión de Azure activa (por ejemplo, con az login desde Azure CLI) para que la herramienta pueda autenticarse y leer los recursos.

  4. Ejecutar y ¡listo! Lanzad el script y veréis cómo aparece un nuevo fichero .drawio en la carpeta del proyecto, listo para abrir y editar.

Aquí un ejemplo navegable de un diagrama de Azure con iconos, creado con draw.io y exportado como un enlace para visualizarlo directamente en el navegador, es navegable:

Microsoft Entra Domain Services con Replica Set en una vpn Vnet2Vnet

El futuro

Este es solo el comienzo del proyecto. Mi idea es seguir ampliándolo para que sea compatible con más servicios de Azure y añadir nuevas funcionalidades que lo hagan aún más útil.

Al ser un proyecto de código abierto, cualquier ayuda es bienvenida. Si os animáis, podéis abrir issues con sugerencias o incluso enviar vuestros propios pull requests.

Espero de corazón que esta herramienta os resulte útil y os ahorre tanto tiempo como a mí.

¡Gracias por leer!

Streamline Your Workflow: Activate All Your PIM Roles with a Single Script Using the JAz.PIM Module

For professionals working with Azure, Privileged Identity Management (PIM) is a cornerstone of robust security hygiene. PIM enables just-in-time access to privileged roles, but manually activating multiple roles each morning can quickly become a repetitive and time-consuming task.

Fortunately, the PowerShell community provides powerful tools to automate such processes. This article introduces a script leveraging the JAz.PIM module, an excellent solution developed by Justin Grote, to simplify and accelerate role activation.

While the script is straightforward, its effectiveness is remarkable.

# Check if the JAz.PIM module is installed; if not, install it
if (-not (Get-module -ListAvailable -Name JAz.PIM)) {
    Install-Module -Name JAz.PIM -Force -Scope CurrentUser
}

# Import the JAz.PIM module if it is not already loaded in the session
if (-not (Get-module -Name JAz.PIM)) {
    Import-module JAz.PIM
}

# Verify Azure login status; if not logged in, initiate login
if (-not (Get-AzContext)) {
    Connect-AzAccount
}

# Set the default activation duration for roles to 8 hours
$PSDefaultParameterValues['Enable-JAz*Role:Hours'] = 8

# Retrieve and activate all eligible roles (Azure Resource and/or Azure AD roles)
Get-JAzRole | Enable-JAzRole -Justification "Administrative task"

This script ensures the JAz.PIM module is installed, connects to Azure if necessary, and activates all your eligible roles in a single command.

Key components: * Get-JAzRole: This cmdlet from the JAz.PIM module retrieves all roles for which you are eligible. * Enable-JAzRole: This command processes each role in the list, submitting an activation request with the specified justification.

Notably, JAz.PIM can manage both Azure Resource roles (Owner, Contributor, etc.) and Azure AD roles (Global Administrator, etc.).

Conclusion

Automation is essential for optimizing daily administrative tasks. This script, powered by the community-driven JAz.PIM module, exemplifies how a manual, repetitive process can be transformed into a quick and efficient command. Adopting such tools not only saves time but also helps maintain PIM security best practices with minimal friction.

If you found this article helpful, consider sharing it with your colleagues and continue exploring the capabilities of PowerShell and Azure. Your time is valuable—make every second count.

For more information about the JAz.PIM module, visit its GitHub repository.

How to set consistent naming in cloud with Azure Naming Tool and Terraform

Consistent naming across cloud resources is crucial for maintainability, clarity, and compliance. The Azure Naming Tool is a powerful tool that helps you define and enforce naming conventions for Azure resources. In this post, we will explore how to use the Azure Naming Tool in conjunction with Terraform to ensure consistent naming across your cloud infrastructure.

What is the Azure Naming Tool?

The Azure Naming Tool is an open-source project that provides a framework for defining and enforcing naming conventions for Azure resources. It allows you to create a set of rules that can be applied to various resource types, ensuring that all resources follow a consistent naming pattern. This is particularly useful in large organizations where multiple teams may be creating resources independently.

Really, the Azure Naming Tool is not only for Azure, it can be used for any cloud provider, as it is a generic tool that can be adapted to different environments if you define the rules correctly. You have the option Resource Type Editing documentation that allows you to define the rules for each resource type or create your own custom resource types, for AWS, GCP, or any other cloud provider.

Why Use Consistent Naming?

Consistent naming is essential for several reasons:

  • Clarity: Clear and consistent names make it easier to understand the purpose of each resource.
  • Maintainability: When resources are named consistently, it simplifies management and reduces the risk of errors.
  • Compliance: Many organizations have compliance requirements that mandate specific naming conventions for resources.
  • Automation: Consistent naming allows for easier automation and scripting, as you can predict resource names based on their types and roles.

What is the problem?

The problem with naming is the interfaces that we use to create resources, Azure Naming Tool portal is a great tool to define the rules, but it is not integrated with Terraform, so we need another way to apply the rules defined in the Azure Naming Tool to our Terraform code.

Solution

To solve the problem of integrating the Azure Naming Tool with Terraform, I created a Terraform module that allows you to use the naming rules defined in the Azure Naming Tool directly in your Terraform code. This module post a request to the Azure Naming Tool API to get the name of the resource based on the rules defined in the Azure Naming Tool.

This example shows how to use the module to create a resource group with a name generated by the Azure Naming Tool based on the rules defined in the Azure Naming Tool portal. The module uses the data.external and data.http resources to call the Azure Naming Tool API and get the name of the resource.

terraform apply -auto-approve
module.azurenamingtool.data.external.aad_token: Reading...
module.azurenamingtool.data.external.aad_token: Read complete after 0s [id=-]
module.azurenamingtool.data.http.name_generation_post: Reading...
module.azurenamingtool.data.http.name_generation_post: Read complete after 1s [id=https://azurenamingtool.azurewebsites.net/api/ResourceNamingRequests/RequestName]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.example will be created
  + resource "azurerm_resource_group" "example" {
      + id       = (known after apply)
      + location = "westeurope"
      + name     = "rg-spa-dev-auc-025"
      + tags     = {
          + "environment" = "example"
          + "project"     = "azurenamingtool"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + generated_name = "rg-spa-dev-auc-025"
azurerm_resource_group.example: Creating...
azurerm_resource_group.example: Still creating... [00m10s elapsed]
azurerm_resource_group.example: Creation complete after 16s [id=/subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/rg-spa-dev-auc-025]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

generated_name = "rg-spa-dev-auc-025"

You can check the module in the Terraform Registry.

Conclusion

Using the Azure Naming Tool in conjunction with Terraform allows you to enforce consistent naming conventions across your cloud resources. By integrating the Azure Naming Tool API into your Terraform workflows, you can automate the naming process and ensure that all resources follow the defined rules. This not only improves clarity and maintainability but also helps meet compliance requirements.

Enjoy the benefits of consistent naming in your cloud infrastructure with the Azure Naming Tool and Terraform!