diff --git a/.woodpecker/deploy.yml b/.woodpecker/deploy.yml index c43b043..03e06bc 100644 --- a/.woodpecker/deploy.yml +++ b/.woodpecker/deploy.yml @@ -1,11 +1,19 @@ branches: - include: [main] + include: [ ] pipeline: init: image: hashicorp/terraform environment: - - CODE_PATH=./hetzner/template + - CODE_PATH=./hetzner/Projects/Development/landing-zone commands: - apk add make - - make init \ No newline at end of file + - make init + apply: + image: hashicorp/terraform + environment: + - CODE_PATH=./hetzner/Projects/Development/landing-zone + secrets: [hetznerkey] + commands: + - apk add make + - make apply \ No newline at end of file diff --git a/.woodpecker/destroy.yml b/.woodpecker/destroy.yml new file mode 100644 index 0000000..5f7d9f4 --- /dev/null +++ b/.woodpecker/destroy.yml @@ -0,0 +1,11 @@ +branches: + include: [ ] + +pipeline: + init: + image: hashicorp/terraform + environment: + - CODE_PATH=./hetzner/template + commands: + - apk add make + - make destroy \ No newline at end of file diff --git a/Makefile b/Makefile index 32f12a5..2c42fcd 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,17 @@ CODE_PATH ?= . +HETZNERKEY ?= . init: @cd $(CODE_PATH) && terraform init -reconfigure -upgrade plan: init validate - @cd $(CODE_PATH) && terraform plan + @cd $(CODE_PATH) && terraform plan -var="hcloud_token=$(HETZNERKEY)" apply: init validate - @cd $(CODE_PATH) && terraform apply --auto-approve + @cd $(CODE_PATH) && terraform apply --auto-approve -var="hcloud_token=$(HETZNERKEY)" refresh: init validate - @cd $(CODE_PATH) && terraform refresh + @cd $(CODE_PATH) && terraform refresh -var="hcloud_token=$(HETZNERKEY)" fmt: @cd $(CODE_PATH) && terraform fmt -check -recursive @@ -19,4 +20,7 @@ validate: @cd $(CODE_PATH) && terraform validate output: init - @cd $(CODE_PATH) && terraform output \ No newline at end of file + @cd $(CODE_PATH) && terraform output + +destroy: init validate + @cd $(CODE_PATH) && terraform destroy --auto-approve -var="hcloud_token=$(HETZNERKEY)" \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl b/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl new file mode 100644 index 0000000..985890d --- /dev/null +++ b/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hetznercloud/hcloud" { + version = "1.36.1" + constraints = "~> 1.36.0" + hashes = [ + "h1:xZSvxx6aUo0oZp2uqNxi/+wqnCNEBBuu8y7GeXIO9qA=", + "zh:16558b25c7f92f187278e94e951b0ab687882b06acff5b1387f3293f27939f8c", + "zh:28fc79ac2189ff0f5e6c9535ada8f57552b6e21c978b59dc78e086c27b9e4b23", + "zh:373907f9f7f2cefa94e2d5638bf5bef3d3b17e7655dc84dd6089346c6f4f9096", + "zh:394716cd877de682a0772d660f1bdb3838c5d751eca2211105d5ede248c48c39", + "zh:3c438c6590fcc8ac65a10039b2f5ba9ee379a734cb93a59c6cf74f385d891e87", + "zh:3f777a460a62fd23b283c269f1533b3887bf0c5564581e1e96cf294e077f5a8a", + "zh:4f62967553d7ce81ec14db7685306b625970ba6640b5764dc0137675ab97af0b", + "zh:56da08f8d75f596d6f9da4f0fd16bd60d1733cabcc260e885e1d7a711d6d3d8b", + "zh:62776c885bfa8e715dba6662f1744b5251f4cdd523dd4d1e4ccb2e25489593e9", + "zh:64cbb68139aa65f95ab3e654d872f9d34ef991fbf667fc30e0f29b96b5e8b4ed", + "zh:75a4b7a73ff0a537214d12d820438b7ae7a33d660e5d793f4ae0ebe3152bff00", + "zh:7b59d72538772ada7d51eaa50c905285200b1889ab29948b533412ccdf4d18de", + "zh:b84eeaa82bf765c6dd945ae83f1a9271fa5fad53b861b18b09cb8deda67dae13", + "zh:e81c3ea971e32a6ca3fdb0cd9e644614308ab2cf2a19482dd8a109d67fe3fb6f", + ] +} diff --git a/hetzner/Projects/Development/landing-zone/main.tf b/hetzner/Projects/Development/landing-zone/main.tf new file mode 100644 index 0000000..cd90f6a --- /dev/null +++ b/hetzner/Projects/Development/landing-zone/main.tf @@ -0,0 +1,10 @@ +# Create a new server running debian +resource "hcloud_server" "node1" { + name = "node1" + image = "debian-11" + server_type = "cx11" + public_net { + ipv4_enabled = true + ipv6_enabled = true + } +} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/provider.tf b/hetzner/Projects/Development/landing-zone/provider.tf new file mode 100644 index 0000000..90dc159 --- /dev/null +++ b/hetzner/Projects/Development/landing-zone/provider.tf @@ -0,0 +1,4 @@ +# Configure the Hetzner Cloud Provider +provider "hcloud" { + token = var.hcloud_token +} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/variables.tf b/hetzner/Projects/Development/landing-zone/variables.tf new file mode 100644 index 0000000..e7c25e6 --- /dev/null +++ b/hetzner/Projects/Development/landing-zone/variables.tf @@ -0,0 +1,5 @@ +# Set the variable value in *.tfvars file +# or using the -var="hcloud_token=..." CLI option +variable "hcloud_token" { + sensitive = true # Requires terraform >= 0.14 +} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/versions.tf b/hetzner/Projects/Development/landing-zone/versions.tf new file mode 100644 index 0000000..7222126 --- /dev/null +++ b/hetzner/Projects/Development/landing-zone/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + hcloud = { + source = "hetznercloud/hcloud" + version = "~> 1.36.0" + } + } + required_version = ">= 1.3.6" +} \ No newline at end of file