Terraform init 报告无法通过 Github Actions 查询提供程序包

时间:2021-06-09 20:45:00

标签: terraform github-actions terraform-provider-gcp

不知道发生了什么,需要你的帮助。它可以在本地运行,但通过管道,我在检索提供程序包时不断遇到问题。

我的github配置:

- name: Setup Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          terraform_version: 0.15.5
          cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

      # Write the gcp credentials to a temp file
      - name: Setup Creds
        run: |-
            echo ${GCP_CREDS} > gcp_key.json
            cat gcp_key.json
        env: 
            GCP_CREDS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DEFAULT }}

      # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
      - name: Terraform Init
        run: terraform init

我的提供者如下所示:

terraform {
  required_version = ">= 0.15"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "3.71.0"
    }

    google-beta = {
      source  = "hashicorp/google-beta"
      version = "3.71.0"
    }
  }
}

而且我不断遇到以下问题:

enter image description here

1 个答案:

答案 0 :(得分:1)

如评论中所述,您的模块具有冲突的版本约束。

错误信息显示:

Could not retrieve the list of available versions for provider hashicorp/google: no available releases match the given constraints >= 2.12.0, ~> 3.45, ~> 3.53, 3.55.0, 3.71.0, <4.0.0

因此,您在 Google 提供程序上设置了以下每个 version constraints 的模块:

  • >= 2.12.0
  • ~> 3.45
  • ~> 3.53
  • 3.55.0
  • 3.71.0
  • <4.0.0

这里出现冲突是因为您对 3.55.03.71.0 都有特定的版本限制,无法解决。

您需要放松对其中之一的限制,以允许 Terraform 能够下载适当的提供程序版本。