Task 8.4: Configure and use HCP Terraform integration
Connecting the CLI: terraform login and its token, the cloud block with organization and workspaces, migrating local state with init, and running plans remotely from a laptop.
Study it
Connecting the CLI: terraform login, the cloud block and state migration
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A developer runs terraform login on a laptop. What does the command do with the HCP Terraform API token it obtains?
AWrites it into the cloud block of the configuration in the current directory
BSaves it in plain text in credentials.tfrc.json
CKeeps it in memory only until the terminal is closed
DStores it in the dependency lock file, encrypted
Show the answer and why
AWrites it into the cloud block of the configuration in the current directory
Incorrect
login never edits configuration files.
BSaves it in plain text in credentials.tfrc.json
Correct
terraform login obtains an API token and by default saves it in plain text in a local CLI configuration file called credentials.tfrc.json.
CKeeps it in memory only until the terminal is closed
Incorrect
The token is saved to disk by default.
DStores it in the dependency lock file, encrypted
Incorrect
The lock file holds provider selections, not credentials.
login is for interactive machines; protect or relocate the saved token.
A working directory has been connected to HCP Terraform for years through the older backend "remote" configuration. The team moves it to the current HCP Terraform integration in the CLI. What happens to its existing workspaces and their state?
ANew workspaces are created for the integration, and the old ones are left unused
BTerraform downloads each workspace's state and asks to push it back after the change
CThe workspaces must be deleted and created again before the integration can use them
DTerraform keeps using the same workspaces and their state; nothing is copied
Show the answer and why
ANew workspaces are created for the integration, and the old ones are left unused
Incorrect
No new workspaces are created; the configuration keeps pointing at the ones it already uses.
BTerraform downloads each workspace's state and asks to push it back after the change
Incorrect
The state is already in HCP Terraform, so there is nothing to download or push.
CThe workspaces must be deleted and created again before the integration can use them
Incorrect
Deleting the workspaces would throw away their state and history for no reason; they work as they are.
DTerraform keeps using the same workspaces and their state; nothing is copied
Correct
When a directory already uses the remote backend, the switch is a configuration change, and Terraform continues to use the same set of HCP Terraform workspaces.
Moving from the remote backend is a change of configuration, not a migration of state: the workspaces, their state versions and their run history stay where they are.
In the CLI-driven workflow, a developer runs terraform plan -var "replicas=5", while the workspace has a workspace-specific variable replicas = 3. Which value does the remote plan use?
A3, since workspace variables always win in remote runs
BThe plan fails because CLI variables are not allowed with HCP Terraform
C5, since CLI -var overwrites them for the run
DBoth values are averaged
Show the answer and why
A3, since workspace variables always win in remote runs
Incorrect
CLI -var values take precedence in CLI-driven runs.
BThe plan fails because CLI variables are not allowed with HCP Terraform
Incorrect
-var is supported in CLI-driven runs.
C5, since CLI -var overwrites them for the run
Correct
With the CLI workflow, variables applied to a run with -var or -var-file overwrite workspace-specific variables and non-priority variable sets with the same key.
DBoth values are averaged
Incorrect
One value wins.
Run-specific CLI variables beat stored variables for that run.