Difference between revisions of "Terraform variables: variables.tf"

From wikieduonline
Jump to navigation Jump to search
Line 3: Line 3:
 
* https://learn.hashicorp.com/tutorials/terraform/aws-variables
 
* https://learn.hashicorp.com/tutorials/terraform/aws-variables
  
== Example variable declaration ==
+
== Variable declaration ==
  
 
Definition in <code>[[variables.tf]]</code>
 
Definition in <code>[[variables.tf]]</code>
Line 21: Line 21:
 
  }
 
  }
  
 +
== Variable usage ==
 
Usage in any terraform file (<code>[[main.tf]]</code>), using <code>[[var.]]</code> prefix:
 
Usage in any terraform file (<code>[[main.tf]]</code>), using <code>[[var.]]</code> prefix:
  

Revision as of 07:06, 31 October 2022

Variable declaration

Definition in variables.tf

variable "YourVarName" {}
variable "YourVarName" { default = "your_default_value" }
variable "your_subnets" { default = ["subnet-0d68d399b6cf9c2b3", "subnet-055f2f0b4de211111"] }
variable "YourVarName" {
  default = "your_default_value"
}
variable "YourVarName" {
  type = string
  description = "Description of your variable"
  default = "your_default_value"
}

Variable usage

Usage in any terraform file (main.tf), using var. prefix:

AnyFieldToAssingAValue = var.YourVarName

Errors

Related term

See also

Advertising: