pkaramol
pkaramol

Reputation: 19342

Terraform: Automatically populate module's variables

I am calling a terraform module from my main.tf as follows:

module "vpc" {
  source                  = "./modules/vpc"
  match_pub_ip_env_vpc_sn = true
  env_vpc_sg_name         = "My name"
  env_vpc_sg_desc         = "My description"
}

My question is this: Can I use a file to populate the call to the above module with the values I want for the above variables without explicitly adding them in the module statement (as above). If so is there a file naming convention that terraform uses for such a purpose? (i.e. without me needing to pass -vars-file in the cmd?)

Upvotes: 0

Views: 200

Answers (1)

ydaetskcoR
ydaetskcoR

Reputation: 56877

Unfortunately not. It's like a method/function call. The module needs to declare what variables it takes (eg the signature or parameter list in a programming language, with some being defaulted if not set) and then the caller of the module needs to pass any required variables when it declares the module.

Upvotes: 1

Related Questions