Skip to content

Commit

Permalink
Update documentation, examples. Fix templates used for tfplugindocs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Mar 5, 2023
1 parent 9114df7 commit c54edaf
Show file tree
Hide file tree
Showing 36 changed files with 745 additions and 152 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ run:
- Makefile
- README.md
- Dockerfile
- rancherk3d/resource_cluster.go
- rancherk3d/data_source.go

severity:
default-severity: error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_cluster_list Data Source - terraform-provider-k3d"
page_title: "k3d_cluster_list Data Source - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_cluster_list (Data Source)
# k3d_cluster_list (Data Source)



Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_kubeconfig Data Source - terraform-provider-k3d"
page_title: "k3d_kubeconfig Data Source - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_kubeconfig (Data Source)
# k3d_kubeconfig (Data Source)



Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_node_list Data Source - terraform-provider-k3d"
page_title: "k3d_node_list Data Source - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_node_list (Data Source)
# k3d_node_list (Data Source)



Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_registry_list Data Source - terraform-provider-k3d"
page_title: "k3d_registry_list Data Source - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_registry_list (Data Source)
# k3d_registry_list (Data Source)



Expand Down
42 changes: 41 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,51 @@ description: |-
---

# k3d Provider
# K3D Provider
A provider which is an alternative to k3d cli, this helps in creating a throw away kubernetes cluster using k3d.
The provider `terraform-provider-k3d` covers almost every task that one can accomplish with `k3d cli` with no `k3d` installed.

## Example Usage
```terraform
terraform {
required_providers {
k3d = {
source = "hashicorp/k3d"
version = "0.1.3"
}
}
}
// Configure GoCD Provider
provider "k3d" {
// if no image is passed while creating cluster attribute `kubernetes_version` and `registry` would be used to construct an image name.
kubernetes_version = "1.24.4-k3s1"
k3d_api_version = "k3d.io/v1alpha4"
registry = "rancher/k3s"
kind = "Simple"
runtime = "docker"
}
// Create node under already created cluster
resource "k3d_node_create" "node-1" {
name = "sample-node-2"
cluster = "sample-cluster"
role = "agent"
replicas = 1
memory = "8g"
// wait = false
// timeout = 1
}
```

## K3D Provider configurations
All parameters which is used by the providers has the environment variable support.
Environment Variables:
- `KUBERNETES_VERSION`
- `K3D_REGISTRY`
- `K3D_API_VERSION`
- `K3D_KIND`
- `K3D_RUNTIME`

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_cluster_action Resource - terraform-provider-k3d"
page_title: "k3d_cluster_action Resource - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_cluster_action (Resource)

# k3d_cluster_action (Resource)
Helps in stopping or stating a specific cluster ot a list of clusters

```terraform
resource "k3d_cluster_action" "start-k3s-cluster" {
depends_on = [
k3d_cluster_action.stop-k3s-cluster,
]
clusters = ["k3s-default"]
start = true
}
```



Expand Down
217 changes: 217 additions & 0 deletions docs/resources/cluster_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "k3d_cluster_create Resource - terraform-provider-k3d"
subcategory: ""
description: |-
---

# k3d_cluster_create (Resource)
Creates a k3d cluster with all below passed configuration by leveraging k3d golang [code](github.com/k3d-io/k3d/v5).
The below attributes are terraform translated k3d [config.yaml](https://k3d.io/v5.4.7/usage/configfile/) which would used while creating cluster via cli `k3d cluster create --config /path/to/cluster-config.yaml`.

```terraform
resource "k3d_cluster_create" "sample_cluster" {
name = "default"
servers_count = 1
agents_count = 2
// image = "rancher/k3s:v1.24.4-k3s1"
kube_api {
host_ip = "0.0.0.0"
host_port = 6445
}
//
// ports {
// host_port = 8080
// container_port = 80
// node_filters = [
// "loadbalancer",
// ]
// }
k3d_options {
no_loadbalancer = false
no_image_volume = false
}
kube_config {
update_default = true
switch_context = true
}
}
```



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

### Optional

- `agents_count` (Number) Count of agents in the cluster
- `cluster_token` (String, Sensitive) superSecretToken to be used
- `config_yaml` (String)
- `env` (Block Set) Environment variables to be added nodes. (see [below for nested schema](#nestedblock--env))
- `host_aliases` (Block Set) /etc/hosts style entries to be injected into /etc/hosts in the node containers and in the NodeHosts section in CoreDNS. (see [below for nested schema](#nestedblock--host_aliases))
- `image` (String) Image name to be used for creation of cluster, it would be used along with kubernetes_version
- `k3d_options` (Block Set) k3d runtime settings (see [below for nested schema](#nestedblock--k3d_options))
- `k3s_options` (Block Set) Options passed on to K3s itself (see [below for nested schema](#nestedblock--k3s_options))
- `kube_api` (Block Set, Max: 1) same as `--api-port myhost.my.domain:6445` (where the name would resolve to 127.0.0.1) (see [below for nested schema](#nestedblock--kube_api))
- `kube_config` (Block Set) Way to manage the kubeconfig generated after creating k3d clusters. (see [below for nested schema](#nestedblock--kube_config))
- `name` (String) Name of the Cluster to be created
- `network` (String) Network to be associated with the cluster
- `ports` (Block Set) Map ports from the node containers (via the serverlb) to the host (Format: [HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]) (see [below for nested schema](#nestedblock--ports))
- `registries` (Block Set) Define how registries should be created or used (see [below for nested schema](#nestedblock--registries))
- `runtime` (Block Set, Max: 1) Runtime options for k3d (see [below for nested schema](#nestedblock--runtime))
- `servers_count` (Number) Count of servers
- `subnetwork` (String) Define a subnet for the newly created container network
- `volumes` (Block Set) Mount volumes into the nodes (Format: [SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]] (see [below for nested schema](#nestedblock--volumes))

### Read-Only

- `id` (String) The ID of this resource.

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

Optional:

- `extra_args` (String)
- `key` (String) key of key-value pair
- `node_filters` (List of String)
- `value` (String) value of key-value pair


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

Optional:

- `hostnames` (List of String) list of hosts names mapped to an IP
- `ip` (String) ip address to which the list of hostnames to be mapped


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

Optional:

- `loadbalancer_config_overrides` (List of String) Use dotted YAML path syntax to override nginx loadbalancer settings
- `no_image_volume` (Boolean) Disable the creation of a volume for importing images.
- `no_loadbalancer` (Boolean) Disable the creation of a LoadBalancer in front of the server nodes.
- `no_rollback` (Boolean) Disable the automatic rollback actions, if anything goes wrong.
- `timeout` (String) Rollback changes if cluster couldn't be created in specified duration.
- `wait` (Boolean) Wait for the server(s) to be ready before returning. Use '--timeout DURATION' to not wait forever. (default true).


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

Optional:

- `extra_args` (Block List) additional arguments passed to the `k3s server|agent` command; same as `--k3s-arg` (see [below for nested schema](#nestedblock--k3s_options--extra_args))
- `node_labels` (Block List) same as `--k3s-node-label 'foo=bar@agent:1'` -> this results in a Kubernetes node label (see [below for nested schema](#nestedblock--k3s_options--node_labels))

<a id="nestedblock--k3s_options--extra_args"></a>
### Nested Schema for `k3s_options.extra_args`

Optional:

- `extra_args` (String)
- `key` (String) key of key-value pair
- `node_filters` (List of String)
- `value` (String) value of key-value pair


<a id="nestedblock--k3s_options--node_labels"></a>
### Nested Schema for `k3s_options.node_labels`

Optional:

- `extra_args` (String)
- `key` (String) key of key-value pair
- `node_filters` (List of String)
- `value` (String) value of key-value pair



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

Optional:

- `host` (String) Important for the `server` setting in the kubeconfig.
- `host_ip` (String) Where the Kubernetes API will be listening on.
- `host_port` (Number) Specify the Kubernetes API server port exposed on the LoadBalancer.


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

Optional:

- `switch_context` (Boolean) Directly switch the default kubeconfig's current-context to the new cluster's context
- `update_default` (Boolean) Directly update the default kubeconfig with the new cluster's context.


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

Required:

- `container_port` (Number)

Optional:

- `host` (String)
- `host_port` (Number)
- `node_filters` (List of String)
- `protocol` (String)


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

Optional:

- `config` (String) define contents of the `registries.yaml` file (or reference a file); same as `--registry-config /path/to/config.yaml`
- `create` (Boolean) creates a default registry to be used with the cluster
- `use` (List of String) some other k3d-managed registry


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

Optional:

- `agents_memory` (String) Memory limit imposed on the agents nodes [From docker]
- `gpu_request` (String) GPU devices to add to the cluster node containers ('all' to pass all GPUs) [From docker].
- `host_pid_mode` (Boolean) Enable host pid mode of server(s) and agent(s)
- `labels` (Block List) Labels to be added node container. (see [below for nested schema](#nestedblock--runtime--labels))
- `servers_memory` (String) Memory limit imposed on the server nodes [From docker]

<a id="nestedblock--runtime--labels"></a>
### Nested Schema for `runtime.labels`

Optional:

- `extra_args` (String)
- `key` (String) key of key-value pair
- `node_filters` (List of String)
- `value` (String) value of key-value pair



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

Required:

- `destination` (String) Destination path for the volume

Optional:

- `node_filters` (List of String)
- `source` (String) Source path of volume mount


Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "rancherk3d_connect_registry Resource - terraform-provider-k3d"
page_title: "k3d_connect_registry Resource - terraform-provider-k3d"
subcategory: ""
description: |-
---

# rancherk3d_connect_registry (Resource)


# k3d_connect_registry (Resource)
Connects or disconnects already created registry from the specified cluster.

```terraform
resource "k3d_connect_registry" "k3s-registry-1" {
registries = [k3d_create_registry.registry-1.host]
cluster = "k3s-default"
connect = true
}
```


<!-- schema generated by tfplugindocs -->
Expand Down
Loading

0 comments on commit c54edaf

Please sign in to comment.