我正在嘗試使用 Terraform 在 Azure (AKS) 上配置一個 kubernetes 集群。配置作業得很好,但我無法將 kubeconfigkube_config_raw匯出到檔案。
下面是我的main.tf和outputs.tf。我壓制了resource_group和user_assigned_identity資源。
這是我用于創建配置的資源:
獎勵:是否可以將其直接匯出到現有的 ~/.kube/config 檔案中?像 az aks get-credentials 命令一樣嗎?
az aks get-credentials --resource-group myresourcegroup --name myCluster存盤組態檔的路徑:

將腳本保存在與 az 命令相同的路徑中的代碼:
resource "local_file" "kubeconfig" {
depends_on = [azurerm_kubernetes_cluster.aks]
filename = "C:/Users/user/.kube/config" this is where the config file gets stored
content = azurerm_kubernetes_cluster.aks.kube_config_raw
}
輸出:
現有組態檔在 /.kube/config

新檔案覆寫現有檔案:

注意:local_file在此處使用block 將完全覆寫檔案,而不是將背景關系附加到前一個檔案。如果您正在尋找像 az 命令那樣將內容合并到單個檔案中,那么它不可能從 terraform 中獲得。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/334199.html
