I have created the following terraform.tfvars file:
ec2_image = "ami-00035f41c82244dab"
ec2_instance_type = "t2.micro"
And use it as follows in a main.tf file:
resource "aws_instance" "OneServer" {
ami = "${var.ec2_image}"
instance_type = "${var.ec2_instance_type}"
}
Then I execute the 'terraform plan' command and it complains with:
Error: resource 'aws_instance.OneServer' config: unknown variable referenced: 'ec2_image'; define it with a 'variable' block
So I changed the main.tf file as follows:
variable "ec2_image" {}
variable "ec2_instance_type" {}
resource "aws_instance" "OneServer" {
ami = "${var.ec2_image}"
instance_type = "${var.ec2_instance_type}"
}
Then the command 'terraform plan' works OK.
I don't understand why these variable blocks are required. What's the point for it?
TF_VAR_
environment variables. – ydaetskcoR