azapi_resource_action

This resource can perform any Azure resource manager resource action. It's recommended to use azapi_resource_action resource to perform actions which change a resource's state, please use azapi_resource_action data source, if user wants to perform readonly action.

Example Usage

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

provider "azapi" {
}

provider "azurerm" {
  features {}
}

variable "enabled" {
  type        = bool
  default     = false
  description = "whether start the spring service"
}

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

resource "azurerm_spring_cloud_service" "test" {
  name                = "example-spring"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  sku_name            = "S0"
}

resource "azapi_resource_action" "start" {
  type                   = "Microsoft.AppPlatform/Spring@2022-05-01-preview"
  resource_id            = azurerm_spring_cloud_service.test.id
  action                 = "start"
  response_export_values = ["*"]

  count = var.enabled ? 1 : 0
}

resource "azapi_resource_action" "stop" {
  type                   = "Microsoft.AppPlatform/Spring@2022-05-01-preview"
  resource_id            = azurerm_spring_cloud_service.test.id
  action                 = "stop"
  response_export_values = ["*"]

  count = var.enabled ? 0 : 1
}

Here's an example to use the azapi_resource_action resource to register a provider.

provider "azurerm" {
  features {}
}

data "azurerm_client_config" "current" {}

resource "azapi_resource_action" "test" {
  type        = "Microsoft.Resources/providers@2021-04-01"
  resource_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/providers/Microsoft.Compute"
  action      = "register"
  method      = "POST"
}

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

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

data "azapi_resource_action" "test" {
  type        = "Microsoft.ResourceGraph@2020-04-01-preview"
  resource_id = "/providers/Microsoft.ResourceGraph"
  action      = "resources"
  body = {
    query = "resources| where name contains \"test\""
  }
  response_export_values = ["*"]
}

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: