0
0
Terraformcloud~5 mins

Connection blocks for SSH in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a connection block in Terraform when using SSH?
A connection block tells Terraform how to connect to a remote machine using SSH. It provides details like the host address, user name, and authentication method so Terraform can run commands or copy files on that machine.
Click to reveal answer
beginner
Which key fields are commonly used inside a Terraform SSH connection block?
Common fields include host (IP or hostname), user (username to log in), private_key (SSH private key content), and port (SSH port, usually 22).
Click to reveal answer
intermediate
How do you specify the SSH private key in a Terraform connection block?
You use the private_key field and provide the private key as a string. For example, you can read it from a file using Terraform's file() function.
Click to reveal answer
beginner
True or False: The connection block is required for Terraform to manage resources on remote machines via SSH.
True. Without a connection block, Terraform does not know how to connect to the remote machine to execute commands or transfer files.
Click to reveal answer
beginner
What happens if you omit the port field in a Terraform SSH connection block?
Terraform will use the default SSH port 22 to connect to the remote machine.
Click to reveal answer
Which field in a Terraform connection block specifies the username for SSH?
Auser
Bhost
Cprivate_key
Dport
What is the default SSH port used if the port field is not set in the connection block?
A443
B21
C80
D22
How can you provide the SSH private key content in a Terraform connection block?
AUsing the <code>password</code> field
BUsing the <code>private_key</code> field with the key as a string
CUsing the <code>host</code> field
DUsing the <code>user</code> field
Which Terraform resource block commonly uses a connection block for SSH?
Aaws_instance
Bazurerm_virtual_network
Cnull_resource
Dgoogle_storage_bucket
What is the main reason to use a connection block in Terraform?
ATo connect to a remote machine for executing commands
BTo define the cloud provider
CTo specify resource dependencies
DTo set environment variables
Explain how a Terraform connection block is used to connect to a remote machine via SSH.
Think about what information Terraform needs to log in and run commands remotely.
You got /5 concepts.
    Describe what happens if you omit the port field in a Terraform SSH connection block.
    Consider the standard SSH port and how Terraform behaves without explicit port info.
    You got /3 concepts.