azapi_resource_action

This resource can perform resource action which gets information from an existing resource. It's recommended to use azapi_resource_action data source to perform readonly action, please use azapi_resource_action resource, if user wants to perform actions which change a resource's state.

Example Usage

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
  enable_hcl_output_for_data_source = true
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-rg"
  location = "west europe"
}

resource "azurerm_automation_account" "example" {
  name                = "example-account"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku_name            = "Basic"
}

data "azapi_resource_action" "example" {
  type                   = "Microsoft.Automation/automationAccounts@2021-06-22"
  resource_id            = azurerm_automation_account.example.id
  action                 = "listKeys"
  response_export_values = ["*"]
}

Here's an example to use the azapi_resource_action data source to get a provider's permissions.

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azurerm" {
  features {}
}

provider "azapi" {
  enable_hcl_output_for_data_source = true
}

data "azurerm_client_config" "current" {}

data "azapi_resource_action" "test" {
  type        = "Microsoft.Resources/providers@2021-04-01"
  resource_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/providers/Microsoft.Network"
  action      = "providerPermissions"
  method      = "GET"
}

Here's an example to use the azapi_resource_action data source to perform a provider action.

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
  enable_hcl_output_for_data_source = true
}

resource "azapi_resource_action" "test" {
  type        = "Microsoft.Cache@2023-04-01"
  resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Cache"
  action      = "CheckNameAvailability"
  body = {
    type = "Microsoft.Cache/Redis"
    name = "cacheName"
  }
}

Arguments Reference

The following arguments are supported:


{
  keys = [
    {
      KeyName = "Primary"
      Permissions = "Full"
      Value = "nHGYNd******i4wdug=="
    },
    {
      KeyName = "Secondary"
      Permissions = "Full"
      Value = "6yoCad******SLzKzg=="
    }
  ]
}

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

// it will output "nHGYNd******i4wdug=="
output "primary_key" {
  value = azapi_resource_action.test.output.keys.0.Value
}

// it will output "6yoCad******SLzKzg=="
output "secondary_key" {
  value = azapi_resource_action.test.output.keys.1.Value
}

Timeouts

The timeouts block allows you to specify timeouts for certain actions: