Skip to content

Commit

Permalink
chore: update registry index file, remove example
Browse files Browse the repository at this point in the history
This PR updates the readme that gets added to the terraform registry, as
well as removes the basic example and instead includes links to *all*
examples in the contrib repo.

Signed-off-by: Spencer Smith <[email protected]>
  • Loading branch information
rsmitty committed Jan 18, 2023
1 parent 158dbbd commit b7d84ba
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 352 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
dist
terraform-provider-talos
_out

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#*.tfvars
#*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
184 changes: 7 additions & 177 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,182 +6,12 @@ description: |-

# Talos Provider

Talos provider allows to generate configs for a Talos cluster and apply them to the nodes. bootstrap nodes and retrieve `kubeconfig` and `talosconfig`.
Talos provider allows to generate configs for a Talos cluster and apply them to the nodes, bootstrap nodes and retrieve `kubeconfig` and `talosconfig`.

A complete example usage is available at [basic example](https://github.com/siderolabs/terraform-provider-talos/tree/main/examples/basic)
Complete usages for this provider can be found at:

The same example is also rendered below:

`variables.tf`

```terraform
variable "cluster_name" {
description = "A name to provide for the Talos cluster"
type = string
}
variable "cluster_endpoint" {
description = "The endpoint for the Talos cluster"
type = string
}
variable "node_data" {
description = "A map of node data"
type = object({
controlplanes = map(object({
install_disk = string
hostname = optional(string)
}))
workers = map(object({
install_disk = string
hostname = optional(string)
}))
})
default = {
controlplanes = {
"10.5.0.2" = {
install_disk = "/dev/sda"
},
"10.5.0.3" = {
install_disk = "/dev/sda"
},
"10.5.0.4" = {
install_disk = "/dev/sda"
}
}
workers = {
"10.5.0.5" = {
install_disk = "/dev/nvme0n1"
hostname = "worker-1"
},
"10.5.0.6" = {
install_disk = "/dev/nvme0n1"
hostname = "worker-2"
}
}
}
}
```

`main.tf`

```terraform
terraform {
required_version = ">= 0.12"
experiments = [module_variable_optional_attrs]
required_providers {
talos = {
source = "siderolabs/talos"
}
}
}
provider "talos" {}
resource "talos_machine_secrets" "machine_secrets" {}
resource "talos_machine_configuration_controlplane" "machineconfig_cp" {
cluster_name = var.cluster_name
cluster_endpoint = var.cluster_endpoint
machine_secrets = talos_machine_secrets.machine_secrets.machine_secrets
}
resource "talos_machine_configuration_worker" "machineconfig_worker" {
cluster_name = var.cluster_name
cluster_endpoint = var.cluster_endpoint
machine_secrets = talos_machine_secrets.machine_secrets.machine_secrets
}
resource "talos_client_configuration" "talosconfig" {
cluster_name = var.cluster_name
machine_secrets = talos_machine_secrets.machine_secrets.machine_secrets
endpoints = [for k, v in var.node_data.controlplanes : k]
}
resource "talos_machine_configuration_apply" "cp_config_apply" {
talos_config = talos_client_configuration.talosconfig.talos_config
machine_configuration = talos_machine_configuration_controlplane.machineconfig_cp.machine_config
for_each = var.node_data.controlplanes
endpoint = each.key
node = each.key
config_patches = [
templatefile("${path.module}/templates/patch.yaml.tmpl", {
hostname = each.value.hostname == null ? format("%s-cp-%s", var.cluster_name, index(keys(var.node_data.workers), each.key)) : each.value.hostname
install_disk = each.value.install_disk
}),
file("${path.module}/files/patch.json"),
]
}
resource "talos_machine_configuration_apply" "worker_config_apply" {
talos_config = talos_client_configuration.talosconfig.talos_config
machine_configuration = talos_machine_configuration_worker.machineconfig_worker.machine_config
for_each = var.node_data.workers
endpoint = each.key
node = each.key
config_patches = [
templatefile("${path.module}/templates/patch.yaml.tmpl", {
hostname = each.value.hostname == null ? format("%s-cp-%s", var.cluster_name, index(keys(var.node_data.workers), each.key)) : each.value.hostname
install_disk = each.value.install_disk
})
]
}
resource "talos_machine_bootstrap" "bootstrap" {
talos_config = talos_client_configuration.talosconfig.talos_config
endpoint = [for k, v in var.node_data.controlplanes : k][0]
node = [for k, v in var.node_data.controlplanes : k][0]
}
resource "talos_cluster_kubeconfig" "kubeconfig" {
talos_config = talos_client_configuration.talosconfig.talos_config
endpoint = [for k, v in var.node_data.controlplanes : k][0]
node = [for k, v in var.node_data.controlplanes : k][0]
}
```

`outputs.tf`

```terraform
output "machineconfig_controlplane" {
value = talos_machine_configuration_controlplane.machineconfig_cp.machine_config
sensitive = true
}
output "machineconfig_worker" {
value = talos_machine_configuration_worker.machineconfig_worker.machine_config
sensitive = true
}
output "talosconfig" {
value = talos_client_configuration.talosconfig.talos_config
sensitive = true
}
output "kubeconfig" {
value = talos_cluster_kubeconfig.kubeconfig.kube_config
sensitive = true
}
```

`files/patch.json`

```json
[
{
"op": "add",
"path": "/cluster/allowSchedulingOnControlPlanes",
"value": true
}
]
```

`templates/patch.yaml.tmpl`

```yaml
machine:
install:
disk: ${install_disk}
network:
hostname: ${hostname}
```
- [AWS](https://github.com/siderolabs/contrib/tree/main/examples/terraform/aws)
- [Basic](https://github.com/siderolabs/contrib/tree/main/examples/terraform/basic)
- [Equinix Metal](https://github.com/siderolabs/contrib/tree/main/examples/terraform/equinix-metal)
- [Hetzner Cloud](https://github.com/siderolabs/contrib/tree/main/examples/terraform/hcloud)
- [Vultr](https://github.com/siderolabs/contrib/tree/main/examples/terraform/vultr)
3 changes: 0 additions & 3 deletions examples/basic/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions examples/basic/files/patch.json

This file was deleted.

72 changes: 0 additions & 72 deletions examples/basic/main.tf

This file was deleted.

19 changes: 0 additions & 19 deletions examples/basic/outputs.tf

This file was deleted.

5 changes: 0 additions & 5 deletions examples/basic/templates/patch.yaml.tmpl

This file was deleted.

46 changes: 0 additions & 46 deletions examples/basic/variables.tf

This file was deleted.

Loading

0 comments on commit b7d84ba

Please sign in to comment.