Sharing a variables.tf file across multiple terraform environment folders

hello forum folks.

having just started using app.terraform.io remote backend states today, and sharing those states across other terraform environments, i’ve come across having to keep a standards copy of a variables.tf file in each of my environments folders, but it would be cool just to use a shared one for all my environments.

this variables.tf file actually picks up values of a local env setup script to set the variables.

eg: a pipeline is currently using assets from the shared terraform remote state from the vpc.

folders:

/vpc
/vpc/network.tf
/vpc/variables.tf
/pipeline
/pipeline/codebuild.tf
/pipeline/variables.tf

variables.tf:

variable "aws_region" {
  default = "{var.aws_region}"
}
(etc etc)

it appears terraform can’t use a new /shared/variables.tf in both the terraform apply for the /vpc and /pipeline folders. if what i’m saying is correct, is there a work around to somehow use a shared variables.tf file like this?

thank you!

1 Like

What about a simple symlink?

@Wolfsrudel comes in FTW! thank you. that worked perfectly.

1 Like

tip: be careful while running terraform fmt over the symlinks. I have observed in the past that the symlinks get converted to regular files.

1 Like

Thanks for the hint. :+1: