backend_config read as file in apply
Problem description
When specifying the backend_config, I get errors about expecting a file. It should work but does not seem to align with according to how the documentation is.
https://github.com/dflook/terraform-github-actions/tree/main/terraform-apply#inputs
Terraform version
1.5.5
Backend
s3
Workflow YAML
name: CI
on:
push:
branches:
- master
jobs:
plan:
name: Apply to GKE
if: ${{ github.repository_owner == 'ExpidusOS' }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
region: [us-west1]
steps:
- uses: actions/checkout@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
with:
token_format: 'access_token'
workload_identity_provider: 'projects/769178210270/locations/global/workloadIdentityPools/ci-pool/providers/github'
service_account: '[email protected]'
- id: get-gke-credentials
uses: google-github-actions/[email protected]
with:
cluster_name: infra-${{ matrix.region }}
location: ${{ matrix.region }}
- name: Write variables
run: |
cat << EOF > terraform.tfvars
region = "${{ matrix.region }}"
aws_access_key_id = "${{ secrets.WASABI_ACCESS_KEY }}"
aws_secret_access_key = "${{ secrets.WASABI_SECRET_KEY }}"
EOF
- name: Apply
uses: dflook/[email protected]
with:
auto_approve: true
backend_config: |
bucket = "expidusos-ci"
key = "infra/${{ matrix.region }}/terraform.tfstate"
endpoint = "s3.us-west-1.wasabisys.com"
region = "us-west-1"
access_key = ${{ secrets.WASABI_ACCESS_KEY }}
secret_key = ${{ secrets.WASABI_SECRET_KEY }}
Workflow log
Installing Terraform
gpg: Signature made Tue Apr 19 07:39:49 2022 UTC
gpg: using RSA key 374EC75B485913604A831CC7C820C6D5CD27AB87
gpg: Good signature from "HashiCorp Security (hashicorp.com/security) <[email protected]>" [ultimate]
terraform_0.9.1_linux_amd64.zip: OK
gpg: Signature made Wed Aug 9 13:10:01 2023 UTC
gpg: using RSA key 374EC75B485913604A831CC7C820C6D5CD27AB87
gpg: Good signature from "HashiCorp Security (hashicorp.com/security) <[email protected]>" [ultimate]
terraform_1.5.5_linux_amd64.zip: OK
Terraform version not specified, using the latest version
Switched to Terraform v1.5.5
Detected s3 backend
Initializing Terraform
Initializing the backend...
╷
│ Error: Failed to read file
│
│ The file "bucket" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "\"expidusos-ci\"" could not be read.
╵
╷
│ Error: Failed to read file
│
│ The file "key" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "\"infra/us-west1/terraform.tfstate\"" could not be read.
╵
╷
│ Error: Failed to read file
│
│ The file "endpoint" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "\"s3.us-west-1.wasabisys.com\"" could not be read.
╵
╷
│ Error: Failed to read file
│
│ The file "region" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "\"us-west-1\"" could not be read.
╵
╷
│ Error: Failed to read file
│
│ The file "access_key" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "***" could not be read.
╵
╷
│ Error: Failed to read file
│
│ The file "secret_key" could not be read.
╵
╷
│ Error: Invalid backend configuration argument
│
│ The backend configuration argument "" given on the command line is not
│ expected for the selected backend type.
╵
╷
│ Error: Failed to read file
│
│ The file "***" could not be read.
╵
Encountering the same issue. @RossComputerGuy did you find a workaround?
Just a hunch, but are there spaces in the backend config? e.g.
backend_config: |
bucket = "my-config"
And does it work if the spaces are removed, like this:
backend_config: |
bucket="my-config"
I have tried that, it works. Thank you very much for helping out @dflook!
Would it be possible to add a note to the documentation that mentions that spaces and quotes should not be used? I encountered the same issue and @dflook suggestion helped. I realize that the current docs in fact do not have spaces or quotes but it wasn't immediately obvious that I should avoid including them.