aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--account/main.tf23
-rw-r--r--account/outputs.tf4
-rw-r--r--web/main.tf (renamed from main.tf)7
-rw-r--r--web/outputs.tf (renamed from outputs.tf)0
-rw-r--r--web/remotes.tf6
5 files changed, 36 insertions, 4 deletions
diff --git a/account/main.tf b/account/main.tf
new file mode 100644
index 0000000..1966aed
--- /dev/null
+++ b/account/main.tf
@@ -0,0 +1,23 @@
+terraform {
+ required_providers {
+ hcloud = {
+ source = "hetznercloud/hcloud"
+ version = "~> 1.68.0"
+ }
+ }
+}
+
+provider "hcloud" {
+ token = var.hcloud_token
+}
+
+variable "hcloud_token" {
+ type = string
+ sensitive = true
+}
+
+resource "hcloud_ssh_key" "default" {
+ name = "default-key"
+ public_key = file("~/.ssh/id_rsa.pub")
+}
+
diff --git a/account/outputs.tf b/account/outputs.tf
new file mode 100644
index 0000000..f7eb536
--- /dev/null
+++ b/account/outputs.tf
@@ -0,0 +1,4 @@
+output "ssh_key_name" {
+ description = "Account ssh key"
+ value = hcloud_ssh_key.default.name
+}
diff --git a/main.tf b/web/main.tf
index 058b5be..bf49fd0 100644
--- a/main.tf
+++ b/web/main.tf
@@ -21,9 +21,8 @@ data "hcloud_image" "openbsd" {
most_recent = true
}
-resource "hcloud_ssh_key" "default" {
- name = "default-key"
- public_key = file("~/.ssh/id_rsa.pub")
+data "hcloud_ssh_key" "default" {
+ name = data.terraform_remote_state.account.outputs.ssh_key_name
}
resource "hcloud_server" "web01" {
@@ -31,7 +30,7 @@ resource "hcloud_server" "web01" {
image = data.hcloud_image.openbsd.id
server_type = "cx23"
location = "nbg1"
- ssh_keys = [hcloud_ssh_key.default.id]
+ ssh_keys = [data.hcloud_ssh_key.default.id]
public_net {
ipv4_enabled = true
diff --git a/outputs.tf b/web/outputs.tf
index 52ca13a..52ca13a 100644
--- a/outputs.tf
+++ b/web/outputs.tf
diff --git a/web/remotes.tf b/web/remotes.tf
new file mode 100644
index 0000000..394a7f8
--- /dev/null
+++ b/web/remotes.tf
@@ -0,0 +1,6 @@
+data "terraform_remote_state" "account" {
+ backend = "local"
+ config = {
+ path = "../account/terraform.tfstate"
+ }
+}