Very first Terraform code and issue

I have my first terraform code and already have an issue and not understanding what it is.
My code is to deploy a t2.micro instance and when I run it, it keeps asking me to “Enter a value:”
From my understanding it should be assigning from my code and not understanding what I’m doing wrong.


You defined a variable:

variable "instance_type" {
  type = string

You did not give it a default, nor provide a value through other means, so you are being prompted for it.

Sorry, can I see an example of “give it a default” please?

Here you go:

variable "instance_type" {
  type = string
  default = "t2.micro"

thank you

getting another issue. I’ll see if I can figure this out.
Thanks again

I think another interesting quirk here is that you wrote -var.instance_type="t2.micro" instead of -var="instance_type=t2.micro".

Normally that would be invalid in a way that would cause an argument parsing error, but I think PowerShell’s parser treated the dot as a token separator and so PowerShell ran Terraform with the argument sequence ["-var", ".instance_type=t2.micro"], and so Terraform in turn thought you were trying to set a value for a variable called .instance_type, with a leading dot.

PowerShell’s support for running external programs (rather than its own cmdlets) is full of strange quirks like this, unfortunately; we typically recommend using Terraform on Windows via the normal Command Prompt instead for that reason, because the Command Prompt doesn’t quietly modify the command line you typed and pass the modified version to the external program. When PowerShell does this, it creates situations like this where the error message doesn’t really make sense for what you typed on the command line – because what you typed on the command line isn’t what PowerShell passed to Terraform as the command line. :confounded:

With that said: if you define a default value for this variable as already discussed then you won’t need this extra argument at all, but if you do want to override that default on the command line then you can do so either by using -var="instance_type=t2.micro" or by putting the value into a .tfvars file and using the -var-file option instead, which reduces the problems associated with PowerShell modifying the argument you gave on the command line.

Thank you for taking the time to inform me with all this info. I would have never known. I’ll definitely start using CMD. Just passing AWS-SAA, was a feet and now trying to get a job with this cred is even rougher and I’ve been doing system integration for over 20 years. Just not coding, so this is a new hurdle for me. Back in the day, I had taken a few languages Cobol, Fortran and RPG. I’m familiar with needing to understand syntax, format and language(s) abilities. Just didn’t think it would be this tough. I have Terraform Up & Running 2nd but just having a hell of a time trouble shooting. I’ll keep trudging on though.
Thanks again!!