When are variables defined in Terraform

0 votes

Hi Team,

I have created a variable in the Terraform file. But I want to pass the variable value from the command line. How can I do that?

Dec 7, 2020 in Terraform by akhtar
• 38,170 points
70 views

1 answer to this question.

0 votes

Hi@akhtar,

You can provide the value of each module variable when calling the module itself in Terraform.

module "folder" {
    source = "../<path>/"
    folder_name = "xyz"  # add this line to define the folder_name variable
}

If you'd like to specify folder_name on the command line instead, you can create a variable in your main.tf file and provide that via the command line instead.

variable "module_folder_name" {
  default = "xyz"
}
module "folder" {
   source = "../<path>/"
   folder_name = "${var.module_folder_name}"
}

And, then provide this variable's value via the command line.

$ terraform apply -var="module_folder_name=abc"
answered Dec 7, 2020 by MD
• 95,060 points

Related Questions In Terraform

0 votes
1 answer

How to create a folder in S3 bucket using terraform?

Hi@akhtar, You can use aws_s3_bucket_object resource to create one ...READ MORE

answered Jun 11, 2020 in Terraform by MD
• 95,060 points
2,521 views
0 votes
1 answer

How to do ssh in EC2 instance using Terraform?

Hi@akhtar, To ssh in your EC2 instance, you ...READ MORE

answered Jun 15, 2020 in Terraform by MD
• 95,060 points
2,716 views
0 votes
1 answer

How to launch one Pod in Minikube using Terraform?

Hi@akhtar, You can use kubernetes_pod resource to launch ...READ MORE

answered Jun 16, 2020 in Terraform by MD
• 95,060 points
1,100 views
0 votes
1 answer

How to create a namespace in minikube using Terraform?

Hi@akhtar, You can use kubernetes_namespace resource. It is used ...READ MORE

answered Jun 30, 2020 in Terraform by MD
• 95,060 points
546 views
0 votes
1 answer

'terraform' is not recognized as an internal or external command, operable program or batch file.

Hi@akhtar, You have to set an environment variable ...READ MORE

answered Jun 10, 2020 in Terraform by MD
• 95,060 points
2,496 views
0 votes
1 answer

How to import module in Terraform code?

Hi@akhtar, A module is a container for multiple resources that ...READ MORE

answered Jul 21, 2020 in Terraform by MD
• 95,060 points
573 views
0 votes
1 answer

What is a Terraform provider?

Hi@akhtar, Terraform is agnostic to the underlying cloud ...READ MORE

answered Jul 23, 2020 in Terraform by MD
• 95,060 points
128 views
0 votes
1 answer

How to read data from a file in Terraform?

Hi@akhtar, You can use the file function in Terraform. This file function ...READ MORE

answered Jul 27, 2020 in Terraform by MD
• 95,060 points
993 views
0 votes
1 answer

How are data sources used in Terraform?

Hi@akhtar, A data source is accessed via a ...READ MORE

answered Dec 7, 2020 in Terraform by MD
• 95,060 points
102 views
0 votes
1 answer

How to create one key in AWS using terraform?

Hi@akhtar, You can use aws_key_pair resource n terraform. ...READ MORE

answered Jun 11, 2020 in Terraform by MD
• 95,060 points
567 views