Skip to content
Snippets Groups Projects
Commit 372d7089 authored by Goik Martin's avatar Goik Martin
Browse files

Terraform + cloud init

parent f578c0a6
No related branches found
No related tags found
No related merge requests found
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
required_version = ">= 0.13"
}
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_ssh_key" "goik" {
name = "goik@hdm-stuttgart.de"
public_key = file("~/.ssh/id_ed25519.pub")
}
resource "hcloud_server" "helloServer" {
name = "hello"
image = "debian-12"
server_type = "cx11"
location = "nbg1"
user_data = file("userData.yml")
ssh_keys = [hcloud_ssh_key.goik.id]
firewall_ids = [hcloud_firewall.wwwFw.id]
}
resource "hcloud_firewall" "wwwFw" {
name = "www-firewall"
rule {
direction = "in"
protocol = "tcp"
port = "22"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction = "in"
protocol = "tcp"
port = "80"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction = "in"
protocol = "tcp"
port = "443"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
}
output "hello_ip_addr" {
value = hcloud_server.helloServer.ipv4_address
description = "The server's IPv4 address"
}
output "hello_datacenter" {
value = hcloud_server.helloServer.datacenter
description = "The server's datacenter"
}
\ No newline at end of file
hcloud_token="your_api_token_goes_here"
#cloud-config
packages:
- nginx
runcmd:
- systemctl enable nginx
- rm /var/www/html/*
- echo "Hello! I am Nginx @ $(curl -s ipinfo.io/ip)! This record added at $(date -u)." >>/var/www/html/index.html
variable "hcloud_token" { # See secret.auto.tfvars
nullable = false
sensitive = true
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment