首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用github操作平台部署GCP计算vm服务器

如何使用github操作平台部署GCP计算vm服务器
EN

Stack Overflow用户
提问于 2022-07-19 12:37:23
回答 1查看 188关注 0票数 0

使用Terraform工作流(而不是Terraform )来部署GCP计算引擎VM服务器的Github操作。我的工作流当前在Terraform格式处理中出错。如果我使用Terraform和/或直接在Google中部署,我知道的main.tf可以工作。

我的工作流错误:

The workflow.yaml

代码语言:javascript
复制
name: 'Terraform CI'

on:
  push:
    branches:
    - main
  pull_request:

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest

    # 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


    # 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
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

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

    # Generates an execution plan for Terraform
    - name: Terraform Plan
      run: terraform plan
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

      # On push to main, build or change infrastructure according to Terraform configuration files
      # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
    - name: Terraform Apply
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      run: terraform apply -auto-approve
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

最后我的main.tf

代码语言:javascript
复制
provider "google" {
  project = "test-project-1"
  region  = "us-west1"
  zone    = "us-west1-b"
}

resource "google_compute_instance" "default" {
  name         = "test-main-node"
  machine_type = "custom-4-8192"

  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-minimal-1804-lts"
      size = "10"
      type = "pd-ssd"
    }
  }

  network_interface {
    network = "default"
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-19 14:16:14

根据我的评论和Matt的解释,fmt选项可能有点违背直觉1

-check -检查输入是否已格式化。如果所有输入都被正确格式化,则退出状态为0,否则为非零。

为了避免这种情况,您应该在没有任何其他选项的情况下运行terraform fmt。您还可以在回购中引入预提交挂钩,这将执行Terraform代码的格式设置,这应该足以避免将来发生类似的错误。

1

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73037051

复制
相关文章

相似问题

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