0
votes

This is my variables.tf file

 variable vpc-count { description = "Number of VPC to create" }

 variable "vpc1" { description = "Enter the CIDR for vpc1" }

 variable "vpc2" { description = "Enter the CIDR for vpc2" }

 variable subnet-count { description ="Enter the number of subnets                             for vpc" }

 variable "sub1vpc1" { description = "Enter the CIDR for subnet1 of vpc1" }

 variable "sub2vpc1" { description = "Enter the CIDR for subnet2 of vpc1" }

 variable "sub1vpc2" { description = "Enter the CIDR for subnet2 of vpc1" }

 variable "sub2vpc2" { description = "Enter the CIDR for subnet2 of vpc2" }

The reason for not specifying the values is because of the need to be interactive and give an option to the user to enter the relevant values for vpc cidr , subnet cidr etc .

But while entering "terraform plan" . It prompts the Enter value: question but not in the order that is mentioned in the variables.tf file

For eg: First question asked is from

  variable "sub1vpc1" { description = "Enter the CIDR for subnet1 of vpc1" }

even though it is 5th in line

Does Terraform does not do ordering of . Asking a question about subnet cidr even before VPC cidr is not proper way i think

Any remedies

2

2 Answers

1
votes

Unfortunately no. It's ordering it alphabetically.

Try this: put the following code into a .tf file and run terraform plan:

variable "z" { description = "var z" }
variable "b" { description = "var b" }
variable "a" { description = "var a" }

If you need to prompt the user in a specific order, you could write a wrapper script that feeds the values into a .tfvars file.

0
votes

Terraform is not procedural, it is declarative and so everything is considered 'at once'. The expression of this is that in OP's case these questions will be asked in a random order, not the same order each time