Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Variables #12

Open
Soolaa opened this issue Mar 5, 2023 · 2 comments
Open

Using Variables #12

Soolaa opened this issue Mar 5, 2023 · 2 comments

Comments

@Soolaa
Copy link

Soolaa commented Mar 5, 2023

Hi.
I am using variables in the variable.tf file and trying to read the data of it. But even if I leave the variable without a default value, when "terraform plan" command is running, It has a value and seems not using of variables.tf file. what is the problem? I will appreciate.
variables.tf file:
variable "ami_id" {}
variable "instance_type" {}

main.tf file:
resource "aws_instance" "Sahar" {
ami = var.ami_id
instance_type = var.instance_type

terraform apply result:

aws_instance.Sahar will be created

  • resource "aws_instance" "Sahar" {
    • ami = "ami-0557a15b87f6559cf"
@moohebat
Copy link

moohebat commented Mar 8, 2023

Hi. I am using variables in the variable.tf file and trying to read the data of it. But even if I leave the variable without a default value, when "terraform plan" command is running, It has a value and seems not using of variables.tf file. what is the problem? I will appreciate. variables.tf file: variable "ami_id" {} variable "instance_type" {}

main.tf file: resource "aws_instance" "Sahar" { ami = var.ami_id instance_type = var.instance_type

terraform apply result:

aws_instance.Sahar will be created

  • resource "aws_instance" "Sahar" {

    • ami = "ami-0557a15b87f6559cf"

are you sure you have not set the variables in terraform.vartf file?

@Mina-Farajian
Copy link

you shouldn't hardcode value amount in variables.tf . you leave value empty there
then set value in terraform.tfvars
variables.tf file:
variable "ami_id" {}
variable "instance_type" {}

terraform.tfvars
ami_id = "ami-08cd358d745620807"
instance_type = "t2.micro"

main.tf file :
resource "aws_instance" "test" {
ami = var.ami_id
instance_type = var.instance_type
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants