Sabo Boz
Sabo Boz

Reputation: 2575

how to pass in variables over CLI when running cdktf deploy

I currently have a cdktf (terraform cdk for typescript) project where I have a variable defined as follows:

const resourceName = new TerraformVariable(this, "resourceName", {
      type: "string",
      default: "defaultResourceName",
      description: "resource name",
});

However, when I run cdktf deploy -var="resourceName=foo" I am seeing that the resourceName variable is still defaultResourceName rather than foo as I have intended to pass in via the cli. According to the terraform documentation at https://www.terraform.io/language/values/variables#variables-on-the-command-line this is the right way to pass in variables on the cli but it's clearly not working here - would anyone know the actual correct way? I know variables can be dynamically changed via environment variables but I'd ideally like to just pass variables through cli directly.

Upvotes: 1

Views: 1534

Answers (2)

javierlga
javierlga

Reputation: 1650

First, you need to set EXCLUDE_STACK_ID_FROM_LOGICAL_IDS to true in the cdktf.json file, otherwise, the variables get a random suffix.

Also, there's no -var flag for the deploy argument, you have to set them as environment variables.

Upvotes: 1

Spacewink
Spacewink

Reputation: 157

I used cdktf deploy -p resourceName=foo

Upvotes: -1

Related Questions