首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在github操作上使用terraform cloud和google provider时会出现错误

在github操作上使用terraform cloud和google provider时会出现错误
EN

Stack Overflow用户
提问于 2021-11-03 05:23:02
回答 1查看 314关注 0票数 0

我正在尝试在gcp中使用terraform cloud。为此,我有以下提供程序配置

代码语言:javascript
复制
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "3.89.0"
    }
  }
}

provider "google" {
  region  = local.region
  project = local.project
  credentials = 
}

按照https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#credentials-1,我已经创建了环境变量GOOGLE_CREDENTIALS并设置了下载的凭证文件。

现在,当我尝试使用github操作运行工作流时,我得到以下错误

这是我的gihub工作流文件的样子

代码语言:javascript
复制
name: 'event profile api deploy pipeline'

on:
  workflow_dispatch:
    branches:
    - main
  pull_request:

jobs:
  terraform:
    name: 'Terraform-deploy'
    runs-on: ubuntu-latest
    environment: dev

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
      run:
        shell: bash

    steps:
    # Checkout the repository to the GitHub Actions runner
    - name: Checkout
      uses: actions/checkout@v2

    # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
    - name: Setup Terraform
      uses: hashicorp/setup-terraform@v1
      with:
        cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

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

    # Checks that all Terraform configuration files adhere to a canonical format
    - name: Terraform Format
      working-directory: ./terraform
      run: terraform fmt -check

    # Generates an execution plan for Terraform
    - name: Terraform Plan
      working-directory: ./terraform
      run: terraform plan

你知道这里会出什么问题吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-04 22:05:38

弄清楚了,我没有在provider部分中使用backend部分。下面给出的是使用Terraform云的工作提供程序版本

代码语言:javascript
复制
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "3.89.0"
    }
  }
  backend "remote" {
    organization = "org"

    workspaces {
      name = "namespace"
    }
  }
}

provider "google" {
  region  = local.region
  project = local.project
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69820011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档