首页 > 解决方案 > terraform 计划与 linode lke 一起挂在 github 操作上

问题描述

我正在尝试在 Github Actions 中使用 terraform 和 Linode 的 kubernetes 集群 (LKE),但是当我尝试运行planorapply命令时遇到了问题——它们只是挂起。我的猜测是,因为terraform init生成了terraform plan无法访问的输出。但我不确定如何使该结果可用于下一步。

我的 github 操作工作流文件如下所示:

init-terraform:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: 'some-branch'
      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          cli_config_credentials_token: ${{ secrets.TERRAFORM_API_TOKEN }}
      - name: Terraform Init
        run: terraform init

      - name: Terraform Plan
        run: terraform plan

      - name: Terraform Apply
        run: terraform apply -auto-approve

初始化似乎工作正常,但计划只是挂起。当我在本地运行它时,该计划大约需要 20 秒。

main.tf在 repo 中的文件如下所示:

terraform {
  required_providers {
    linode = {
      source  = "linode/linode"
      version = "=1.16.0"
    }
  }
}

provider "linode" {
}

resource "linode_lke_cluster" "lke_cluster" {
    label       = "my-label"
    k8s_version = "1.21"
    region      = "us-central"

    pool {
        type  = "g6-standard-2"
        count = 3
    }
}

我已将其设置TERRAFORM_API_TOKEN为 github 机密,并将其设置LINODE_TOKEN为 terraform 环境变量。

我错过了什么导致 terraform 调用挂起?

标签: kubernetesterraformgithub-actionslinode

解决方案


虽然,我不熟悉 linode 的提供者,但我有一种强烈的预感,你需要包括在内

        with:
          cli_config_credentials_token: ${{ secrets.TERRAFORM_API_TOKEN }}

在你的每一步。


推荐阅读