【发布时间】:2021-05-05 15:54:32
【问题描述】:
我有一个 Makefile 来编译 Terraform 代码。当我在本地运行Makefile up 时,一切正常。
生成文件
BACKEND_CONFIG = -backend-config=resource_group_name=${AZURE_TERRAFORM_RESOURCE_GROUP_NAME} \
-backend-config=storage_account_name=${AZURE_TERRAFORM_STORAGE_ACCOUNT_NAME} \
-backend-config=container_name=${AZURE_TERRAFORM_STORAGE_CONTAINER_NAME} \
-backend-config=key=${AZURE_TERRAFORM_RESOURCE_GROUP_NAME}.tfstate \
VARIABLES = -var=path=${PWD}/config/resource-groups \
all:
up: init plan apply
down: init destroy
init:
terraform init -reconfigure ${BACKEND_CONFIG} src
plan:
terraform plan ${VARIABLES} -out="plan.out" src
apply:
terraform apply plan.out
destroy:
terraform destroy ${VARIABLES} src
.PHONY = all init plan apply destroy up down import az_up az_down
我现在要做的是在我发出推送请求时运行Makefile up。我在 Github secrets 中添加了我所有的秘密并创建了一个 Github 操作。
terraform.yml
on:
push:
branches:
- dev
pull_request:
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
environment: production
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: build application
run: make up
working-directory: ./infra_as_code
Makefile(新)
BACKEND_CONFIG = -backend-config=resource_group_name=${{ secrets.AZURE_TERRAFORM_RESOURCE_GROUP_NAME }} \
-backend-config=storage_account_name=${{ secrets.AZURE_TERRAFORM_STORAGE_ACCOUNT_NAME }} \
-backend-config=container_name=${{ secrets.AZURE_TERRAFORM_STORAGE_CONTAINER_NAME }} \
-backend-config=key=${{ secrets.AZURE_TERRAFORM_RESOURCE_GROUP_NAME }}.tfstate \
VARIABLES = -var=path=${PWD}/config/resource-groups \
all:
up: init plan apply
down: init destroy
init:
terraform init -reconfigure ${BACKEND_CONFIG} src
plan:
terraform plan ${VARIABLES} -out="plan.out" src
apply:
terraform apply plan.out
destroy:
terraform destroy ${VARIABLES} src
.PHONY = all init plan apply destroy up down import az_up az_down
我在 Github Actions 中遇到的错误:
Run make up
make up
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
terraform init -reconfigure -backend-config=resource_group_name=} -backend-config=storage_account_name=} -backend-config=container_name=} -backend-config=key=}.tfstate src
Too many command line arguments. Did you mean to use -chdir?
make: *** [Makefile:15: init] Error 1
Error: Process completed with exit code 2.
【问题讨论】:
标签: makefile terraform github-actions