I am getting an strange error message when running the plan command to deploy a Linux VM from a image gallery. The error is as follows:
╷
│ Error: Missing required argument
│
│ The argument “server” is required, but was not set.
╵
╷
│ Error: Missing required argument
│
│ The argument “username” is required, but was not set.
╵
Using TF_LOG=DEBUG gives nothing and there is no text in the debug print out that could tell me what is wrong. Does anyone recognise this and can give me a lead?
I know I’m posting on an old topic here, and I hope you got it figured out, but just in case you didn’t…
The error messages are describing a couple of cases where a module you are using has not received the required input variables server and username.
Somewhere in your code, you should have something to the effect of:
variable "server" {
description = "foo"
type = string # making assumptions on the typing here
}
...
variable "username" {
description = "bar"
type = string
}
Because they do not have a default value, terraform considers them “required” input variables but doesn’t know and does not assume what their values should be.
When you’re calling your module, you’ll want to supply those either through directly assigning their values in the module definition, as defaults in the module, as external variables (such as through a terraform.tfvars file), or even as environmental variables. One such case would be as follows:
module "module_name_here" {
source = "/path/to/module"
server = "a name for the server"
username = "a name for the user"
}
Here are some resources from Hashicorp surrounding variables and modules that might help with further comprehension: