Secrets and state
Guide to Managing Terraform secrets.
variables.tf |
env |
providers.tf |
|---|---|---|
variable "hcloud_token" {
nullable = false
sensitive = true
} |
export TF_VAR_hcloud_token=mBSxD... |
provider "hcloud" {
token = var.hcloud_token
} |
|
||
For security reasons, secrets should not be under version control:
...
provider "hcloud" { token = "xdaGfz9LmwO8SWkg ... "}
...|
Declaring variable "hcloud_token" { # See secret.auto.tfvars
nullable = false
sensitive = true
} |
Defining hcloud_token="xdaGfz9LmwO8SWkg ... " |
|
Using provider "hcloud" { token = var.hcloud_token } |
Template file
hcloud_token="your_api_token_goes_here" |
|
Content of file
Content
of file
|
-
Again declare
hcloud_tokeninvariables.tf. -
Add a
dot.env.templatefile to version control:export TF_VAR_hcloud_token="Your token goes here" -
Copy
dot.env.templateto.env, supply secret and add it to your.gitignorefile. -
Source the
.envfile, e.g. in a Bash shell execute:. .envTest it:
$ . ./env $ echo $TF_VAR_hcloud_token gTwn5...
No. 13
Incrementally creating a base system
|
Q: |
Follow the subsequent steps creating basic server based on Terraform:
|
-
Problems:
-
Multiple users and local Terraform state.
-
DayDisjoint working environments, i.e. company and home office.
-
-
Solution: Move Terraform state to shared backend.
