Skip to content

🖥 Provisioning a Hetzner Server, automated configuration of ssh, firewall, nginx, and s3 bucket mount with Terraform and cloud init. Features security-hardened SSH setup, fail2ban integration, UFW firewall rules, ensuring consistent and secure deployments.

Notifications You must be signed in to change notification settings

thoth2357/Provisioning-hetzner-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Provisioning a Hetzner Server with Terraform

This repository encompasses the essential files and code for provisioning a Hetzner server through Terraform. It automates the configuration of firewall rules, SSH access with added keys, utilizes cloud-init for provisioning tasks including hardening SSH, configuring the firewall, setting up nginx, and finally, mounting an external Contabo S3 bucket..

Prerequisites

Before you begin, make sure your development environment includes the following prerequisites:

Usage

To use this code and provision a Hetzner server with Terraform, follow these steps:

  1. Clone or download this repository to your local machine.
  1. Obtain an API token from Hetzner Cloud. This token will be used to authenticate and interact with the Hetzner API.
  1. Create a terraform.tfvars file in the root directory of your project. This file should contain the following configuration:

    hcloud_token = "YOUR_HETZNER_API_TOKEN"
    

    Replace YOUR_HETZNER_API_TOKEN with your actual Hetzner API token.

    Note: Make sure to keep this file secure and do not commit it to version control systems.

  1. Update the values in the variables.tf file according to your requirements. This file defines the input variables used in the Terraform configuration.
  1. Update the values in the ssh.tf file according to your requirements. This file defines the SSH keys to be used for authentication with the Hetzner server. It includes the primary SSH key and two secondary SSH keys.
  1. Update, delete, or add new firewall rules in the firewall.tf file according to your requirements. This file defines the firewall rules for the Hetzner server. It currently includes inbound and outbound rules for specific ports and protocols.
  1. Update the values in the instance.tf file according to your requirements. This file defines the resources to be provisioned, such as the Hetzner server, networking settings, and any other required infrastructure components.
  1. Update the values in the cloud-init.yml file according to your requirements. Such as your access_id and key, hashed_passwd and ssh_authorized_keys that can login to the specific users. To Generate the hashed passwd, run below command on your local machine, input your desired password and copy the output to the cloud-init.yml file.
thoth@Macbook:~$ mkpasswd --method=SHA-512 --rounds=500000
Password:
  1. Run terraform init to initialize the Terraform configuration.
  1. Run terraform plan to see an execution plan for the Terraform provisioning process.
  1. Run terraform apply to provision the Hetzner server and deploy the defined infrastructure components.
  1. After the provisioning process is complete, you can retrieve information about the provisioned resources by running terraform output.
  1. To destroy the provisioned resources and clean up, run terraform destroy.

That's it! You have now successfully provisioned a Hetzner server using Terraform and deployed the necessary infrastructure components. Enjoy using your new server!

Replace YOUR_HETZNER_API_TOKEN with your actual Hetzner API token.

Note: Make sure to keep this file secure and do not commit it to version control systems.

About

🖥 Provisioning a Hetzner Server, automated configuration of ssh, firewall, nginx, and s3 bucket mount with Terraform and cloud init. Features security-hardened SSH setup, fail2ban integration, UFW firewall rules, ensuring consistent and secure deployments.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages