Using variables
# config.auto.tfvars # Overriding default value "hello" serverName = "testServer" # variables.tf variable "serverName" { description = "Project unique server name" type = string nullable = false default = "hello" } |
# main.tf resource "hcloud_server" "mySrv" { name = var.serverName ... } terraform apply ... serverProps = { "ip" = "46.62.254.219" "name" = "testServer" } |
For security reasons, secrets should not be under version control:
# provider.tf
provider "hcloud" { token = "xdaGfz9LmwO8SWkg ... "}
...# variables.tf variable "hcloud_token" { description = "Hetzner API token" type = string nullable = false sensitive = true } # .env file # Setting environment variable export TF_VAR_hcloud_token="utRw..." |
# main.tf resource "hcloud_server" "mySrv" { name = var.serverName ... } . .env # Source environment file echo $TF_VAR_hcloud_token utRw... terraform apply ... |
No. 15
Using configuration variables
|
Q: |
Start from Adding ssh public keys and firewall and:
The only difference to the previous exercise is thus the extraction of sensitive and non-sensitive values into configuration files. |
