-
Notifications
You must be signed in to change notification settings - Fork 0
initial terraform-provider-bluechi implementation #1
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .vscode/ | ||
| terraform-provider-bluechi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| HOSTNAME=registry.terraform.io | ||
| NAMESPACE=bluechi | ||
| NAME=bluechi | ||
| BINARY=terraform-provider-${NAME} | ||
| VERSION=0.1.0 | ||
| OS_ARCH=linux_amd64 | ||
| INSTALLDIR=~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} | ||
|
|
||
| SOURCES = $(shell find . -path './.*' -prune -o \( \( -name '*.go' \) -a ! -name '*_test.go' \) -print) | ||
|
|
||
| .PHONY: default | ||
| default: all | ||
|
|
||
| .PHONY: all | ||
| all: install | ||
|
|
||
| .PHONY: build | ||
| build: ${BINARY} | ||
|
|
||
| .PHONY: ${BINARY} | ||
| ${BINARY}: ${SOURCES} go.mod go.sum | ||
| go build -o ${BINARY} | ||
|
|
||
| .PHONY: install | ||
| install: ${BINARY} | ||
| mkdir -p ${INSTALLDIR} | ||
| cp ${BINARY} ${INSTALLDIR} | ||
|
|
||
| uninstall: | ||
| rm -f ${INSTALLDIR}/${BINARY} | ||
|
|
||
| clean: uninstall | ||
| rm -f ${BINARY} | ||
|
|
||
| test: | ||
| bash container/container-setup.sh start bluechi | ||
| TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m | ||
| bash container/container-setup.sh stop | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| # terraform-provider-bluechi | ||
| Terraform provider for setting up systems with BlueChi | ||
| # Terraform Provider for BlueChi | ||
|
|
||
| This terraform provider can be used to setup a multi-node system to be controlled via [BlueChi](https://github.com/containers/bluechi/). | ||
|
|
||
| For examples on how to use this provider, please refer to the [examples](./examples/) directory which contains examples to: | ||
|
|
||
| - [setup multiple containers with BlueChi](./examples/resources/bluechi_plain_ssh/) | ||
| - [setup AWS EC2 instances with BlueChi](./examples/resources/bluechi_with_aws/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| FROM quay.io/centos/centos:stream9 | ||
|
|
||
| RUN dnf upgrade --refresh -y --nodocs && \ | ||
| dnf install --nodocs \ | ||
| policycoreutils-python-utils \ | ||
| python3-dasbus \ | ||
| selinux-policy \ | ||
| systemd \ | ||
| systemd-devel \ | ||
| openssh-server \ | ||
| openssh-clients \ | ||
| dnf-plugin-config-manager \ | ||
| -y && \ | ||
| dnf -y clean all | ||
|
|
||
| RUN dnf copr enable -y @centos-automotive-sig/bluechi-snapshot | ||
| RUN dnf install \ | ||
| --nogpgcheck \ | ||
| --nodocs \ | ||
| bluechi \ | ||
| bluechi-debuginfo \ | ||
| bluechi-agent \ | ||
| bluechi-agent-debuginfo \ | ||
| bluechi-ctl \ | ||
| bluechi-ctl-debuginfo \ | ||
| bluechi-selinux \ | ||
| python3-bluechi \ | ||
| -y && \ | ||
| dnf -y clean all | ||
|
|
||
| RUN systemctl enable sshd | ||
|
|
||
| CMD [ "/sbin/init" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| FROM quay.io/centos/centos:stream9 | ||
|
|
||
| RUN dnf upgrade --refresh -y --nodocs && \ | ||
| dnf install --nodocs \ | ||
| policycoreutils-python-utils \ | ||
| selinux-policy \ | ||
| systemd \ | ||
| systemd-devel \ | ||
| openssh-server \ | ||
| openssh-clients \ | ||
| dnf-plugin-config-manager \ | ||
| -y && \ | ||
| dnf -y clean all | ||
|
|
||
| RUN systemctl enable sshd | ||
|
|
||
| CMD [ "/sbin/init" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/bin/bash -xe | ||
|
|
||
| PUBKEYPATH=~/.ssh/id_rsa.pub | ||
| PUBKEY=$( cat $PUBKEYPATH ) | ||
|
|
||
| SCRIPT_DIR=$( realpath "$0" ) | ||
| SCRIPT_DIR=$(dirname "$SCRIPT_DIR") | ||
|
|
||
| CONTAINER_NAMES=(main worker1 worker2 worker3) | ||
|
|
||
| function build_image(){ | ||
| if [[ "$1" == "bluechi" ]]; then | ||
| podman build -t localhost/bluechi -f $SCRIPT_DIR/bluechi.image | ||
| elif [[ "$1" == "centos" ]]; then | ||
| podman build -t localhost/centos -f $SCRIPT_DIR/centos.image | ||
| else | ||
| echo "Unknown image: '$1'" | ||
| fi | ||
| } | ||
|
|
||
| function start(){ | ||
| if [[ "$1" != "bluechi" && "$1" != "centos" ]]; then | ||
| echo "Unknown container image: '$1'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| port=2020 | ||
| for name in ${CONTAINER_NAMES[@]}; do | ||
| # start all containers | ||
| podman run -dt --rm --name $name --network host localhost/$1:latest | ||
| # inject public key | ||
| podman exec $name bash -c "echo $PUBKEY >> ~/.ssh/authorized_keys" | ||
| # change the port for the ssh config | ||
| podman exec $name bash -c "echo 'Port $port' >> /etc/ssh/sshd_config" | ||
| podman exec $name bash -c "systemctl restart sshd" | ||
| let port++ | ||
| done | ||
| } | ||
|
|
||
| function stop() { | ||
| for name in ${CONTAINER_NAMES[@]}; do | ||
| podman stop $name | ||
| done | ||
| } | ||
|
|
||
| $1 $2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| terraform { | ||
| required_providers { | ||
| bluechi = { | ||
| source = "bluechi/bluechi" | ||
| version = "0.1.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "bluechi" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| This example requires a container setup as provided by [container-setup.sh](../../../container/container-setup.sh): | ||
|
|
||
| ```bash | ||
| # build image with bluechi pre-installed or | ||
| $ bash container/container-setup.sh build_image bluechi | ||
| # use a plain centos container without bluechi | ||
| $ bash container/container-setup.sh build_image centos | ||
|
|
||
| # start all container, bluechi isn't setup, yet | ||
| $ bash container/container-setup.sh start bluechi | ||
|
|
||
| # build and install terraform-provider-bluechi | ||
| $ make install | ||
|
|
||
| # apply the terraform example | ||
| $ cd examples/resources/bluechi_plain_ssh/ | ||
| $ tf init | ||
| $ tf apply | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| terraform { | ||
| required_providers { | ||
| bluechi = { | ||
| source = "bluechi/bluechi" | ||
| version = "0.1.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "bluechi" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| resource "bluechi_node" "main" { | ||
|
|
||
| ssh = { | ||
| host = "127.0.0.1:2020" | ||
| user = "root" | ||
| password = "" | ||
| private_key_path = "~/.ssh/id_rsa" | ||
| accept_host_key_insecure = true | ||
| } | ||
|
|
||
| bluechi_controller = { | ||
| allowed_node_names = [ | ||
| "main", "worker1", "worker2", "worker3", | ||
| ] | ||
| manager_port = 3030 | ||
| log_level = "DEBUG" | ||
| log_target = "stderr-full" | ||
| log_is_quiet = false | ||
| } | ||
|
|
||
| bluechi_agent = { | ||
| node_name = "main" | ||
| manager_host = "127.0.0.1" | ||
| manager_port = 3030 | ||
| manager_address = "" | ||
| heartbeat_interval = 5000 | ||
| log_level = "DEBUG" | ||
| log_target = "stderr-full" | ||
| log_is_quiet = false | ||
| } | ||
| } | ||
|
|
||
| resource "bluechi_node" "worker1" { | ||
|
|
||
| ssh = { | ||
| host = "127.0.0.1:2021" | ||
| user = "root" | ||
| password = "" | ||
| private_key_path = "~/.ssh/id_rsa" | ||
| accept_host_key_insecure = true | ||
| } | ||
|
|
||
| bluechi_agent = { | ||
| node_name = "worker1" | ||
| manager_host = "127.0.0.1" | ||
| manager_port = 3030 | ||
| manager_address = "" | ||
| heartbeat_interval = 5000 | ||
| log_level = "DEBUG" | ||
| log_target = "stderr-full" | ||
| log_is_quiet = false | ||
| } | ||
| } | ||
|
|
||
| resource "bluechi_node" "worker2" { | ||
|
|
||
| ssh = { | ||
| host = "127.0.0.1:2022" | ||
| user = "root" | ||
| password = "" | ||
| private_key_path = "~/.ssh/id_rsa" | ||
| accept_host_key_insecure = true | ||
| } | ||
|
|
||
| bluechi_agent = { | ||
| node_name = "worker2" | ||
| manager_host = "127.0.0.1" | ||
| manager_port = 3030 | ||
| manager_address = "" | ||
| heartbeat_interval = 5000 | ||
| log_level = "DEBUG" | ||
| log_target = "stderr-full" | ||
| log_is_quiet = false | ||
| } | ||
| } | ||
|
|
||
| resource "bluechi_node" "worker3" { | ||
|
|
||
| ssh = { | ||
| host = "127.0.0.1:2023" | ||
| user = "root" | ||
| password = "" | ||
| private_key_path = "~/.ssh/id_rsa" | ||
| accept_host_key_insecure = true | ||
| } | ||
|
|
||
| bluechi_agent = { | ||
| node_name = "worker3" | ||
| manager_host = "127.0.0.1" | ||
| manager_port = 3030 | ||
| manager_address = "" | ||
| heartbeat_interval = 5000 | ||
| log_level = "DEBUG" | ||
| log_target = "stderr-full" | ||
| log_is_quiet = false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.