hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Support for postBuild substitution in flux_configuration #24081

Open endakelly opened 11 months ago

endakelly commented 11 months ago

Is there an existing issue for this?

Community Note

Description

I would be great to have support to add postBuild substitutions in the azurerm_flux_configuration resource. Presently, this can be done using a patch request to the API but this is not ideal. The setting is also not yet exposed in the azure cli or azure portal.

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_flux_configuration#kustomizations

This is the api endpoint that can be used https://learn.microsoft.com/en-us/rest/api/kubernetesconfiguration/flux-configurations/update?view=rest-kubernetesconfiguration-2023-05-01&tabs=HTTP#kustomizationpatchdefinition

Here is an example request:

az rest --method patch --headers "{'Content-Type': 'application/json'}" --uri https://management.azure.com/subscriptions/<sub-id>/resourceGroups/<my-rg>/providers/Microsoft.ContainerService/managedClusters/<my-cluster>/providers/Microsoft.KubernetesConfiguration/fluxConfigurations/flux-system\?api-version\=2023-05-01 --body "{'properties':{'gitRepository':{'url':'https://github.com/my-flux-config.git','repositoryRef':{'branch':'my-branch'}},'kustomizations':{'flux-system':{'path':'./clusters/sbox/01','syncIntervalInSeconds':300,'postBuild':{'substitute':{'WI_NAME':'flux-system','ENVIRONMENT':'sbox','WI_ENVIRONMENT':'sbox','CLUSTER':'01','ISSUER_URL':'https://uksouth.oic.prod-aks.azure.com/<tenant-id>/<federated-credential-id>/','ENV_MONITOR_CHANNEL':'aks-monitor-sbox','KEYVAULT_ENVIRONMENT':'sbox'}}}}}}"

New or Affected Resource(s)/Data Source(s)

azurerm_kubernetes_flux_configuration

Potential Terraform Configuration

resource "azurerm_kubernetes_flux_configuration" "microsoft_flux_configuration" {
  name       = "flux-system"
  cluster_id = azurerm_kubernetes_cluster.kubernetes_cluster.id
  namespace  = "flux-system"

  git_repository {
    url             = "https://github.com/my-flux-config"
    reference_type  = "branch"
    reference_value = "my-branch"
  }

  kustomizations {
    name = "flux-system"
    path = "./clusters/${var.environment}/${var.cluster_number}"
    postBuild = {
     substitute = {
      WI_NAME: "flux-system"
      ENVIRONMENT: "sbox"
      WI_ENVIRONMENT: "sbox"
      CLUSTER: "01"
      ISSUER_URL: "https://uksouth.oic.prod-aks.azure.com/<tenant-id>/<federated-credential-id>/"
      ENV_MONITOR_CHANNEL: "aks-monitor-sbox"
      KEYVAULT_ENVIRONMENT: "sbox"
      }
    }
  }

  scope = "cluster"

  depends_on = [
    azurerm_kubernetes_cluster_extension.microsoft_flux_extension
  ]
}

References

No response

jayctran commented 6 months ago

Hi @rcskosir, is the pull request I provided to resolve this issue able to be reviewed please? Thanks