Skip to content

Commit

Permalink
Add necessary steps to terraform provider tutorial (hetzneronline#454)
Browse files Browse the repository at this point in the history
* Add necessary steps

* Adjust line of text

Co-authored-by: Lars Pickelin <[email protected]>
  • Loading branch information
4ND3R50N and Lars Pickelin authored May 13, 2022
1 parent 9751eba commit 2ee1bb3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tutorials/howto-hcloud-terraform/01.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ In order to create a Hetzner Cloud API token, please visit Hetzner Cloud Console

## Step 1 - Basic Usage

First of all, we create a new directory which will contain our Terraform configuration. We will call it `terraform` and create a new file there called `hcloud.tf`. You can name the file as you like.
First of all, we create a new directory which will contain our Terraform configuration. We will call it `terraform` and create two new files called `hcloud.tf` and `variables.tf`. You can name the files as you like.

```bash
mkdir terraform
touch hcloud.tf
touch variables.tf
```

You can now edit the `hcloud.tf` with a text editor of your choice.
Expand Down Expand Up @@ -88,6 +89,37 @@ resource "hcloud_server" "web" {

This short snippet does basically nothing. It just defines a resource from type `hcloud_server` called `web`. But it won't work, because we didn't tell Terraform which server should be created.

You can now edit the `variables.tf` with a text editor of your choice.

We will first copy the following example into the file.

```hcl
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
required_version = ">= 0.13"
}
```
We will see, what the specific parts mean:

```hcl
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
```
Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a `required_providers` block.
A provider requirement consists of a local `name` (`hcloud`), a `source` location (`hetznercloud/hcloud`) , and a `version` constraint. In our case, we only add the `source` which forces terraform to use the latest provider version.

```hcl
required_version = ">= 0.13"
```
The `required_version` setting accepts a version constraint string, which specifies which versions of Terraform can be used with your configuration. in our case, we use v0.13 or higher.

So now you should create a `terraform.tfvars` -file which will contain the following content:

```text
Expand Down

0 comments on commit 2ee1bb3

Please sign in to comment.