baynezy
baynezy

Reputation: 7036

Trouble passing variable in terraform apply

I am using Terraform Cloud for my Backend with version 1.1

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
  cloud {
    hostname     = "app.terraform.io"
    organization = "MyOrg"

    workspaces {
      name = "MyWorkspace"
    }
  }
}

I have a variable in my HCL

variable "app_version" {
  description = "The application version to deploy"
  type        = string
}

I am attempting to set it when I call terraform apply like so:-

terraform apply -var="app_version=v0.0.1" 

I get the following error though.

1 error occurred:
        * Invalid HCL in variable "app_version": At 1:15: Unknown token: 1:15 IDENT v0.0.1

What does this mean?

Upvotes: 4

Views: 1311

Answers (2)

Bryan
Bryan

Reputation: 158

Grzegorz was correct but if you are on a windows machine you will need to escape the double quotes but adding a \ before each double quote.

Upvotes: 0

Grzegorz Oledzki
Grzegorz Oledzki

Reputation: 24251

I think the Terraform docs for command line variables do a poor job of explaining that, but you basically need to wrap the value in double quotes. As the value passed after = is interpreted as Terraform expression, not constant (which opens up for other possibilities).

So, try:

terraform apply -var 'app_version="v0.0.1"' 

Also notice there should be no = after -var

Upvotes: 2

Related Questions