Skip to content

Commit

Permalink
Rework examples
Browse files Browse the repository at this point in the history
- Make sure examples use plugin from Terraform Registry and TF 0.13 by
  giving this preamble:

    terraform {
      required_providers {
        gridscale = {
          source = "gridscale/gridscale"
        }
      }
    }

- Flatten hierarchy and remove trivial examples
- List examples and a short summary in README
- Make sure every example has it's own README
- Make sure all examples actually work
  • Loading branch information
bkircher committed Aug 19, 2020
1 parent 648e447 commit 0eb6cdc
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 179 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Terraform configuration examples for gridscale
# Terraform Examples for gridscale

This repository contains configuration files you can use as a starting point for [Terraform](https://www.terraform.io/) on gridscale. We also have some step-by-step guides on how to use these config files in our [tutorials](https://gridscale.io/en/community/tutorials/terraform-ubuntu-einrichten-gridscale/) section. Check them out!
This repository contains small self-contained Terraform projects you can use as a starting point for using [Terraform](https://www.terraform.io/) with gridscale. It showcases how easy it is to manage gridscale resources with Terraform in simple as well as more advanced scenarios.

To use the config files, you'll need an [API token](https://my.gridscale.io/Easy/APIs/) and a [gridscale](https://my.gridscale.io/signup/) account.
To make use of the examples, you will need a [gridscale.io](https://my.gridscale.io/signup/) account and an [API token](https://my.gridscale.io/Easy/APIs/).

After Terraform is up and running, you can navigate to one of the example directories and run `terraform init` and `terraform apply`. You will be prompted to enter your API credentials by Terraform.
## Examples

- [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.

## More

Check out the provider's [reference documentation](https://registry.terraform.io/providers/gridscale/gridscale/latest/docs) for all Data Sources and Resources, along with a complete list of the arguments they accept.

We also have an introductory-level guide on how to setup and use Terraform in our [tutorials](https://gridscale.io/en/community/tutorials/terraform-ubuntu-einrichten-gridscale/) section. Check it out.

Have fun!
2 changes: 1 addition & 1 deletion multi-project/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multi-project example
# Multi-project Example

This example shows how you can leverage gridscale multi-project feature with Terraform.

Expand Down
42 changes: 0 additions & 42 deletions multiple-servers/mainserver.tf

This file was deleted.

63 changes: 0 additions & 63 deletions multiple-servers/webservers.tf

This file was deleted.

2 changes: 1 addition & 1 deletion single-server/provisioner/.envrc → provisioner/.envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export GRIDSCALE_TOKEN=project-a-api-token
export GRIDSCALE_TOKEN=your-api-token
export GRIDSCALE_URL=https://api.gridscale.io
export GRIDSCALE_UUID=your-user-id
File renamed without changes.
4 changes: 2 additions & 2 deletions single-server/provisioner/README.md → provisioner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Note: You need Ansible installed and in PATH to run this example.

As usual, set `GRIDSCALE_TOKEN` and `GRIDSCALE_UUID` environment variables to the values you got from your panel.

$ export GRIDSCALE_TOKEN=project-a-api-token
$ export GRIDSCALE_TOKEN=your-api-token
$ export GRIDSCALE_UUID=your-user-id

Open `server.tf` and paste your SSH public key where it says `"INSERT KEY"`. Then do
Expand All @@ -19,7 +19,7 @@ And then do a

$ terraform apply

Type `yes` when terraform asks you to. In the end, you should see something like following output in your terminal:
Type `yes` when Terraform asks you to. In the end, you should see something like following output in your terminal:

```raw
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "gridscale" {}
terraform {
required_providers {
gridscale = {
source = "gridscale/gridscale"
}
}
}

data "gridscale_public_network" "pubnet" {
}
Expand Down
3 changes: 3 additions & 0 deletions single-server/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export GRIDSCALE_TOKEN=your-api-token
export GRIDSCALE_URL=https://api.gridscale.io
export GRIDSCALE_UUID=your-user-id
42 changes: 42 additions & 0 deletions single-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# A Simple Server

This is a simple example that show how to use resources and data sources to create a basic running server.

## Running the Example

Set `GRIDSCALE_TOKEN` and `GRIDSCALE_UUID` environment variables to the values you got from your panel.

$ export GRIDSCALE_TOKEN=your-api-token
$ export GRIDSCALE_UUID=your-user-id

Open `server.tf` and paste your SSH public key where it says `"INSERT KEY"`. Then do

$ terraform init

Note that this will download the gridscale provider plugin to `.terraform/`.

Let's create the server. Do

$ terraform apply

Terraform will now plan the actions it is about to perform. You should see something like:

```raw
Plan: 5 to add, 0 to change, 0 to destroy.
```

Investigate the actions that Terraform is about to perform and type `yes`. After about 30 seconds, Terraform will print

```raw
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
```

Go ahead and inspect the panel for the newly created objects. When your done, remove all resources again by doing

$ terraform destroy

After a few moments, everything is removed again.

```raw
Destroy complete! Resources: 5 destroyed.
```
42 changes: 0 additions & 42 deletions single-server/complete/server.tf

This file was deleted.

7 changes: 0 additions & 7 deletions single-server/server-only/server.tf

This file was deleted.

47 changes: 47 additions & 0 deletions single-server/server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
terraform {
required_providers {
gridscale = {
source = "gridscale/gridscale"
}
}
}

resource "gridscale_server" "demo" {
name = "demo"
cores = 1
memory = 2
storage {
object_uuid = gridscale_storage.demo.id
}
network {
object_uuid = gridscale_network.demo.id
}
ipv4 = gridscale_ipv4.demo.id
power = true
}

resource "gridscale_storage" "demo" {
name = "demo"
capacity = 10
template {
template_uuid = data.gridscale_template.ubuntu.id
sshkeys = [gridscale_sshkey.demo.id]
}
}

resource "gridscale_network" "demo" {
name = "demo"
}

resource "gridscale_ipv4" "demo" {
name = "demo"
}

resource "gridscale_sshkey" "demo" {
name = "demo"
sshkey = "INSERT KEY"
}

data "gridscale_template" "ubuntu" {
name = "Ubuntu 18.04 LTS"
}
16 changes: 0 additions & 16 deletions single-server/with-storage/server.tf

This file was deleted.

0 comments on commit 0eb6cdc

Please sign in to comment.