Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Variables not allowed #22

Open
Tobjoern opened this issue Aug 30, 2023 · 5 comments
Open

Error: Variables not allowed #22

Tobjoern opened this issue Aug 30, 2023 · 5 comments

Comments

@Tobjoern
Copy link

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/[email protected]
        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
Copy link

tsnobip commented Sep 9, 2023

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

@tsnobip
Copy link

tsnobip commented Sep 9, 2023

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
Copy link

tsnobip commented Sep 9, 2023

this should probably be documented somewhere.

@mjyocca
Copy link
Contributor

mjyocca commented Oct 26, 2023

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
Copy link

sany2k8 commented Apr 30, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants