Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from rancher/import-k3s
Browse files Browse the repository at this point in the history
add import functionality
  • Loading branch information
drpebcak authored Oct 22, 2019
2 parents 88608d0 + 0de379a commit 4a7a3a2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This module supports creating a k3s cluster with a postgres backend in AWS. By d
| rancher\_chart | Helm chart to use for Rancher install | string | `"rancher-stable/rancher"` | no |
| rancher\_password | | string | n/a | yes |
| rancher\_version | Version of Rancher to install | string | `"2.3.1"` | no |
| registration\_command | Registration command to import cluster into Rancher. Should not be used when installing Rancher in this same cluster | string | `""` | no |
| server\_image\_id | AMI to use for k3s server instances | string | `"null"` | no |
| server\_instance\_ssh\_user | Username for sshing into instances | string | `"ubuntu"` | no |
| server\_instance\_type | | string | `"m5.large"` | no |
Expand Down
5 changes: 5 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ data "template_cloudinit_config" "k3s_server" {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/rancher-install.sh", { certmanager_version = local.certmanager_version, letsencrypt_email = local.letsencrypt_email, rancher_version = local.rancher_version, rancher_hostname = "${local.name}.${local.domain}", install_rancher = local.install_rancher, install_ingress = local.install_ingress, install_certmanager = local.install_certmanager })
}

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/register-to-rancher.sh", { is_k3s_server = true, install_rancher = local.install_rancher, registration_command = local.registration_command })
}
}

data "template_cloudinit_config" "k3s_agent" {
Expand Down
2 changes: 1 addition & 1 deletion files/k3s-install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

%{ if !is_k3s_server }
%{ if is_k3s_server }
curl -o ${storage_cafile} https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
%{ endif }

Expand Down
7 changes: 7 additions & 0 deletions files/register-to-rancher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

%{ if is_k3s_server }
%{ if !install_rancher }
${registration_command}
%{ endif }
%{ endif }
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ locals {
install_rancher = var.install_rancher
install_ingress = var.install_ingress
create_external_nlb = var.create_external_nlb ? 1 : 0
registration_command = var.registration_command
}

resource "random_password" "k3s_cluster_secret" {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,9 @@ variable "storage_cafile" {
type = string
description = "Location to download RDS CA Bundle"
}

variable "registration_command" {
default = ""
type = string
description = "Registration command to import cluster into Rancher. Should not be used when installing Rancher in this same cluster"
}

0 comments on commit 4a7a3a2

Please sign in to comment.