diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a67a0a8 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +HOSTNAME=registry.terraform.io +NAMESPACE=bluechi +NAME=bluechi +BINARY=terraform-provider-${NAME} +VERSION=1.0.0 +OS_ARCH=linux_amd64 +INSTALLDIR=~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} + +.PHONY: default +default: all + +.PHONY: all +all: install + +.PHONY: ${BINARY} +${BINARY}: + 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 diff --git a/README.md b/README.md index c7f8953..45460a2 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/container/bluechi.image b/container/bluechi.image new file mode 100644 index 0000000..cea69b4 --- /dev/null +++ b/container/bluechi.image @@ -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" ] diff --git a/container/centos.image b/container/centos.image new file mode 100644 index 0000000..0062485 --- /dev/null +++ b/container/centos.image @@ -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" ] diff --git a/container/container-setup.sh b/container/container-setup.sh new file mode 100644 index 0000000..d117eb4 --- /dev/null +++ b/container/container-setup.sh @@ -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 diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf new file mode 100644 index 0000000..26257c6 --- /dev/null +++ b/examples/provider/provider.tf @@ -0,0 +1,11 @@ +terraform { + required_providers { + bluechi = { + source = "bluechi/bluechi" + } + } +} + +provider "bluechi" { + use_mock = var.use_mock +} diff --git a/examples/provider/variables.tf b/examples/provider/variables.tf new file mode 100644 index 0000000..d50b837 --- /dev/null +++ b/examples/provider/variables.tf @@ -0,0 +1,4 @@ +variable "use_mock" { + type = bool + default = true +} diff --git a/examples/resources/bluechi_plain_ssh/README.md b/examples/resources/bluechi_plain_ssh/README.md new file mode 100644 index 0000000..aecc9f0 --- /dev/null +++ b/examples/resources/bluechi_plain_ssh/README.md @@ -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 +``` diff --git a/examples/resources/bluechi_plain_ssh/provider.tf b/examples/resources/bluechi_plain_ssh/provider.tf new file mode 100644 index 0000000..2b634ad --- /dev/null +++ b/examples/resources/bluechi_plain_ssh/provider.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + bluechi = { + source = "bluechi/bluechi" + version = "1.0.0" + } + } +} + +provider "bluechi" { + use_mock = var.use_mock +} diff --git a/examples/resources/bluechi_plain_ssh/resource.tf b/examples/resources/bluechi_plain_ssh/resource.tf new file mode 100644 index 0000000..8d99f4d --- /dev/null +++ b/examples/resources/bluechi_plain_ssh/resource.tf @@ -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 + } +} diff --git a/examples/resources/bluechi_plain_ssh/variables.tf b/examples/resources/bluechi_plain_ssh/variables.tf new file mode 100644 index 0000000..747f795 --- /dev/null +++ b/examples/resources/bluechi_plain_ssh/variables.tf @@ -0,0 +1,4 @@ +variable "use_mock" { + type = bool + default = false +} diff --git a/examples/resources/bluechi_with_aws/aws_resource.tf b/examples/resources/bluechi_with_aws/aws_resource.tf new file mode 100644 index 0000000..26bc4ac --- /dev/null +++ b/examples/resources/bluechi_with_aws/aws_resource.tf @@ -0,0 +1,125 @@ +resource "aws_vpc" "autosd_demo_vpc" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "autosd-demo-vpc" + } +} + +resource "aws_subnet" "autosd_demo_subnet_public" { + vpc_id = aws_vpc.autosd_demo_vpc.id + cidr_block = "10.0.1.0/24" + availability_zone = "us-east-2a" + + tags = { + Name = "autosd-demo-subnet-public" + } +} + +resource "aws_subnet" "autosd_demo_subnet_private" { + vpc_id = aws_vpc.autosd_demo_vpc.id + cidr_block = "10.0.2.0/24" + availability_zone = "us-east-2a" + + tags = { + Name = "autosd-demo-subnet-private" + } +} + +resource "aws_internet_gateway" "autosd_demo_ig" { + vpc_id = aws_vpc.autosd_demo_vpc.id + + tags = { + Name = "autosd-demo-ig" + } +} + +resource "aws_route_table" "autosd_demo_rt" { + vpc_id = aws_vpc.autosd_demo_vpc.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.autosd_demo_ig.id + } + + route { + ipv6_cidr_block = "::/0" + gateway_id = aws_internet_gateway.autosd_demo_ig.id + } + + tags = { + Name = "autosd-demo-rt" + } +} + +resource "aws_route_table_association" "public_1_rt_a" { + subnet_id = aws_subnet.autosd_demo_subnet_public.id + route_table_id = aws_route_table.autosd_demo_rt.id +} + +resource "aws_security_group" "autosd_demo_sg" { + name = "autosd-demo-sg" + vpc_id = aws_vpc.autosd_demo_vpc.id + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = var.bluechi_manager_port + to_port = var.bluechi_manager_port + protocol = "tcp" + cidr_blocks = [aws_vpc.autosd_demo_vpc.cidr_block] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_key_pair" "bluechi" { + key_name = "bluechi-key" + public_key = file(var.ssh_key_pair[0]) +} + +resource "aws_instance" "ec2main" { + ami = var.autosd_ami + instance_type = var.instance_type + key_name = aws_key_pair.bluechi.id + + subnet_id = aws_subnet.autosd_demo_subnet_public.id + vpc_security_group_ids = [aws_security_group.autosd_demo_sg.id] + associate_public_ip_address = true + + tags = { + Platform = "AutoSD" + } +} + +resource "aws_instance" "ec2worker1" { + ami = var.autosd_ami + instance_type = var.instance_type + key_name = aws_key_pair.bluechi.id + + subnet_id = aws_subnet.autosd_demo_subnet_public.id + vpc_security_group_ids = [aws_security_group.autosd_demo_sg.id] + associate_public_ip_address = true + + tags = { + Platform = "AutoSD" + } +} + +output "ec2main_public_ip" { + value = aws_instance.ec2main.public_ip +} + +output "ec2worker1_public_ip" { + value = aws_instance.ec2worker1.public_ip +} diff --git a/examples/resources/bluechi_with_aws/bluechi_resource.tf b/examples/resources/bluechi_with_aws/bluechi_resource.tf new file mode 100644 index 0000000..bf1e89a --- /dev/null +++ b/examples/resources/bluechi_with_aws/bluechi_resource.tf @@ -0,0 +1,57 @@ +resource "bluechi_node" "main" { + + depends_on = [aws_internet_gateway.autosd_demo_ig] + + ssh = { + host = "${aws_instance.ec2main.*.public_ip[0]}:22" + user = var.ssh_user + password = "" + private_key_path = var.ssh_key_pair[1] + accept_host_key_insecure = true + } + + bluechi_controller = { + allowed_node_names = [ + var.bluechi_nodes[0], var.bluechi_nodes[1], + ] + manager_port = var.bluechi_manager_port + log_level = "DEBUG" + log_target = "stderr-full" + log_is_quiet = false + } + + bluechi_agent = { + node_name = var.bluechi_nodes[0] + manager_host = "127.0.0.1" + manager_port = var.bluechi_manager_port + manager_address = "" + heartbeat_interval = 5000 + log_level = "DEBUG" + log_target = "stderr-full" + log_is_quiet = false + } +} + +resource "bluechi_node" "worker1" { + + depends_on = [aws_internet_gateway.autosd_demo_ig] + + ssh = { + host = "${aws_instance.ec2worker1.*.public_ip[0]}:22" + user = var.ssh_user + password = "" + private_key_path = var.ssh_key_pair[1] + accept_host_key_insecure = true + } + + bluechi_agent = { + node_name = var.bluechi_nodes[1] + manager_host = "${aws_instance.ec2main.*.private_ip[0]}" + manager_port = var.bluechi_manager_port + manager_address = "" + heartbeat_interval = 5000 + log_level = "DEBUG" + log_target = "stderr-full" + log_is_quiet = false + } +} diff --git a/examples/resources/bluechi_with_aws/provider.tf b/examples/resources/bluechi_with_aws/provider.tf new file mode 100644 index 0000000..37c870f --- /dev/null +++ b/examples/resources/bluechi_with_aws/provider.tf @@ -0,0 +1,23 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.16" + } + + bluechi = { + source = "bluechi/bluechi" + version = "1.0.0" + } + } + + required_version = ">= 1.2.0" +} + +provider "aws" { + region = "us-east-2" +} + +provider "bluechi" { + use_mock = var.use_mock +} diff --git a/examples/resources/bluechi_with_aws/variables.tf b/examples/resources/bluechi_with_aws/variables.tf new file mode 100644 index 0000000..e4b17c9 --- /dev/null +++ b/examples/resources/bluechi_with_aws/variables.tf @@ -0,0 +1,44 @@ +/*********************/ +/* Variables for AWS */ +/*********************/ + +# tuple(public key path, private key path) +variable "ssh_key_pair" { + type = tuple([string, string]) + default = ["~/.ssh/bluechi_aws.pub", "~/.ssh/bluechi_aws"] +} + +variable "ssh_user" { + type = string + default = "ec2-user" +} + +# Developer AMI, changes frequently +variable "autosd_ami" { + type = string + default = "ami-0b2337f1f6379076e" +} + +variable "instance_type" { + type = string + default = "t3a.micro" +} + +/*************************/ +/* Variables for BlueChi */ +/*************************/ + +variable "use_mock" { + type = bool + default = false +} + +variable "bluechi_manager_port" { + type = number + default = 3030 +} + +variable "bluechi_nodes" { + type = list(string) + default = ["main", "worker1"] +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c716196 --- /dev/null +++ b/go.mod @@ -0,0 +1,60 @@ +module github.com/eclipse-bluechi/terraform-provider-bluechi + +go 1.21.1 + +require ( + github.com/hashicorp/go-uuid v1.0.3 + github.com/hashicorp/terraform-plugin-framework v1.4.1 + github.com/hashicorp/terraform-plugin-go v0.19.0 + github.com/hashicorp/terraform-plugin-log v0.9.0 + github.com/hashicorp/terraform-plugin-testing v1.5.1 + golang.org/x/crypto v0.13.0 +) + +require ( + github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/agext/levenshtein v1.2.2 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/fatih/color v1.13.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-checkpoint v0.5.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-plugin v1.5.1 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect + github.com/hashicorp/hc-install v0.6.0 // indirect + github.com/hashicorp/hcl/v2 v2.18.0 // indirect + github.com/hashicorp/logutils v1.0.0 // indirect + github.com/hashicorp/terraform-exec v0.19.0 // indirect + github.com/hashicorp/terraform-json v0.17.1 // indirect + github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 // indirect + github.com/hashicorp/terraform-registry-address v0.2.2 // indirect + github.com/hashicorp/terraform-svchost v0.1.1 // indirect + github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/mitchellh/go-wordwrap v1.0.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/oklog/run v1.0.0 // indirect + github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect + github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect + github.com/zclconf/go-cty v1.14.0 // indirect + golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.13.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect + google.golang.org/grpc v1.57.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8b5a7cb --- /dev/null +++ b/go.sum @@ -0,0 +1,229 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= +github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= +github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= +github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= +github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= +github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= +github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= +github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= +github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-plugin v1.5.1 h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k= +github.com/hashicorp/go-plugin v1.5.1/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hc-install v0.6.0 h1:fDHnU7JNFNSQebVKYhHZ0va1bC6SrPQ8fpebsvNr2w4= +github.com/hashicorp/hc-install v0.6.0/go.mod h1:10I912u3nntx9Umo1VAeYPUUuehk0aRQJYpMwbX5wQA= +github.com/hashicorp/hcl/v2 v2.18.0 h1:wYnG7Lt31t2zYkcquwgKo6MWXzRUDIeIVU5naZwHLl8= +github.com/hashicorp/hcl/v2 v2.18.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM= +github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg= +github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= +github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-plugin-framework v1.4.1 h1:ZC29MoB3Nbov6axHdgPbMz7799pT5H8kIrM8YAsaVrs= +github.com/hashicorp/terraform-plugin-framework v1.4.1/go.mod h1:XC0hPcQbBvlbxwmjxuV/8sn8SbZRg4XwGMs22f+kqV0= +github.com/hashicorp/terraform-plugin-go v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU= +github.com/hashicorp/terraform-plugin-go v0.19.0/go.mod h1:EhRSkEPNoylLQntYsk5KrDHTZJh9HQoumZXbOGOXmec= +github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= +github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 h1:wcOKYwPI9IorAJEBLzgclh3xVolO7ZorYd6U1vnok14= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0/go.mod h1:qH/34G25Ugdj5FcM95cSoXzUgIbgfhVLXCcEcYaMwq8= +github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c= +github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0= +github.com/hashicorp/terraform-registry-address v0.2.2 h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno= +github.com/hashicorp/terraform-registry-address v0.2.2/go.mod h1:LtwNbCihUoUZ3RYriyS2wF/lGPB6gF9ICLRtuDk7hSo= +github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= +github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= +github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= +github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc= +github.com/zclconf/go-cty v1.14.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= +golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/client/bluechi.go b/internal/client/bluechi.go new file mode 100644 index 0000000..e19f014 --- /dev/null +++ b/internal/client/bluechi.go @@ -0,0 +1,74 @@ +package client + +import ( + "strconv" + "strings" +) + +const ( + BlueChiControllerConfdDirectory string = "/etc/bluechi/controller.conf.d/" + BlueChiAgentConfdDirectory string = "/etc/bluechi/agent.conf.d/" +) + +type BlueChiControllerConfig struct { + AllowedNodeNames []string + ManagerPort *int64 + LogLevel *string + LogTarget *string + LogIsQuiet *bool +} + +func (cfg BlueChiControllerConfig) Serialize() string { + res := "[bluechi-controller]\n" + res += "AllowedNodeNames=" + strings.Join(cfg.AllowedNodeNames, ",\n\t") + res += "\n" + if cfg.ManagerPort != nil { + res += "ManagerPort=" + strconv.FormatInt(*cfg.ManagerPort, 10) + "\n" + } + if cfg.LogLevel != nil { + res += "LogLevel=" + *cfg.LogLevel + "\n" + } + if cfg.LogTarget != nil { + res += "LogTarget=" + *cfg.LogTarget + "\n" + } + if cfg.LogIsQuiet != nil { + res += "LogIsQuiet=" + strconv.FormatBool(*cfg.LogIsQuiet) + "\n" + } + + return res +} + +type BlueChiAgentConfig struct { + NodeName *string + ManagerHost *string + ManagerPort *int64 + ManagerAddress *string + HeartbeatInterval *int64 + LogLevel *string + LogTarget *string + LogIsQuiet *bool +} + +func (cfg BlueChiAgentConfig) Serialize() string { + res := "[bluechi-agent]\n" + res += "NodeName=" + *cfg.NodeName + "\n" + res += "ManagerHost=" + *cfg.ManagerHost + "\n" + res += "ManagerPort=" + strconv.FormatInt(*cfg.ManagerPort, 10) + "\n" + if cfg.ManagerAddress != nil { + res += "ManagerAddress=" + *cfg.ManagerAddress + "\n" + } + if cfg.HeartbeatInterval != nil { + res += "HeartbeatInterval=" + strconv.FormatInt(*cfg.HeartbeatInterval, 10) + "\n" + } + if cfg.LogLevel != nil { + res += "LogLevel=" + *cfg.LogLevel + "\n" + } + if cfg.LogTarget != nil { + res += "LogTarget=" + *cfg.LogTarget + "\n" + } + if cfg.LogIsQuiet != nil { + res += "LogIsQuiet=" + strconv.FormatBool(*cfg.LogIsQuiet) + "\n" + } + + return res +} diff --git a/internal/client/client.go b/internal/client/client.go new file mode 100644 index 0000000..bdda079 --- /dev/null +++ b/internal/client/client.go @@ -0,0 +1,18 @@ +package client + +type Client interface { + Connect() error + Disconnect() error + + InstallBlueChi(bool, bool) error + + CreateControllerConfig(string, BlueChiControllerConfig) error + RemoveControllerConfig(string) error + RestartBlueChiController() error + StopBlueChiController() error + + CreateAgentConfig(string, BlueChiAgentConfig) error + RemoveAgentConfig(string) error + RestartBlueChiAgent() error + StopBlueChiAgent() error +} diff --git a/internal/client/ssh.go b/internal/client/ssh.go new file mode 100644 index 0000000..c65efb7 --- /dev/null +++ b/internal/client/ssh.go @@ -0,0 +1,349 @@ +package client + +import ( + "fmt" + "net" + "os" + "path" + "strings" + + "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/knownhosts" +) + +func ignoreHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error { + return nil +} + +type SSHClient struct { + Host string + User string + Password string + PKPath string + InsecureIgnoreHostKey bool + + conn *ssh.Client + connHasRoot bool +} + +func (c *SSHClient) newSSHSession() (*ssh.Session, error) { + if c == nil || c.conn == nil { + return nil, fmt.Errorf("not connected") + } + + return c.conn.NewSession() +} + +func (c *SSHClient) determineRootPrivileges() error { + session, err := c.newSSHSession() + if err != nil { + return err + } + defer session.Close() + + output, err := session.Output("whoami") + if err != nil { + return fmt.Errorf("failed to determine if root: (%s, %s)", err.Error(), string(output)) + } + + c.connHasRoot = (string(output) == "root") + return nil +} + +func (c *SSHClient) runCommand(cmd string) ([]byte, error) { + session, err := c.newSSHSession() + if err != nil { + return nil, err + } + defer session.Close() + + if !c.connHasRoot { + cmd = "sudo " + cmd + } + + return session.Output(cmd) +} + +func (c *SSHClient) isServiceInstalled(service string) (bool, error) { + output, err := c.runCommand(fmt.Sprintf("systemctl list-unit-files %s", service)) + if err != nil { + if serr, ok := err.(*ssh.ExitError); ok && serr.ExitStatus() == 1 { + return false, nil + } + return false, fmt.Errorf("failed to list unit files: %s", string(output)) + } + + return strings.Contains(string(output), service), nil +} + +func (c *SSHClient) determineOS() (string, error) { + output, err := c.runCommand("cat /etc/os-release | grep -w ID=") + if err != nil { + return "", fmt.Errorf("failed to determine os: %s", string(output)) + } + + os := strings.ReplaceAll(string(output), "ID=", "") + os = strings.ReplaceAll(os, "\"", "") + return strings.TrimSpace(os), nil +} + +func (c *SSHClient) Connect() error { + var err error + var authMethods []ssh.AuthMethod + var hostkeyCallback ssh.HostKeyCallback + + if c.PKPath != "" { + pkPath := c.PKPath + // resolve home directory + if strings.HasPrefix(pkPath, "~/") { + homeDir, err := os.UserHomeDir() + if err != nil { + return err + } + pkPath = path.Join(homeDir, strings.Replace(pkPath, "~/", "", 1)) + } + pKey, err := os.ReadFile(pkPath) + if err != nil { + return err + } + + signer, err := ssh.ParsePrivateKey(pKey) + if err != nil { + return err + } + + authMethods = append(authMethods, ssh.PublicKeys(signer)) + } + + if c.Password != "" { + authMethods = append(authMethods, ssh.Password(c.Password)) + } + + hostkeyCallback = ignoreHostKeyCallback + if !c.InsecureIgnoreHostKey { + homeDir, err := os.UserHomeDir() + if err != nil { + return err + } + + knownHostsPath := fmt.Sprintf("%s/.ssh/known_hosts", homeDir) + hostkeyCallback, err = knownhosts.New(knownHostsPath) + if err != nil { + return err + } + } + + conf := &ssh.ClientConfig{ + User: c.User, + HostKeyCallback: hostkeyCallback, + Auth: authMethods, + } + + c.conn, err = ssh.Dial("tcp", c.Host, conf) + if err != nil { + return err + } + + err = c.determineRootPrivileges() + if err != nil { + return err + } + + return nil +} + +func (c *SSHClient) Disconnect() error { + if c == nil || c.conn == nil { + return nil + } + return c.conn.Close() +} + +func (c *SSHClient) InstallBlueChi(installCtrl bool, installAgent bool) error { + needsInstallCtrl := false + needsInstallAgent := false + + if installCtrl { + isInstalled, err := c.isServiceInstalled("bluechi-controller.service") + if err != nil { + return err + } + needsInstallCtrl = !isInstalled + } + if installAgent { + isInstalled, err := c.isServiceInstalled("bluechi-agent.service") + if err != nil { + return err + } + needsInstallAgent = !isInstalled + } + + if !needsInstallCtrl && !needsInstallAgent { + return nil + } + + os, err := c.determineOS() + if err != nil { + return err + } + + if os == "autosd" || os == "centos" { + packagesToInstall := "" + if needsInstallCtrl { + packagesToInstall += " bluechi-controller bluechi-ctl " + } + if needsInstallAgent { + packagesToInstall += " bluechi-agent" + } + if packagesToInstall == "" { + return nil + } + + output, err := c.runCommand(fmt.Sprintf("dnf install -y %s", packagesToInstall)) + if err != nil { + return fmt.Errorf("failed to install packages '%s': %s", packagesToInstall, output) + } + } + + return nil +} + +func (c *SSHClient) CreateControllerConfig(file string, cfg BlueChiControllerConfig) error { + cmd := fmt.Sprintf("bash -c 'echo \"%s\" > %s'", cfg.Serialize(), path.Join(BlueChiControllerConfdDirectory, file)) + output, err := c.runCommand(cmd) + if err != nil { + return fmt.Errorf("failed to create controller config file: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) RemoveControllerConfig(file string) error { + cmd := fmt.Sprintf("rm -f %s", path.Join(BlueChiControllerConfdDirectory, file)) + output, err := c.runCommand(cmd) + if err != nil { + return fmt.Errorf("failed to remove controller config file: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) RestartBlueChiController() error { + output, err := c.runCommand("systemctl start bluechi-controller") + if err != nil { + return fmt.Errorf("failed to restart controller service: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) StopBlueChiController() error { + output, err := c.runCommand("systemctl stop bluechi-controller") + if err != nil { + return fmt.Errorf("failed to stop controller service: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) CreateAgentConfig(file string, cfg BlueChiAgentConfig) error { + cmd := fmt.Sprintf("bash -c 'echo \"%s\" > %s'", cfg.Serialize(), path.Join(BlueChiAgentConfdDirectory, file)) + output, err := c.runCommand(cmd) + if err != nil { + return fmt.Errorf("failed to create agent config file: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) RemoveAgentConfig(file string) error { + cmd := fmt.Sprintf("rm -f %s", path.Join(BlueChiAgentConfdDirectory, file)) + output, err := c.runCommand(cmd) + if err != nil { + return fmt.Errorf("failed to remove agent config file: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) RestartBlueChiAgent() error { + output, err := c.runCommand("systemctl start bluechi-agent") + if err != nil { + return fmt.Errorf("failed to restart agent service: %s", string(output)) + } + + return nil +} + +func (c *SSHClient) StopBlueChiAgent() error { + output, err := c.runCommand("systemctl stop bluechi-agent") + if err != nil { + return fmt.Errorf("failed to stop agent service: %s", string(output)) + } + + return nil +} + +func NewSSHClient(host string, user string, password string, pkPath string, insecureIgnoreHostKey bool) Client { + return &SSHClient{ + Host: host, + User: user, + Password: password, + PKPath: pkPath, + InsecureIgnoreHostKey: insecureIgnoreHostKey, + } +} + +/* + + */ + +type SSHClientMock struct{} + +func (c *SSHClientMock) Connect() error { + return nil +} + +func (c *SSHClientMock) Disconnect() error { + return nil +} + +func (c *SSHClientMock) InstallBlueChi(installCtrl bool, installAgent bool) error { + return nil +} + +func (c *SSHClientMock) CreateControllerConfig(file string, cfg BlueChiControllerConfig) error { + return nil +} + +func (c *SSHClientMock) RemoveControllerConfig(string) error { + return nil +} + +func (c *SSHClientMock) RestartBlueChiController() error { + return nil +} + +func (c *SSHClientMock) StopBlueChiController() error { + return nil +} + +func (c *SSHClientMock) CreateAgentConfig(file string, cfg BlueChiAgentConfig) error { + return nil +} + +func (c *SSHClientMock) RemoveAgentConfig(string) error { + return nil +} + +func (c *SSHClientMock) RestartBlueChiAgent() error { + return nil +} + +func (c *SSHClientMock) StopBlueChiAgent() error { + return nil +} + +func NewSSHClientMock() Client { + return &SSHClientMock{} +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go new file mode 100644 index 0000000..5dad541 --- /dev/null +++ b/internal/provider/provider.go @@ -0,0 +1,68 @@ +package provider + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/provider/schema" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var _ provider.Provider = &BlueChiProvider{} + +type BlueChiProvider struct { + version string +} + +type BlueChiProviderModel struct { + UseMock types.Bool `tfsdk:"use_mock"` +} + +func (p *BlueChiProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { + resp.TypeName = "bluechi" + resp.Version = p.version +} + +func (p *BlueChiProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "use_mock": schema.BoolAttribute{ + Optional: true, + Description: "Flag to indicate if a mock client should be used", + }, + }, + } +} + +func (p *BlueChiProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { + var data BlueChiProviderModel + + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + resp.DataSourceData = data.UseMock + resp.ResourceData = data.UseMock +} + +func (p *BlueChiProvider) Resources(ctx context.Context) []func() resource.Resource { + return []func() resource.Resource{ + NewBlueChiNodeResource, + } +} + +func (p *BlueChiProvider) DataSources(ctx context.Context) []func() datasource.DataSource { + return []func() datasource.DataSource{} +} + +func New(version string) func() provider.Provider { + return func() provider.Provider { + return &BlueChiProvider{ + version: version, + } + } +} diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go new file mode 100644 index 0000000..cb9c27f --- /dev/null +++ b/internal/provider/provider_test.go @@ -0,0 +1,16 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + + blueChiProvider "github.com/eclipse-bluechi/terraform-provider-bluechi/internal/provider" +) + +var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ + "bluechi": providerserver.NewProtocol6WithError(blueChiProvider.New("1.0.0")()), +} + +func testAccPreCheck(t *testing.T) {} diff --git a/internal/provider/resource_bluechi_node.go b/internal/provider/resource_bluechi_node.go new file mode 100644 index 0000000..1a09228 --- /dev/null +++ b/internal/provider/resource_bluechi_node.go @@ -0,0 +1,473 @@ +package provider + +import ( + "context" + "fmt" + + "github.com/eclipse-bluechi/terraform-provider-bluechi/internal/client" + "github.com/hashicorp/go-uuid" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var _ resource.Resource = &BlueChiNodeResource{} +var _ resource.ResourceWithImportState = &BlueChiNodeResource{} + +func NewBlueChiNodeResource() resource.Resource { + return &BlueChiNodeResource{} +} + +type BlueChiNodeResource struct { + UseMock types.Bool +} + +type BlueChiNodeResourceModel struct { + Id types.String `tfsdk:"id"` + SSH BlueChiSSHModel `tfsdk:"ssh"` + BlueChiController *BlueChiControllerModel `tfsdk:"bluechi_controller"` + BlueChiAgent *BlueChiAgentModel `tfsdk:"bluechi_agent"` +} + +type BlueChiSSHModel struct { + Host types.String `tfsdk:"host"` + User types.String `tfsdk:"user"` + Password types.String `tfsdk:"password"` + PrivateKeyPath types.String `tfsdk:"private_key_path"` + AcceptHostKeyInsecure types.Bool `tfsdk:"accept_host_key_insecure"` +} + +type BlueChiControllerModel struct { + AllowedNodeNames types.Set `tfsdk:"allowed_node_names"` + ManagerPort types.Int64 `tfsdk:"manager_port"` + LogLevel types.String `tfsdk:"log_level"` + LogTarget types.String `tfsdk:"log_target"` + LogIsQuiet types.Bool `tfsdk:"log_is_quiet"` + ConfigFile types.String `tfsdk:"config_file"` +} + +func (m BlueChiControllerModel) ToConfig() client.BlueChiControllerConfig { + cfg := client.BlueChiControllerConfig{} + m.AllowedNodeNames.ElementsAs(context.Background(), &cfg.AllowedNodeNames, true) + cfg.ManagerPort = m.ManagerPort.ValueInt64Pointer() + cfg.LogLevel = m.LogLevel.ValueStringPointer() + cfg.LogTarget = m.LogTarget.ValueStringPointer() + cfg.LogIsQuiet = m.LogIsQuiet.ValueBoolPointer() + + return cfg +} + +type BlueChiAgentModel struct { + NodeName types.String `tfsdk:"node_name"` + ManagerHost types.String `tfsdk:"manager_host"` + ManagerPort types.Int64 `tfsdk:"manager_port"` + ManagerAddress types.String `tfsdk:"manager_address"` + HeartbeatInterval types.Int64 `tfsdk:"heartbeat_interval"` + LogLevel types.String `tfsdk:"log_level"` + LogTarget types.String `tfsdk:"log_target"` + LogIsQuiet types.Bool `tfsdk:"log_is_quiet"` + ConfigFile types.String `tfsdk:"config_file"` +} + +func (m BlueChiAgentModel) ToConfig() client.BlueChiAgentConfig { + cfg := client.BlueChiAgentConfig{} + cfg.NodeName = m.NodeName.ValueStringPointer() + cfg.ManagerHost = m.ManagerHost.ValueStringPointer() + cfg.ManagerPort = m.ManagerPort.ValueInt64Pointer() + cfg.ManagerAddress = m.ManagerAddress.ValueStringPointer() + cfg.HeartbeatInterval = m.HeartbeatInterval.ValueInt64Pointer() + cfg.LogLevel = m.LogLevel.ValueStringPointer() + cfg.LogTarget = m.LogTarget.ValueStringPointer() + cfg.LogIsQuiet = m.LogIsQuiet.ValueBoolPointer() + + return cfg +} + +func (r *BlueChiNodeResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_node" +} + +func (r *BlueChiNodeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "A BlueChi node", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "Unique identifier of the node", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + + "ssh": schema.SingleNestedAttribute{ + Required: true, + Description: "Connection method to the machine", + Attributes: map[string]schema.Attribute{ + "host": schema.StringAttribute{ + Required: true, + Description: "Host of the machine", + Validators: []validator.String{}, + }, + "user": schema.StringAttribute{ + Required: true, + Description: "User on the machine", + Validators: []validator.String{}, + }, + "password": schema.StringAttribute{ + Optional: true, + Description: "Password to log in to the machine", + Validators: []validator.String{}, + }, + "private_key_path": schema.StringAttribute{ + Optional: true, + Description: "Path to the private key used for login", + Validators: []validator.String{}, + }, + "accept_host_key_insecure": schema.BoolAttribute{ + Optional: true, + Description: "Flag to indicate if host should be validated", + }, + }, + }, + "bluechi_controller": schema.SingleNestedAttribute{ + Optional: true, + Description: "BlueChi controller configuration used on the node", + Attributes: map[string]schema.Attribute{ + "allowed_node_names": schema.SetAttribute{ + Required: true, + ElementType: types.StringType, + Description: "List of all allowed node names", + Validators: []validator.Set{}, + }, + "manager_port": schema.Int64Attribute{ + Optional: true, + Description: "Port the manager is listening on", + Validators: []validator.Int64{}, + }, + "log_level": schema.StringAttribute{ + Optional: true, + Description: "Log level used by BlueChi controller", + Validators: []validator.String{}, + }, + "log_target": schema.StringAttribute{ + Optional: true, + Description: "Log target used by BlueChi controller", + Validators: []validator.String{}, + }, + "log_is_quiet": schema.BoolAttribute{ + Optional: true, + Description: "Flag to indicate if logs are written", + }, + "config_file": schema.StringAttribute{ + Computed: true, + Description: "The bluechi controller configuration file on the system", + }, + }, + }, + "bluechi_agent": schema.SingleNestedAttribute{ + Optional: true, + Description: "BlueChi agent configuration used on the node", + Attributes: map[string]schema.Attribute{ + "node_name": schema.StringAttribute{ + Required: true, + Description: "Name of the BlueChi agent", + Validators: []validator.String{}, + }, + "manager_host": schema.StringAttribute{ + Required: true, + Description: "Host of the manager to connect to", + Validators: []validator.String{}, + }, + "manager_port": schema.Int64Attribute{ + Required: true, + Description: "Port of the manager to connect to", + Validators: []validator.Int64{}, + }, + "manager_address": schema.StringAttribute{ + Optional: true, + Description: "Address of the manager to connect to. Replaces host and port.", + Validators: []validator.String{}, + }, + "heartbeat_interval": schema.Int64Attribute{ + Optional: true, + Description: "The interval in ms in which the connection is tested", + Validators: []validator.Int64{}, + }, + "log_level": schema.StringAttribute{ + Optional: true, + Description: "Log level used by BlueChi controller", + Validators: []validator.String{}, + }, + "log_target": schema.StringAttribute{ + Optional: true, + Description: "Log target used by BlueChi controller", + Validators: []validator.String{}, + }, + "log_is_quiet": schema.BoolAttribute{ + Optional: true, + Description: "Flag to indicate if logs are written", + }, + "config_file": schema.StringAttribute{ + Computed: true, + Description: "The bluechi agent configuration file on the system", + }, + }, + }, + }, + } +} + +func (r *BlueChiNodeResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + useMock, ok := req.ProviderData.(types.Bool) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected types.Bool, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.UseMock = useMock +} + +func (r *BlueChiNodeResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data BlueChiNodeResourceModel + + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + tflog.Error(ctx, "Failed to read model") + return + } + + sshClient, errDiag := setupSSHClient(data.SSH, r.UseMock.ValueBool()) + if errDiag != nil { + tflog.Error(ctx, "Failed to connect via SSH") + resp.Diagnostics.AddError(errDiag.Summary(), errDiag.Detail()) + return + } + defer sshClient.Disconnect() + + id, err := uuid.GenerateUUID() + if err != nil { + tflog.Error(ctx, "Failed to generate UUID for node") + resp.Diagnostics.AddError("Failed to generate UUID for node", err.Error()) + return + } + data.Id = types.StringValue(id) + + ctrlConf := data.BlueChiController + agentConf := data.BlueChiAgent + + err = sshClient.InstallBlueChi(ctrlConf != nil, agentConf != nil) + if err != nil { + tflog.Error(ctx, "Failed to install BlueChi") + resp.Diagnostics.AddError(fmt.Sprintf("Failed to install BlueChi: %v", err), err.Error()) + return + } + + if ctrlConf != nil { + ctrlConfFile := assembleConfigFileName("ctrl") + err := sshClient.CreateControllerConfig(ctrlConfFile, data.BlueChiController.ToConfig()) + if err != nil { + tflog.Error(ctx, "Failed to create controller config") + resp.Diagnostics.AddError("Failed to create controller config", err.Error()) + return + } + data.BlueChiController.ConfigFile = types.StringValue(ctrlConfFile) + + err = sshClient.RestartBlueChiController() + if err != nil { + tflog.Error(ctx, "Failed to start controller service") + resp.Diagnostics.AddError("Failed to start controller service", err.Error()) + return + } + } + + if agentConf != nil { + agentConfFile := assembleConfigFileName("agent") + err := sshClient.CreateAgentConfig(agentConfFile, data.BlueChiAgent.ToConfig()) + if err != nil { + tflog.Error(ctx, "Failed to create agent config") + resp.Diagnostics.AddError("Failed to create agent config", err.Error()) + return + } + data.BlueChiAgent.ConfigFile = types.StringValue(agentConfFile) + + err = sshClient.RestartBlueChiAgent() + if err != nil { + tflog.Error(ctx, "Failed to start agent service") + resp.Diagnostics.AddError("Failed to start agent service", err.Error()) + return + } + } + + tflog.Trace(ctx, "Setup BlueChi on machine completed") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *BlueChiNodeResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data BlueChiNodeResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + // TODO: implement read + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *BlueChiNodeResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data BlueChiNodeResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + sshClient, errDiag := setupSSHClient(data.SSH, r.UseMock.ValueBool()) + if errDiag != nil { + tflog.Error(ctx, "Failed to create and connect via SSH") + resp.Diagnostics.AddError(errDiag.Summary(), errDiag.Detail()) + return + } + defer sshClient.Disconnect() + + ctrlConf := data.BlueChiController + if ctrlConf != nil { + err := sshClient.CreateControllerConfig( + data.BlueChiController.ConfigFile.ValueString(), + data.BlueChiController.ToConfig(), + ) + if err != nil { + tflog.Error(ctx, "Failed to update controller config") + resp.Diagnostics.AddError("Failed to update controller config", err.Error()) + return + } + + err = sshClient.RestartBlueChiController() + if err != nil { + tflog.Error(ctx, "Failed to start controller service") + resp.Diagnostics.AddError("Failed to start controller service", err.Error()) + return + } + } + + agentConf := data.BlueChiAgent + if agentConf != nil { + err := sshClient.CreateAgentConfig( + data.BlueChiAgent.ConfigFile.ValueString(), + data.BlueChiAgent.ToConfig(), + ) + if err != nil { + tflog.Error(ctx, "Failed to update agent config") + resp.Diagnostics.AddError("Failed to update agent config", err.Error()) + return + } + + err = sshClient.RestartBlueChiAgent() + if err != nil { + tflog.Error(ctx, "Failed to start agent service") + resp.Diagnostics.AddError("Failed to start agent service", err.Error()) + return + } + } + + tflog.Trace(ctx, "Setup BlueChi on machine updated") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *BlueChiNodeResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data BlueChiNodeResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + sshClient, errDiag := setupSSHClient(data.SSH, r.UseMock.ValueBool()) + if sshClient == nil { + tflog.Error(ctx, "Failed to connect via SSH") + resp.Diagnostics.AddError(errDiag.Summary(), errDiag.Detail()) + return + } + defer sshClient.Disconnect() + + ctrlConf := data.BlueChiController + if ctrlConf != nil { + err := sshClient.RemoveControllerConfig(ctrlConf.ConfigFile.ValueString()) + if err != nil { + tflog.Error(ctx, "Failed to remove controller config") + resp.Diagnostics.AddError("Failed to remove controller config", err.Error()) + return + } + + err = sshClient.StopBlueChiController() + if err != nil { + tflog.Error(ctx, "Failed to stop controller service") + resp.Diagnostics.AddError("Failed to stop controller service", err.Error()) + return + } + } + + agentConf := data.BlueChiAgent + if agentConf != nil { + err := sshClient.RemoveAgentConfig(agentConf.ConfigFile.ValueString()) + if err != nil { + tflog.Error(ctx, "Failed to remove agent config") + resp.Diagnostics.AddError("Failed to remove agent config", err.Error()) + return + } + + err = sshClient.StopBlueChiAgent() + if err != nil { + tflog.Error(ctx, "Failed to stop agent service") + resp.Diagnostics.AddError("Failed to stop agent service", err.Error()) + return + } + } +} + +func (r *BlueChiNodeResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +func setupSSHClient(sshModel BlueChiSSHModel, useMock bool) (client.Client, *diag.ErrorDiagnostic) { + sshClient := client.NewSSHClient( + sshModel.Host.ValueString(), + sshModel.User.ValueString(), + sshModel.Password.ValueString(), + sshModel.PrivateKeyPath.ValueString(), + sshModel.AcceptHostKeyInsecure.ValueBool(), + ) + + if err := sshClient.Connect(); err != nil { + errSummary := fmt.Sprintf("Failed to connect to '%s'", sshModel.Host.ValueString()) + diagnostic := diag.NewErrorDiagnostic(errSummary, err.Error()) + return nil, &diagnostic + } + + return sshClient, nil +} + +func assembleConfigFileName(suffix string) string { + return fmt.Sprintf("ZZZ-%s.conf", suffix) +} diff --git a/internal/provider/resource_bluechi_node_test.go b/internal/provider/resource_bluechi_node_test.go new file mode 100644 index 0000000..35a9047 --- /dev/null +++ b/internal/provider/resource_bluechi_node_test.go @@ -0,0 +1,127 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestBlueChiNodeResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: exampleConfig(), + Check: resource.ComposeAggregateTestCheckFunc(), + }, + }, + }) +} + +func exampleConfig() string { + return ` +provider "bluechi" { + use_mock = false +} + +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 + } +} + +` +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..c4249e7 --- /dev/null +++ b/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "context" + "flag" + "log" + + "github.com/eclipse-bluechi/terraform-provider-bluechi/internal/provider" + "github.com/hashicorp/terraform-plugin-framework/providerserver" +) + +var ( + version string = "1.0.0" +) + +func main() { + var debug bool + + flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := providerserver.ServeOpts{ + Address: "registry.terraform.io/bluechi/bluechi", + Debug: debug, + ProtocolVersion: 6, + } + + err := providerserver.Serve(context.Background(), provider.New(version), opts) + if err != nil { + log.Fatal(err.Error()) + } +}