Is it already possible to use AzAPI in CDKTF?

Hi,
I’m currently providing Azure infrastructure with CDKTF (TypeScript or Java). I would like to create “Azure Container Apps”. It looks like that this is only possible using AzAPI. Is it possible to use the AzAPI in CDKTF projects? I wasn’t able to find any kind of documentation.

Thx! :coffee:

Hi @Aldjinn :wave:

Yes, you can use the AzAPI Terraform provider in CDKTF. We don’t have pre-built provider bindings for it, but you can generate the bindings locally (using cdktf get).

You can run cdktf provider add azure/azapi which will add and locally build the provider for you.

Best!
Ansgar

Thx @ansgarm. That did the trick. :+1:

Now I’m able to create AzAPI resources. Is there any convenient possibility to write the “body” in an easy way?

resource "azapi_resource" "aca_env" {
  type      = "Microsoft.App/managedEnvironments@2022-03-01"
  parent_id = azurerm_resource_group.rg.id
  location  = azurerm_resource_group.rg.location
  name      = "aca-env-terraform"
  tags      = local.tags
  
  body   = jsonencode({
    properties = {
      appLogsConfiguration = {
        destination               = "log-analytics"
        logAnalyticsConfiguration = {
          customerId = azurerm_log_analytics_workspace.law.workspace_id
          sharedKey  = azurerm_log_analytics_workspace.law.primary_shared_key
        }
      }
    }
 })
}

Source: How to Deploy Azure Container Apps with Terraform · Thorsten Hans' blog

Hi @Aldjinn,

that’s great!

You could to something like:

body: Fn.jsonencode({ properties: { appLogsConfiguration: { /* ... */ } }})

But I don’t think there are types for the inner configuration of body available for Java or TypeScript. But I have not done extensive research on whether they exist somewhere or could be generated based on something that exists.

curious, is it possible to use cdktf to generate this as ‘shared’ library such that it can be used with multiple resources im using cdktf to create?
right now what i do is generate it for one of the folders, and copy the source outside, adding that to my python path so it can be imported from any of the sub packages where im building resources.

Hi, I am using the same approach to generate the binding for azure/azapi and i am able to generate them but when i try to run cdktf deploy ,its failing saying it can not find the provider registry.terraform.io/hashicorp/azapi. i dont know why its looking at hashicorp/azapi even though the provider i added is Azure/azapi. anybody else facing same issue?