Skip to content

Commit dfe916b

Browse files
authored
[update] A Beginner's Guide to Terraform
fixes: #4962
1 parent 2eda78b commit dfe916b

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

  • docs/guides/applications/configuration-management/terraform/beginners-guide-to-terraform

docs/guides/applications/configuration-management/terraform/beginners-guide-to-terraform/index.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,58 @@ Here's a simple example of a complete Terraform configuration in HCL:
6161
terraform {
6262
required_providers {
6363
linode = {
64-
source = "linode/linode"
64+
source = "linode/linode"
6565
version = "1.16.0"
6666
}
6767
}
6868
}
6969

7070
provider "linode" {
71-
token = "your-linode-api-token"
71+
token = "your-linode-api-token"
7272
}
7373

7474
resource "linode_instance" "example_instance" {
75-
label = "example_instance_label"
76-
image = "linode/ubuntu18.04"
77-
region = "us-central"
78-
type = "g6-standard-1"
79-
authorized_keys = ["ssh-rsa AAAA...Gw== user@example.local"]
80-
root_pass = "your-root-password"
75+
label = "example_instance_label"
76+
image = "linode/ubuntu18.04"
77+
region = "us-central"
78+
type = "g6-standard-1"
79+
authorized_keys = ["ssh-rsa AAAA...Gw== user@example.local"]
80+
root_pass = "your-root-password"
8181
}
82+
83+
output "ipv4" {
84+
value = linode_instance.example_instance.ipv4
85+
}
86+
87+
output "login_ipv4" {
88+
value = "ssh -i ~/.ssh/id_rsa root@${tolist(linode_instance.example_instance.ipv4)[0]}"
89+
}
90+
91+
output "ipv6" {
92+
value = linode_instance.example_instance.ipv6
93+
}
94+
95+
output "login_ipv6" {
96+
value = "ssh -6 -i ~/.ssh/id_rsa root@${linode_instance.example_instance.ipv6}"
97+
}
98+
8299
{{< /file >}}
83100

84101
{{< note >}}
85-
The SSH key in this example was truncated for brevity.
102+
* The SSH key in this example was truncated for brevity.
103+
* SSH Access Defaults to Root:
104+
By default, the authorized_keys argument sets up SSH access for the root user. If you attempt to SSH as a different user such as `ubuntu`, it fails unless you’ve configured additional steps inside the instance.
105+
Example SSH command:
106+
```ssh -i ~/.ssh/id_rsa root@<linode-ip>```
107+
You can use the login_ipv4 and login_ipv6 outputs to get ready-to-use commands after terraform apply.
108+
* Non-root Users:
109+
The linode_instance resource does not support creating or configuring additional users directly. If you prefer to log in as a non-root user (such as ubuntu), you must either:
110+
- Use a startup script such as stackscript or user_data to create and configure that user.
111+
- Log in as root and manually create the user, then add your SSH key to their `~/.ssh/authorized_keys` file.
112+
* Root Password and SSH Key Usage:
113+
This example provides both a root_pass and authorized_keys. While the password offers a fallback for debugging or recovery, using SSH keys is more secure. It is not recommended to keep the `root_pass` in production use. Consider omitting it or managing access through SSH keys and minimal sudo privileges instead.
114+
* Outputs for Easier Connectivity:
115+
The example includes output values that generate SSH commands. These make it easy to copy/paste commands to access your Linode instance after provisioning.
86116
{{< /note >}}
87117

88118
This example Terraform file, with the Terraform file extension `.tf`, represents the creation of a single Linode instance labeled `example_instance_label`. This example file is prefixed with a mandatory `provider` block, which sets up the Linode provider and which you must list somewhere in your configuration.

0 commit comments

Comments
 (0)