Home NewsX Announcing AzAPI 2.0 – Microsoft Community Hub

Announcing AzAPI 2.0 – Microsoft Community Hub

by info.odysseyx@gmail.com
0 comment 7 views


The AzAPI provider, designed to accelerate integration of HashiCorp Terraform with new Azure services, has now released 2.0. This updated version is an important step in our goal to provide launch-date support for Azure services using Terraform.

The AzAPI provider operates as a lightweight layer on top of the Azure ARM REST API. This is the best provider experience with the AzureRM provider. Azure resources that are not yet (or may not be) supported by AzureRM, including private and public preview services and features, can be accessed through this provider.

Key features of the AzAPI provider include:

  • Resource-specific versioningUsers can switch to a new API version without having to change their provider version.
  • special features Equivalent to `azapi_update_resource` and `azapi_resource_action`.
  • Immediate Day 0 support For new services.

Are you ready to see new updates? Let’s take a look!

All resource properties, outputs, and state representations are now handled in HashiCorp Configuration Language (HCL) instead of JSON. This change allows you to use all native Terraform HCL features. For more information about usage scenarios, Check out our first announcement.

The output can now be customized via the `response_export_values` property, which can act as a list or map.

For example, to export response values ​​to Azure Container Registry:

  • If you set the values ​​as a list (e.g. response_export_values ​​= `)[“properties.loginServer”, “properties.policies.quarantinePolicy.status”]` , you get the following output:
{
    properties = {
        loginServer = "registry1.azurecr.io"
        policies = {
            quarantinePolicy = {
                status = "disabled"
            }
        }
    }
}
  • Instead, if you set the values ​​to a map using JMES path queryi.e. response_export_values ​​= `{“login_server”: “properties.loginServer”, “quarantine_status”: “properties.policies.quarantinePolicy.status”}`, and you get output like this:
{
    "login_server" = "registry1.azurecr.io"
    "quarantine_status" = "disabled"
}

This feature uses key-value configuration, making it easier to specify exact output values. For example, you can set `{“login_server”: “properties.loginServer”, “quarantine_status”: “properties.policies.quarantinePolicy.status”}`.

User-defined retryable errors via retry blocks help providers handle expected errors. For example, if your resource may be experiencing creation timeout issues, the following code block may be helpful:

resource "azapi_resource" "example" {
    
    retry {
        interval_seconds     = 5
        randomization_factor = 0.5 
        multiplier           = 2 
        error_message_regex  = ["ResourceNotFound"]
    }
    timeouts {
        create = "10m"
}

Pre-execution validation enabled by feature flags provides a faster feedback loop by identifying errors without deploying resources. For example, in configurations with multiple resources, incorrect network addressPrefix definitions are quickly discovered.

provider "azapi" {
  enable_preflight = true
}
resource "azapi_resource" "vnet" {
  type      = "Microsoft.Network/virtualNetworks@2024-01-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "example-vnet"
  location  = "westus"
  body = {
    properties = {
      addressSpace = {
        addressPrefixes = [
          "10.0.0.0/160", 
        ]
      }
    }
  }
}

Customize the specific way you replace resources.

  • replace_trigger_external_value: Replaced when the specified external value changes.
  • Replace_Trigger_Reference: Trigger resource replacement based on changes in the specified path.

Use the new `azapi_resource_list` data source to retrieve resources from parent IDs such as subscriptions, virtual networks, or resource groups. You can also filter using query parameters as shown below.

data "azapi_client_config" "current" {}

data "azapi_resource_list" "listPolicyDefinitionsBySubscription" {
  type      = "Microsoft.Authorization/policyDefinitions@2021-06-01"
  parent_id = "/subscriptions/${data.azapi_client_config.current.subscription_id}"
  query_parameters = {
    "$filter" = ["policyType eq 'BuiltIn'"]
  }
  response_export_values = ["*"]
}

output "o1" {
  value = data.azapi_resource_list.listPolicyDefinitionsBySubscription.output
}

AzAPI now supports several Terraform provider features.

  • build_resource_id: Generates an Azure resource ID.
  • parsing_resource_id: Categorizes an Azure resource ID into its components.
  • subscription_resource_id: Generates an Azure subscription scoped resource ID.
  • Tenant_Resource_ID: Build an Azure tenant-scoped resource ID.
  • Management_Group_Resource_ID: Create an Azure management group scoped resource ID.
  • resource_group_resource_id: Configure the Azure resource group scoped resource ID.
  • extension_resource_id: Generates an Azure extended resource ID using an additional name.

For references and examples, visit: Terraform registry.

This release coincides with the VSCode extension update.

  • Code sample: Quickly insert code samples into automatically generated pipelines.

VSCode extension code sample.gif

  • Paste with AzAPI. Convert JSON or ARM templates directly to HCL:

Paste as AzAPI.gif

AzAPI 2.0 delivers a number of improvements, promising a better Terraform experience on Azure. With these features, we believe you can use AzAPI as a standalone provider to meet all your infrastructure needs. Stay tuned for a blog post suggesting when to use each provider. Be sure to check out our new features. We are sure you will enjoy it!

Check out your provider if you haven’t already. https://registry.terraform.io/providers/Azure/azapi/latest/docs





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX