Difference between revisions of "Terraform variables: variables.tf"
Jump to navigation
Jump to search
(50 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | + | TOMERGE [[Terraform variables]] | |
− | |||
* https://www.terraform.io/docs/language/values/variables.html | * https://www.terraform.io/docs/language/values/variables.html | ||
* https://learn.hashicorp.com/tutorials/terraform/aws-variables | * https://learn.hashicorp.com/tutorials/terraform/aws-variables | ||
+ | https://cloud.google.com/docs/terraform/best-practices-for-terraform#variables | ||
− | == | + | string |
+ | number | ||
+ | bool | ||
+ | |||
+ | == Variable declaration == | ||
Definition in <code>[[variables.tf]]</code> | Definition in <code>[[variables.tf]]</code> | ||
− | variable " | + | |
− | type = string | + | [[variable]] "YourVarName" {} |
+ | variable "YourVarName" { default = "your_default_value" } | ||
+ | variable "your_subnets" { default = ["subnet-0d68d399b6cf9c2b3", "subnet-055f2f0b4de211111"] } | ||
+ | |||
+ | [[variable]] "YourVarName" { | ||
+ | default = "your_default_value" | ||
+ | } | ||
+ | |||
+ | variable "YourVarName" { | ||
+ | [[Terraform variable types|type]] = [[string]] | ||
description = "Description of your variable" | description = "Description of your variable" | ||
default = "your_default_value" | default = "your_default_value" | ||
} | } | ||
− | Usage in <code>[[main.tf]]</code> | + | == Variable usage == |
+ | Usage in any terraform file (<code>[[main.tf]]</code>), using <code>[[var.]]</code> prefix: | ||
+ | |||
+ | <code>AnyFieldToAssingAValue = [[var.]]YourVarName</code> | ||
+ | <code>[[AnyFieldToAssingAValue]] = "${var.YourVarName}-yourtext-here"</code> | ||
+ | |||
+ | yourvar = "${aws_lb.your_lb_resource_name.dns_name}" | ||
+ | == Errors == | ||
+ | * <code>[[Error: No value for required variable]]</code> | ||
+ | * <code>[[Error: Reference to undeclared input variable]]</code> | ||
+ | * <code>[[Error: Variables not allowed]]</code> | ||
== Related term == | == Related term == | ||
* <code>[[main.tf]]</code> | * <code>[[main.tf]]</code> | ||
* <code>[[variable.tfvars]]</code> | * <code>[[variable.tfvars]]</code> | ||
− | * [[ | + | * <code>[[terraform.tfvars]]</code> |
− | * <code>[[terraform apply]] -var | + | * <code>[[terraform apply]] -var 'myvar=football'</code> |
+ | * <code>[[terraform plan]]</code> | ||
+ | * <code>[[local.]]</code> | ||
+ | * <code>[[module.]]</code> | ||
+ | * <code>[[data.]]</code> | ||
+ | * <code>[[.name]]</code> | ||
+ | * <code>[[.dns_name]]</code> | ||
+ | * <code>[[.arn]]</code> | ||
+ | * [[Terraform best practices]] | ||
+ | * [[random_string.suffix.result]] | ||
+ | * [[context.tf]] | ||
== See also == | == See also == | ||
* {{tf files}} | * {{tf files}} | ||
− | + | * {{Terraform variables}} | |
− | * {{Terraform}} | ||
[[Category:Terraform]] | [[Category:Terraform]] |
Latest revision as of 03:33, 11 July 2024
TOMERGE Terraform variables
- https://www.terraform.io/docs/language/values/variables.html
- https://learn.hashicorp.com/tutorials/terraform/aws-variables
https://cloud.google.com/docs/terraform/best-practices-for-terraform#variables
string number bool
Variable declaration[edit]
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[edit]
Usage in any terraform file (main.tf
), using var.
prefix:
AnyFieldToAssingAValue = var.YourVarName
AnyFieldToAssingAValue = "${var.YourVarName}-yourtext-here"
yourvar = "${aws_lb.your_lb_resource_name.dns_name}"
Errors[edit]
Error: No value for required variable
Error: Reference to undeclared input variable
Error: Variables not allowed
Related term[edit]
main.tf
variable.tfvars
terraform.tfvars
terraform apply -var 'myvar=football'
terraform plan
local.
module.
data.
.name
.dns_name
.arn
- Terraform best practices
- random_string.suffix.result
- context.tf
See also[edit]
- Terraform configuration files, Terraform state files:
.tf
,.tfvars
,main.tf, outputs.tf
,variables.tf
,.terraform.d/
,terraform init
,providers.tf
,.terraform/
,terraform.tfstate
,.terraform.lock.hcl
,terraform.tfstate.d, override.tf, versions.tf
- Terraform variables, types, env variables,
variables.tf
,.tfvars
,nullable
,validation
,terraform.tfvars
Advertising: