Reputation: 625
I have a terraform module
that looks like below
module "newserver" {
source = "./newserver"
// passing the variables here
}
Instead of passing the variables there, can i pass them as a file in the command like below
terraform apply -var-file="/path/variables.tfvars"
When i do that, i am getting errors like missing required argument
, what am i missing here, any help on this would be appreciated.
Upvotes: 0
Views: 1360
Reputation: 2881
Your module has variables defined inside it with variable
blocks such as
variable "example_var" {}
When you instantiate the module, you'll need to pass the required variable into the module. If you want to pass variables into the module when you instantiate it, you'll also have to define those variables as well
module "newserver" {
source = "./newserver"
example_var = var.example_var
}
variable "example_var" {}
Terraform is scoped so that variables are scoped inside of modules, you'll have to make a new variable if you instantiate a module and want to pass variables into it
Upvotes: 1