Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit b971b76

Browse files
author
KoLiBer
committed
feat: init project
0 parents  commit b971b76

File tree

9 files changed

+307
-0
lines changed

9 files changed

+307
-0
lines changed

.github/.releaserc.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tagFormat: $${q}{version}
2+
branches:
3+
- main
4+
- master
5+
- +([0-9])?(.{+([0-9]),x}).x
6+
- { name: next, prerelease: true }
7+
- { name: beta, prerelease: true }
8+
- { name: alpha, prerelease: true }
9+
- { name: stable, prerelease: true }
10+
plugins:
11+
- "@semantic-release/commit-analyzer"
12+
- "@semantic-release/release-notes-generator"
13+
- "@semantic-release/changelog"
14+
- "@semantic-release/github"
15+
- - "@semantic-release/git"
16+
- assets: [CHANGELOG.md]

.github/workflows/cicd.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI/CD
2+
3+
on:
4+
pull_request: { branches: ["*"] }
5+
push:
6+
branches:
7+
- "+([0-9])?(.{+([0-9]),x}).x"
8+
- master
9+
- main
10+
- next
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- uses: actions/setup-node@v2
20+
with:
21+
node-version: "17"
22+
- uses: hashicorp/setup-terraform@v1
23+
with:
24+
terraform_version: "1.1.4"
25+
- uses: actions/cache@v2
26+
with:
27+
path: .terraform/
28+
key: ${{ hashFiles('.terraform.lock.hcl') }}
29+
- uses: actions/cache@v2
30+
with:
31+
path: build/
32+
key: ${{ github.sha }}
33+
34+
- run: terraform init
35+
- run: terraform fmt -check
36+
- run: terraform validate -no-color
37+
- run: mkdir -p build && cp -R .terraform.lock.hcl *.tf build
38+
39+
test:
40+
needs: build
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v3
44+
45+
- run: echo CodeCoverage
46+
47+
release:
48+
needs: test
49+
runs-on: ubuntu-latest
50+
if: github.event_name == 'push'
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: actions/cache@v2
54+
with:
55+
path: build/
56+
key: ${{ github.sha }}
57+
58+
- run: npm i -g semantic-release @semantic-release/changelog @semantic-release/github @semantic-release/git
59+
- run: cat .github/.releaserc.yml | envsubst > .releaserc.yml && semantic-release
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# Crash log files
9+
crash.log
10+
11+
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
12+
# password, private keys, and other secrets. These should not be part of version
13+
# control as they are data points which are potentially sensitive and subject
14+
# to change depending on the environment.
15+
#
16+
*.tfvars
17+
18+
# Ignore override files as they are usually used to override resources locally and so
19+
# are not checked in
20+
override.tf
21+
override.tf.json
22+
*_override.tf
23+
*_override.tf.json
24+
25+
# Include override files you do wish to add to version control using negated pattern
26+
#
27+
# !example_override.tf
28+
29+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
30+
# example: *tfplan*
31+
32+
# Ignore CLI configuration files
33+
.terraformrc
34+
terraform.rc
35+
36+
# dotenv environment variables file
37+
.env

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022-present, KoLiBer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Terraform Module RKE
2+
3+
![pipeline](https://github.com/cktf/terraform-module-rke/actions/workflows/cicd.yml/badge.svg)
4+
![release](https://img.shields.io/github/v/release/cktf/terraform-module-rke?display_name=tag)
5+
![license](https://img.shields.io/github/license/cktf/terraform-module-rke)
6+
7+
**RKE** is a Terraform module useful for bootstraping **HA** kubernetes clusters using **k3s** and **rke2** on **Remote Machines**
8+
9+
## Installation
10+
11+
Add the required configurations to your terraform config file and install module using command bellow:
12+
13+
```bash
14+
terraform init
15+
```
16+
17+
## Usage
18+
19+
```hcl
20+
module "rke" {
21+
source = "cktf/rke/module"
22+
23+
masters = {
24+
1 = {
25+
connection = {
26+
type = "ssh"
27+
host = "192.168.172.185"
28+
port = 22
29+
user = "ubuntu"
30+
password = "ubuntu"
31+
}
32+
}
33+
}
34+
35+
nodes = {
36+
1 = {
37+
connection = {
38+
type = "ssh"
39+
host = "192.168.172.186"
40+
port = 22
41+
user = "ubuntu"
42+
password = "ubuntu"
43+
}
44+
}
45+
2 = {
46+
connection = {
47+
type = "ssh"
48+
host = "192.168.172.186"
49+
port = 22
50+
user = "ubuntu"
51+
password = "ubuntu"
52+
}
53+
}
54+
}
55+
}
56+
```
57+
58+
## Contributing
59+
60+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
61+
62+
Please make sure to update tests as appropriate.
63+
64+
## License
65+
66+
This project is licensed under the [MIT](LICENSE.md).
67+
Copyright (c) KoLiBer ([email protected])

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 0.14.0"
3+
required_providers {
4+
null = {
5+
source = "hashicorp/null"
6+
version = ">= 3.0.0"
7+
}
8+
}
9+
}

outputs.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
output "host" {
2+
depends_on = [data.k8sbootstrap_auth.this]
3+
4+
value = "https://${local.public_alb}:6443"
5+
sensitive = false
6+
description = "Cluster Host"
7+
}
8+
9+
output "token" {
10+
depends_on = [data.k8sbootstrap_auth.this]
11+
12+
value = "${random_string.token_id.result}.${random_string.token_secret.result}"
13+
sensitive = true
14+
description = "Cluster Token"
15+
}
16+
17+
output "ca_crt" {
18+
value = data.k8sbootstrap_auth.this.ca_crt
19+
sensitive = true
20+
description = "Cluster CA Certificate"
21+
}
22+
23+
output "kubeconfig" {
24+
value = data.k8sbootstrap_auth.this.kubeconfig
25+
sensitive = true
26+
description = "Cluster Kubernetes Config"
27+
}

script.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
resource "null_resource" "this" {
2+
triggers = {
3+
connection = jsonencode(var.connection)
4+
create = var.create
5+
destroy = var.destroy
6+
}
7+
8+
connection {
9+
type = try(jsondecode(self.triggers.connection).type, null)
10+
host = try(jsondecode(self.triggers.connection).host, null)
11+
port = try(jsondecode(self.triggers.connection).port, null)
12+
user = try(jsondecode(self.triggers.connection).user, null)
13+
password = try(jsondecode(self.triggers.connection).password, null)
14+
timeout = try(jsondecode(self.triggers.connection).timeout, null)
15+
script_path = try(jsondecode(self.triggers.connection).script_path, null)
16+
private_key = try(jsondecode(self.triggers.connection).private_key, null)
17+
certificate = try(jsondecode(self.triggers.connection).certificate, null)
18+
agent = try(jsondecode(self.triggers.connection).agent, null)
19+
agent_identity = try(jsondecode(self.triggers.connection).agent_identity, null)
20+
host_key = try(jsondecode(self.triggers.connection).host_key, null)
21+
https = try(jsondecode(self.triggers.connection).https, null)
22+
insecure = try(jsondecode(self.triggers.connection).insecure, null)
23+
use_ntlm = try(jsondecode(self.triggers.connection).use_ntlm, null)
24+
cacert = try(jsondecode(self.triggers.connection).cacert, null)
25+
bastion_host = try(jsondecode(self.triggers.connection).bastion_host, null)
26+
bastion_host_key = try(jsondecode(self.triggers.connection).bastion_host_key, null)
27+
bastion_port = try(jsondecode(self.triggers.connection).bastion_port, null)
28+
bastion_user = try(jsondecode(self.triggers.connection).bastion_user, null)
29+
bastion_password = try(jsondecode(self.triggers.connection).bastion_password, null)
30+
bastion_private_key = try(jsondecode(self.triggers.connection).bastion_private_key, null)
31+
bastion_certificate = try(jsondecode(self.triggers.connection).bastion_certificate, null)
32+
}
33+
34+
provisioner "remote-exec" {
35+
when = create
36+
inline = [
37+
"echo '${try(jsondecode(self.triggers.connection).password, "")}' | sudo -S -v",
38+
"echo ${base64encode(self.triggers.create)} | base64 -d | sudo sh"
39+
]
40+
}
41+
42+
provisioner "remote-exec" {
43+
when = destroy
44+
inline = [
45+
"echo '${try(jsondecode(self.triggers.connection).password, "")}' | sudo -S -v",
46+
"echo ${base64encode(self.triggers.destroy)} | base64 -d | sudo sh"
47+
]
48+
}
49+
}

variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "connection" {
2+
type = any
3+
default = {}
4+
sensitive = false
5+
description = "Script Connection"
6+
}
7+
8+
variable "create" {
9+
type = string
10+
default = ""
11+
sensitive = false
12+
description = "Script Create"
13+
}
14+
15+
variable "destroy" {
16+
type = string
17+
default = ""
18+
sensitive = false
19+
description = "Script Destroy"
20+
}

0 commit comments

Comments
 (0)