Jananath Banuka
Jananath Banuka

Reputation: 3923

Terraform self signed certificates for Azure APIM cannot find

I have some self signed certificates and I want to use it with the APIM management, developer and proxy domains as below:

But I am getting this error:

creating/updating API Management Service "jananath-apim" (Resource Group "apim-appGw-RG"): apimanagement.ServiceClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameters" Message="Invalid parameter: Invalid certificate associated with DeveloperPortal. Error Message: Cannot find the requested object.\r\n."

And here's my terraform code:

apim.tf

resource "azurerm_api_management" "example" {
  name                = "jananath-apim"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  publisher_name      = "Contoso"
  publisher_email     = "[email protected]"

  sku_name = "Developer_1"
  virtual_network_type = "Internal"
  
  virtual_network_configuration {
    subnet_id = azurerm_subnet.apimSubnet.id
  }

  hostname_configuration {

      management {
        host_name                    = var.managementHostname  
        certificate                  = base64encode("jananath-ssl.pfx")
        certificate_password         = var.managementCertPfxPassword       
      }

      developer_portal {
        host_name = var.portalHostname  
        certificate                  = base64encode("jananath-ssl.pfx")
        certificate_password         = var.portalCertPfxPassword    
      }

      proxy {
        host_name = var.gatewayHostname 
        certificate                  = base64encode("jananath-ssl.pfx")
        certificate_password         = var.gatewayCertPfxPassword       
      }
  }
}

And the jananath-ssl.pfx is in the same path as the apim.tf

What I am doing wrong? Can someone help me?

Upvotes: 1

Views: 474

Answers (1)

Marcin
Marcin

Reputation: 238537

base64encode just covers string to base64. It does not read the actual file. To read the file you would have to use:

base64encode(file("jananath-ssl.pfx"))

or filebase64:

filebase64("jananath-ssl.pfx")

Upvotes: 1

Related Questions