Terraform Kubernetes提供程序在Github Action上失败,并显示以下内容:“config_path”引用的路径无效:“/github/主页/.kube/配置”

mklgxw1f  于 2023-02-18  发布在  Kubernetes
关注(0)|答案(1)|浏览(89)

我正在Minikube上尝试使用Terraform在Github Actions for Kubernetes部署中创建CI构建。Terraform应用在部署提供程序时失败,并显示以下消息:

Invalid attribute in provider configuration

  with provider["registry.terraform.io/hashicorp/kubernetes"],
  on providers.tf line 18, in provider "kubernetes":
  18: provider "kubernetes" {

'config_path' refers to an invalid path: "/github/home/.kube/config": stat
/github/home/.kube/config: no such file or directory

我该如何解决它呢?我尝试了各种方法,但到目前为止都不起作用。当我用Minikube在本地部署它时,一切都很好。
来自Terraform的相关代码片段:
variables.tf:

variable "kube_config" {
  type    = string
  default = "~/.kube/config"
}

providers.tf:

provider "kubernetes" {
  config_path    = pathexpand(var.kube_config)
  config_context = "minikube"
}

Github操作作业:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: setup minikube
      uses: manusa/actions-setup-minikube@v2.7.2
      with:
        minikube version: 'v1.28.0'
        kubernetes version: 'v1.25.4'
        github token: ${{ secrets.GITHUB_TOKEN }}
        driver: docker
        container runtime: docker

    - name: terraform-apply
      uses: dflook/terraform-apply@v1.29.1
      with:
          path: terraform-k8s
          auto_approve: true

我也试过用官方的setup-minikube操作来运行它,但是效果不太好。

xcitsw88

xcitsw881#

看来我已经设法使它的工作使用官方Hashicorp的行动,而不是原来的。要检查它是否部署一切在最后:)

- uses: hashicorp/setup-terraform@v2   
    - name: terraform-init
      run: terraform -chdir=terraform-k8s init
    - name: terraform-apply
      run: terraform -chdir=terraform-k8s apply -auto-approve

相关问题