Azure / terraform-azurerm-lz-vending

Terraform module to deploy landing zone subscriptions (and much more) in Azure
https://registry.terraform.io/modules/Azure/lz-vending/azurerm
MIT License
169 stars 78 forks source link

feat: azapi v2 support #406

Open matt-FFFFFF opened 2 months ago

matt-FFFFFF commented 2 months ago

Update the module to take advantage of the many improvements in azapi v2

ekrof commented 2 weeks ago

This needs to be prioritized as you're using >=version constraints against the AzAPI provider, now officially released in v2.0.1. There's no upper bound version e.g.= ">= 1.4.0, < 2.0.0". Currently facing issues when deploying with this module:

╷
│ Error: Invalid body
│ 
│   with module.lz-vending.azapi_resource.telemetry_root,
│   on .terraform/modules/lz-vending/main.telemetry.tf line 3, in resource "azapi_resource" "telemetry_root":
│    3: resource "azapi_resource" "telemetry_root" {
│ 
│ The argument "body" is invalid: unmarshaling failed: value:
│ "{\"properties\":{\"mode\":\"Incremental\",\"template\":{\"$schema\":\"https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#\",\"contentVersion\":\"1.0.0.0\",\"outputs\":{\"telemetry\":{\"type\":\"String\",\"value\":\"For
│ more information, see
│ https://aka.ms/lz-vending/tf/telemetry\"}},\"parameters\":{},\"resources\":[],\"variables\":{}}}}",
│ err: json: cannot unmarshal string into Go value of type
│ map[string]interface {}
╵
╷
│ Error: Invalid Type
│ 
│   with module.lz-vending.azapi_resource.telemetry_root,
│   on .terraform/modules/lz-vending/main.telemetry.tf line 9, in resource "azapi_resource" "telemetry_root":
│    9:   body = jsonencode({
│   10:     properties = {
│   11:       mode     = "Incremental"
│   12:       template = local.telem_arm_subscription_template
│   13:     }
│   14:   })
│ 
│ The value must not be a string
╵
╷
│ Error: Invalid body
│ 
│   with module.lz-vending.module.resourcegroup_networkwatcherrg.azapi_resource.rg,
│   on .terraform/modules/lz-vending/modules/resourcegroup/main.tf line 1, in resource "azapi_resource" "rg":
│    1: resource "azapi_resource" "rg" {
│ 
│ The argument "body" is invalid: unmarshaling failed: value: "{}", err:
│ json: cannot unmarshal string into Go value of type map[string]interface {}
╵
╷
│ Error: Invalid body
│ 
│   with module.lz-vending.module.resourcegroup.azapi_resource.rg,
│   on .terraform/modules/lz-vending/modules/resourcegroup/main.tf line 1, in resource "azapi_resource" "rg":
│    1: resource "azapi_resource" "rg" {
│ 
│ The argument "body" is invalid: unmarshaling failed: value: "{}", err:
│ json: cannot unmarshal string into Go value of type map[string]interface {}
╵
╷
│ Error: Invalid Type
│ 
│   with module.lz-vending.module.resourcegroup_networkwatcherrg.azapi_resource.rg,
│   on .terraform/modules/lz-vending/modules/resourcegroup/main.tf line 6, in resource "azapi_resource" "rg":
│    6:   body      = jsonencode({})
│ 
│ The value must not be a string
╵
╷
│ Error: Invalid Type
│ 
│   with module.lz-vending.module.resourcegroup.azapi_resource.rg,
│   on .terraform/modules/lz-vending/modules/resourcegroup/main.tf line 6, in resource "azapi_resource" "rg":
│    6:   body      = jsonencode({})
│ 
│ The value must not be a string
╵
╷
│ Error: Invalid body
│ 
│   with module.lz-vending.module.usermanagedidentity.azapi_resource.umi,
│   on .terraform/modules/lz-vending/modules/usermanagedidentity/main.tf line 32, in resource "azapi_resource" "umi":
│   32: resource "azapi_resource" "umi" {
│ 
│ The argument "body" is invalid: unmarshaling failed: value: "{}", err:
│ json: cannot unmarshal string into Go value of type map[string]interface {}
╵
╷
│ Error: Invalid Type
│ 
│   with module.lz-vending.module.usermanagedidentity.azapi_resource.umi,
│   on .terraform/modules/lz-vending/modules/usermanagedidentity/main.tf line 36, in resource "azapi_resource" "umi":
│   36:   body      = jsonencode({})
│ 
│ The value must not be a string
╵
Error: Process completed with exit code 1.
matt-FFFFFF commented 2 weeks ago

Hi @ekrof

You can introduce your own constraints in your root module whilst we work on this

Also checking the lock file into source control can prevent provider upgrades.

ekrof commented 2 weeks ago

Hi @ekrof

You can introduce your own constraints in your root module whilst we work on this

Just realized after posting this. Thanks. The other AVM modules we use still haven't been updated to support Azurerm v4 either, so that's a shame.

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.0, < 5.0"
    }
    azapi = {
      source  = "azure/azapi"
      version = "~> 1"
    }
  }