Azure-Samples/container-apps-azapi-terraform

Reference Azure Container Registry in AzApi template

Closed this issue · 0 comments

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

I am trying to deploy Container App with a container from a private registry with the terraform and AzAPI module. Decided to follow ARM template specification to pass credentials and server URI for ACR via AzAPI resource but it seems the module does not parse them at all.

Minimal steps to reproduce

Variable definition:

variable "container_apps" {
  description = "Specifies the container apps in the managed environment."
  type = list(object({
    name = string
    configuration = object({
      secrets = optional(list(object({
        name   = string
        value = string
      })))
      ingress = optional(object({
        external      = optional(bool)
        targetPort    = optional(number)
        allowInsecure = optional(bool)
        traffic = list(object({
          latestRevision = optional(bool)
          weight         = optional(number)
        }))
      }))
      registries = optional(list(object({
        server            = string
        username          = string
        passwordSecretRef = string
      })))
      dapr = optional(object({
        enabled     = optional(bool)
        appId       = optional(string)
        appProtocol = optional(string)
        appPort     = optional(number)
      }))
    })
    template = object({
......

tfvars file

container_apps = [{
  name = "my-container"
  configuration = {
    secrets = [
      {
        name  = "registrySecret"
        value = "value"
      }
    ]
    ingress = {
      external   = true
      targetPort = 8080,
      traffic = [{
        latestRevision = true
        weight         = 100
      }]
    }
    registries = [
      {
        server            = "myreg.azurecr.io"
        username          = "myuser"
        passwordSecretRef = "registrySecret"
      }
    ]
  }
  template = {
.....

with the following output without registries configuration:

Terraform will perform the following actions:

  # module.mymodule.azapi_resource.container_app["my-production"] will be created
  + resource "azapi_resource" "container_app" {
      + body                      = jsonencode(
            {
              + properties = {
                  + configuration        = {
                      + dapr    = null
                      + ingress = {
                          + allowInsecure = false
                          + external      = true
                          + targetPort    = 8080
                          + traffic       = [
                              + {
                                  + latestRevision = true
                                  + weight         = 100
                                },
                            ]
                        }
                    }
                  + managedEnvironmentId = "/subscriptions/id/resourceGroups/my-group/providers/Microsoft.App/managedEnvironments/managedEnvironment-my-production"
                  + template             = {
....

Expected/desired behavior

AzAPI module creates registry configuration inside ContainerApp.

OS and Version?

macOS Monterey

Versions

azurerm = 3.19.1
azapi = 0.5.0
terraform v1.2.7