From a91bd66c2d8eb37997234c6ccc7670d36dc9ae90 Mon Sep 17 00:00:00 2001 From: Benjamin Kircher Date: Tue, 26 Jan 2021 16:49:43 +0100 Subject: [PATCH] Add pubkey-from-file example --- README.md | 1 + pubkey-from-file/.envrc | 3 +++ pubkey-from-file/README.md | 10 ++++++++++ pubkey-from-file/example.tf | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 pubkey-from-file/.envrc create mode 100644 pubkey-from-file/README.md create mode 100644 pubkey-from-file/example.tf diff --git a/README.md b/README.md index c17c38d..93dcd1b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ To make use of the examples, you will need a [gridscale.io](https://my.gridscale - [single-server](single-server/README.md): A simple example that shows how a complete server with attached storage, template selection, and networking can be described in Terraform. - [provisioner](provisioner/README.md): Shows how to integrate Ansible with Terraform to provision your servers and assign them your Ansible roles. - [multi-project](multi-project/README.md): Describes how you could get Terraform to work in a multi-project scenario. +- [pubkey-from-file](pubkey-from-file/README.md): Example that shows how to load an SSH public key file with `file()`. ## More diff --git a/pubkey-from-file/.envrc b/pubkey-from-file/.envrc new file mode 100644 index 0000000..c1fa7a2 --- /dev/null +++ b/pubkey-from-file/.envrc @@ -0,0 +1,3 @@ +export GRIDSCALE_TOKEN=your-api-token +export GRIDSCALE_URL=https://api.gridscale.io +export GRIDSCALE_UUID=your-user-id diff --git a/pubkey-from-file/README.md b/pubkey-from-file/README.md new file mode 100644 index 0000000..b59679e --- /dev/null +++ b/pubkey-from-file/README.md @@ -0,0 +1,10 @@ +# SSH pubkey from file + +This is a small example that shows how to load an SSH public key file from disk with `file()` + +```hcl +resource "gridscale_sshkey" "demo" { + name = "demo" + sshkey = file("/home/john/.ssh/id_rsa.pub") +} +``` diff --git a/pubkey-from-file/example.tf b/pubkey-from-file/example.tf new file mode 100644 index 0000000..06babdd --- /dev/null +++ b/pubkey-from-file/example.tf @@ -0,0 +1,36 @@ +terraform { + required_providers { + gridscale = { + source = "gridscale/gridscale" + version = "~> 1.8.2" + } + } +} + +resource "gridscale_server" "demo" { + name = "demo" + cores = 1 + memory = 1 + storage { + object_uuid = gridscale_storage.demo.id + } + power = false +} + +resource "gridscale_storage" "demo" { + name = "demo" + capacity = 10 + template { + template_uuid = data.gridscale_template.ubuntu.id + sshkeys = [gridscale_sshkey.demo.id] + } +} + +resource "gridscale_sshkey" "demo" { + name = "demo" + sshkey = file("/home/john/.ssh/id_rsa.pub") +} + +data "gridscale_template" "ubuntu" { + name = "Ubuntu 18.04 LTS" +}