hashicorp / tfc-workflows-github

HCP Terraform starter workflows and github actions to automate Terraform Cloud CI/CD pipelines.
Mozilla Public License 2.0
124 stars 20 forks source link

Error: Variables not allowed #22

Open Tobjoern opened 10 months ago

Tobjoern commented 10 months ago

I'm struggling to pass in a variable at runtime. I used the learn tfc tutorial to get a basic project going.

The projects works fine, when declaring variable in the interface, but it doesn't work at all, when trying to pass them in via en variables. I modified the 'main.tf' file:

variable "access_key" {
  description = "value of AWS access key"
  type = string
  default = null
}

variable "secret_key" {
  description = "value of AWS secret key"
  type = string
  default = null
}

provider "aws" {
  region = "us-west-2"
  access_key = var.access_key
  secret_key = var.secret_key
}

And try to run tf in an action:

      - name: Create Plan Run
        uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0
        id: plan-run
        with:
          workspace: ${{ env.TF_WORKSPACE }}
          configuration_version: ${{ steps.plan-upload.outputs.configuration_version_id }}
          plan_only: true
        env:
          TF_VAR_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          TF_VAR_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

However in the tfc console I receive the error:

2023-08-30T12:12:41.859Z [DEBUG] backend/local: Skipping interactive prompts for variables because input is disabled
╷
│ Error: Variables not allowed
│ 
│   on /home/tfc-agent/.tfc-agent/component/terraform/runs/run-uGHGZhRqc5VVoXhU/terraform.tfvars line 1:
│    1: access_key = xxx
│ 
│ Variables may not be used here.
╵
Operation failed: failed running terraform plan (exit 1)

Am I missing something?

tsnobip commented 9 months ago

I'm hitting the same issue, what are we missing?

tsnobip commented 9 months ago

OK in my case, the issue was coming from missing double quotes in the resulting string, thanks yaml for you sloppy string handling!

I had this:

env:
  TF_VAR_image_tag: "latest"

but I actually needed to do this:

env:
  TF_VAR_image_tag: '"latest"'
tsnobip commented 9 months ago

this should probably be documented somewhere.

mjyocca commented 8 months ago

Apologies for the confusion. We went ahead and pointed out this detail in the create-run action documentation.

Looking into how we can improve this experience in the future.

sany2k8 commented 2 months ago

Let's say I have hundrads of variables with their values in my env/dev.tfvars, and currently with terraform cli I am passing terraform plan -var-file="./env/dev.tfvars" how can I do with this action: https://github.com/hashicorp/tfc-workflows-github?