Documentation

Figure 1094. Your course result: Code structure Slide presentation
...
├── .gitignore
├── env.template
├── Conf
│   └── config.tf.template
├── 030HelloSshPublicKey
│   ├── main.tf
│   ├── providers.tf
│   ├── Readme.md
│   └── variables.tf
├── 040...
...
└── Modules
    ├── HostMetaDat
   ...
    └── SshKnownHosts
   ...

Figure 1095. The env.template secrets file Slide presentation
export TF_VAR_hcloud_token=add_your_provider_token
export TF_VAR_dns_secret=add_your_ds_server_secret
  • env.template is to be copied to e.g. an env file.

  • Required credentials to be filled in.

  • Prior to executing e.g. terraform init the env file has to be sourced:

    . ../env                  # Sourcing environment
    echo $TF_VAR_hcloud_token # For testing purpose only
    z0Tgf...
    terraform init
    ...
  • In contrast to env.template the env file is being listed in .gitignore due to sensible content.


Figure 1096. Using environment variable secrets Slide presentation
# variables.tf
variable "hcloud_token" {  # See env file
  nullable = false
  sensitive = true
}
# env file
TF_VAR_hcloud_token="z0Tgf ... "
# providers.tf
...
provider "hcloud" { token = var.hcloud_token }

Figure 1097. The Conf/config.tf.template configuration file Slide presentation
output "authorizedKeys" {
  description = "List of authorized users' public ssh keys"
  type        = map(string)

  value = {
    goik  = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKY24AeEibQGSMPtstaN4REByLCM3kzjM//apEZ9WyUB goik@hdm-stuttgart.de"
    xy001 = "KEY_OF_USER_xy001 xy001@hdm-stuttgart.de"
    xy002 = ...
  }
}

output "loginUserName" {
  description = "Login user's name with admin privileges"
  type        = string

  value = "devops"
}

Figure 1098. The .gitignore file Slide presentation
env
Conf/config.tf

Figure 1099. Managing Terraform states Slide presentation
  • Problems:

    1. Multiple users and local Terraform state.

    2. Disjoint working environments, i.e. company and home office.

  • Solution: Move Terraform state to shared backend.

  • How to Manage Terraform State with GitLab