AZURE HEROES
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Azure Heroes Sessions #9
    • Azure Heroes Sessions #10
    • Azure Heroes Sessions #11
    • Azure Heroes Sessions #12
    • Azure Heroes Sessions #13
    • Azure Heroes Sessions #14
    • Azure Heroes Sessions #15
    • Azure Heroes Sessions #16
    • Azure Heroes Sessions #17
    • Azure Heroes Sessions #18
  • Registration Form
  • Privacy Policy
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Azure Heroes Sessions #9
    • Azure Heroes Sessions #10
    • Azure Heroes Sessions #11
    • Azure Heroes Sessions #12
    • Azure Heroes Sessions #13
    • Azure Heroes Sessions #14
    • Azure Heroes Sessions #15
    • Azure Heroes Sessions #16
    • Azure Heroes Sessions #17
    • Azure Heroes Sessions #18
  • Registration Form
  • Privacy Policy

Navigating Azure Infrastructure with Terraform: AzureRM and AzAPI Providers

6/8/2024

0 Comments

 
Terraform, developed by HashiCorp, is a leading Infrastructure as Code (IaC) tool that enables developers to define and provision infrastructure using declarative configuration files. When working with Microsoft Azure, Terraform utilizes providers to interact with Azure's resources. Two primary providers facilitate this interaction: AzureRM and AzAPI. Understanding their differences and appropriate use cases is crucial for effective Azure infrastructure management.
Picture
AzureRM Provider
The Azure Resource Manager (AzureRM) provider is the traditional and widely adopted Terraform provider for Azure. It offers a comprehensive set of resources and data sources, allowing users to manage various Azure services. The AzureRM provider abstracts the underlying Azure REST APIs, providing a more user-friendly and Terraform-centric interface.
Key Features of AzureRM:
  • Mature and Stable: With extensive community support and regular updates, AzureRM is stable and reliable for production environments.
  • High-Level Abstractions: The provider simplifies complex Azure services into manageable Terraform resources, making it easier to define infrastructure.
  • Rich Documentation: Comprehensive documentation and examples are available, aiding users in implementing best practices.
AzAPI Provider
The Azure API (AzAPI) provider is a newer addition to the Terraform ecosystem. It offers a lower-level interface to Azure services by directly interacting with Azure's REST APIs. This provider is particularly useful for accessing Azure features and services that are not yet available in the AzureRM provider.
Key Features of AzAPI:
  • Direct API Access: AzAPI allows Terraform configurations to interact directly with Azure's REST APIs, enabling access to the latest Azure features without waiting for AzureRM updates.
  • Flexibility: Users can define resources and properties that may not yet be abstracted in higher-level providers like AzureRM.
  • Rapid Updates: As Azure introduces new services or features, AzAPI can be used to manage them immediately, providing agility in infrastructure management.
Choosing Between AzureRM and AzAPI
When deciding which provider to use, consider the following factors:
  • Maturity of Service: For well-established Azure services with stable APIs, AzureRM is typically sufficient and provides a more straightforward configuration experience.
  • Access to New Features: If you need to utilize the latest Azure features not yet supported by AzureRM, AzAPI offers a viable solution.
  • Complexity vs. Control: AzureRM's abstractions simplify configurations but may limit access to certain features. AzAPI provides granular control at the cost of increased complexity.

To illustrate the practical applications of the AzureRM and AzAPI providers in Terraform, let's explore examples of deploying an Azure Storage Account using each provider.
Example 1: Deploying an Azure Storage Account with the AzureRM Provider
The AzureRM provider offers a high-level abstraction for managing Azure resources, simplifying the deployment process. Here's how you can define a Storage Account using AzureRM:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_storage_account" "example" {
  name                     = "examplestorageacct"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}
In this configuration:
  • The azurerm provider is initialized with default features.
  • A Resource Group named example-resources is created in the "West Europe" region.
  • A Storage Account named examplestorageacct is provisioned within the Resource Group, utilizing Standard performance tier and Locally Redundant Storage (LRS) replication.
This example demonstrates the straightforward approach of the AzureRM provider in managing Azure resources.
Example 2: Deploying an Azure Storage Account with the AzAPI Provider
The AzAPI provider enables direct interaction with Azure's REST APIs, offering flexibility to manage resources not yet supported by AzureRM. Here's how you can define a Storage Account using AzAPI:

provider "azapi" {
  subscription_id = "<your-subscription-id>"
}

resource "azapi_resource" "example" {
  type      = "Microsoft.Storage/storageAccounts@2021-04-01"
  name      = "examplestorageacct"
  location  = "westeurope"
  parent_id = azapi_resource_group.example.id
  body      = jsonencode({
    sku: {
      name: "Standard_LRS"
    },
    kind: "StorageV2",
    properties: {}
  })
}

resource "azapi_resource_group" "example" {
  name     = "example-resources"
  location = "westeurope"
}
In this configuration:
  • The azapi provider is initialized with the specified Azure subscription ID.
  • A Resource Group named example-resources is created in the "westeurope" region.
  • A Storage Account named examplestorageacct is provisioned within the Resource Group. The resource type Microsoft.Storage/storageAccounts@2021-04-01 specifies the API version, and the body field defines the resource's properties in JSON format.
This example showcases the AzAPI provider's capability to manage Azure resources using direct API calls, providing access to the latest features and services.

Conclusion
Both AzureRM and AzAPI providers offer unique approaches to managing Azure infrastructure with Terraform. AzureRM provides a simplified and user-friendly interface for well-established services, while AzAPI offers granular control and immediate access to new Azure features. Choosing the appropriate provider depends on your project's requirements and the specific Azure services you intend to utilize.



0 Comments



Leave a Reply.

    Author

    Mohammad Al Rousan is a Microsoft MVP (Azure), Microsoft Certified Solution Expert (MCSE) in Cloud Platform & Azure DevOps & Infrastructure, An active community blogger and speaker. Al Rousan has over 11 years of professional experience in IT Infrastructure and very passionate about Microsoft technologies and products.

    Picture
    Picture
    Top 10 Microsoft Azure Blogs

    Archives

    January 2025
    December 2024
    November 2024
    October 2024
    September 2024
    July 2024
    June 2024
    May 2024
    April 2024
    February 2024
    September 2023
    August 2023
    May 2023
    November 2022
    October 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    May 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    June 2020
    April 2020
    January 2020
    July 2019
    June 2019
    May 2019
    February 2019
    January 2019

    Categories

    All
    AKS
    Azure
    Beginner
    CDN
    DevOps
    End Of Support
    Fundamentals
    Guide
    Hybrid
    License
    Migration
    Network
    Security
    SQL
    Storage
    Virtual Machines
    WAF

    RSS Feed

    Follow
    Free counters!
Powered by Create your own unique website with customizable templates.