Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the civo instance documentation. Fixes issue #289 #299

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 103 additions & 27 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,81 @@ Provides a Civo instance resource. This can be used to create, modify, and delet

## Example Usage

* View instances after creation on the [CLI](https://www.civo.com/docs/overview/civo-cli):
```
civo instances ls
```
* View instances after creation on the [Dashboard](https://dashboard.civo.com/instances)
* View node sizes on [CLI](https://www.civo.com/docs/overview/civo-cli):

```
civo instances size
```

### Simple and smallest instance with its own network

```terraform
# Query small instance size
data "civo_instances_size" "small" {
filter {
provider "civo" {
region = "LON1"
}

resource "civo_firewall" "example" {
name = "example-firewall"
create_default_rules = true
network_id = civo_network.example.id

}

resource "civo_network" "example" {
label = "example-network"

}

# Query instance disk image
data "civo_disk_image" "debian" {
filter {
key = "name"
values = ["g3.small"]
match_by = "re"
}
values = ["debian-10"]
}
}

# Create a new instance
resource "civo_instance" "example" {
hostname = "example"
tags = ["example", "documentation"]
notes = "This is an example instance"
firewall_id = civo_firewall.example.id
network_id = civo_network.example.id
size = "g3.xsmall"
disk_image = data.civo_disk_image.debian.diskimages[0].id
}
```

With this configuration, an initial password for the instance gets written to the state on output `initial_password` which you can use to access the instance.

Alternative you can get the password with the [CLI](https://www.civo.com/docs/overview/civo-cli):

filter {
key = "type"
values = ["instance"]
}
```
civo instances show example
```

### Instance with ssh login

```terraform

provider "civo" {
region = "LON1"
}

resource "civo_firewall" "example" {
name = "example-firewall"
create_default_rules = true
network_id = civo_network.example.id

}

resource "civo_network" "example" {
label = "example-network"

}

Expand All @@ -36,18 +98,30 @@ data "civo_disk_image" "debian" {
}
}

# To create the example key, run this command:
# ssh-keygen -f ~/.ssh/example-tf -C "terraform-example@localmachine"

resource "civo_ssh_key" "example"{
name = "example"
public_key = file("~/.ssh/example-tf.pub")
}

# Create a new instance
resource "civo_instance" "foo" {
hostname = "foo.com"
tags = ["python", "nginx"]
notes = "this is a note for the server"
size = element(data.civo_instances_size.small.sizes, 0).name
disk_image = element(data.civo_disk_image.debian.diskimages, 0).id
resource "civo_instance" "example" {
hostname = "example"
tags = ["example", "documentation"]
notes = "This is an example instance"
sshkey_id = civo_ssh_key.example.id
firewall_id = civo_firewall.example.id
network_id = civo_network.example.id
size = "g3.xsmall"
disk_image = data.civo_disk_image.debian.diskimages[0].id
}

```

<!-- schema generated by tfplugindocs -->
## Schema

## Argument Reference

### Required

Expand All @@ -69,10 +143,17 @@ resource "civo_instance" "foo" {
- `size` (String) The name of the size, from the current list, e.g. g3.xsmall
- `sshkey_id` (String) The ID of an already uploaded SSH public key to use for login to the default user (optional; if one isn't provided a random password will be set and returned in the initial_password field)
- `tags` (Set of String) An optional list of tags, represented as a key, value pair
- `template` (String, Deprecated) The ID for the template to use to build the instance
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) defines timeouts for cluster creation, read and update, default is 30 minutes for all

### Read-Only

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String) sets timeout for cluster creation - default 30 minutes

## Attributes Reference

- `cpu_cores` (Number) Instance's CPU cores
- `created_at` (String) Timestamp when the instance was created
Expand All @@ -86,18 +167,13 @@ resource "civo_instance" "foo" {
- `source_type` (String) Instance's source type
- `status` (String) Instance's status

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String)

## Import

Import is supported using the following syntax:

```shell
# using ID
terraform import civo_instance.myintance 18bd98ad-1b6e-4f87-b48f-e690b4fd7413
terraform import civo_instance.example 18bd98ad-1b6e-4f87-b48f-e690b4fd7413
```
Loading