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

From wikieduonline
Jump to navigation Jump to search
Line 36: Line 36:
 
* <code>[[terraform.tfvars]]</code>
 
* <code>[[terraform.tfvars]]</code>
 
* <code>[[terraform apply]] -var 'myvar=football'</code>
 
* <code>[[terraform apply]] -var 'myvar=football'</code>
 +
* <code>[[terraform plan]]</code>
 
* <code>[[local.]]</code>
 
* <code>[[local.]]</code>
 
* <code>[[module.]]</code>
 
* <code>[[module.]]</code>
 
* <code>[[data.]]</code>
 
* <code>[[data.]]</code>
* <code>[[terraform plan]]</code>
 
  
 
== See also ==
 
== See also ==

Revision as of 15:53, 12 January 2023

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
AnyFieldToAssingAValue = "{var.YourVarName}-yourtext-here}"

Errors

Related term

See also

Advertising: