diff --git a/README.md b/README.md index fb79f69..90fb70a 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ See [https://github.com/dodevops/kc](the kc website) for details. * 🟦 krew * 🐚 Kubectlnodeshell * 🐳 Kubernetes +* 📦 Opentofu * 📦 Packages * 📦 Packer * 👟 Run @@ -83,6 +84,7 @@ See [https://github.com/dodevops/kc](the kc website) for details. * [krew](#krew) * [Kubectlnodeshell](#kubectlnodeshell) * [Kubernetes](#kubernetes) + * [Opentofu](#opentofu) * [Packages](#packages) * [Packer](#packer) * [Run](#run) @@ -578,6 +580,24 @@ Installs and configures [kubernetes](https://kubernetes.io/docs/reference/kubect * Environment GCLOUD_K8S_CLUSTERS: A comma separated list of zone[@project]:cluster-name * Environment K8S_USE_GCLOUD_AUTH: Whether to use the new GKE_GCLOUD_AUTH plugin [true] +### Opentofu + +Installs and configures [Opentofu](https://opentofu.org/) + +#### Configuration + +* USE_opentofu: Enable this feature (or use the FEATURES variable instead) +* OPENTOFU_VERSION (required): Version to install (or use the FEATURES variable instead) +* DEBUG_opentofu: Debug this feature +* Add a volume mount to the `volumes:` section of docker compose like this: + (...) + volumes: + - ":/opentofu" +* If you used the browser based login in gcloud, you'll probably need to authenticate using the application-default + login using the gcloud cli by running + + gcloud auth application-default login + ### Packages Installs additional packages into the container diff --git a/build.sh b/build.sh index 53b513d..97cf0e9 100644 --- a/build.sh +++ b/build.sh @@ -9,7 +9,7 @@ set -euo pipefail # # If no flavour is specified, all flavours will be built -mv Dockerfile Dockerfile.sav +mv Dockerfile Dockerfile.sav &>/dev/null || true TAG=latest if [ -n "$1" ] diff --git a/feature/opentofu/feature.yaml b/feature/opentofu/feature.yaml new file mode 100644 index 0000000..134a921 --- /dev/null +++ b/feature/opentofu/feature.yaml @@ -0,0 +1,15 @@ +icon: "📦" +title: "Opentofu" +description: "Installs and configures [Opentofu](https://opentofu.org/)" +configuration: + - | + Add a volume mount to the `volumes:` section of docker compose like this: + (...) + volumes: + - ":/opentofu" + - | + If you used the browser based login in gcloud, you'll probably need to authenticate using the application-default + login using the gcloud cli by running + + gcloud auth application-default login +requiresVersion: true diff --git a/feature/opentofu/goss.unsetversion/.will-fail b/feature/opentofu/goss.unsetversion/.will-fail new file mode 100644 index 0000000..b9a034c --- /dev/null +++ b/feature/opentofu/goss.unsetversion/.will-fail @@ -0,0 +1 @@ +The opentofu feature requires a version set using OPENTOFU_VERSION. diff --git a/feature/opentofu/goss/.env b/feature/opentofu/goss/.env new file mode 100644 index 0000000..f2c9589 --- /dev/null +++ b/feature/opentofu/goss/.env @@ -0,0 +1,2 @@ +OPENTOFU_VERSION=1.10.5 +DEBUG_opentofu=true \ No newline at end of file diff --git a/feature/opentofu/goss/goss.yaml b/feature/opentofu/goss/goss.yaml new file mode 100644 index 0000000..f5912ff --- /dev/null +++ b/feature/opentofu/goss/goss.yaml @@ -0,0 +1,6 @@ +command: + terraform: + exec: "/home/cloudcontrol/bin/tofu --version" + exit-status: 0 + stdout: + - "OpenTofu v1.10.5" diff --git a/feature/opentofu/install.sh b/feature/opentofu/install.sh new file mode 100755 index 0000000..7f030b0 --- /dev/null +++ b/feature/opentofu/install.sh @@ -0,0 +1,19 @@ +. /feature-installer-utils.sh + +if [ -z "${OPENTOFU_VERSION}" ] +then + echo "The opentofu feature requires a version set using OPENTOFU_VERSION. See https://github.com/opentofu/opentofu/releases for valid versions" + exit 1 +fi + +OPENTOFU_VERSION=$(checkAndCleanVersion "${OPENTOFU_VERSION}") + +TEMPDIR=$(mktemp -d) +cd "${TEMPDIR}" || exit + +execHandle "Downloading opentofu" curl -f -s -L "https://github.com/opentofu/opentofu/releases/download/v${OPENTOFU_VERSION}/tofu_${OPENTOFU_VERSION}_linux_$(getPlatform).zip" --output opentofu.zip +execHandle "Unpacking opentofu" unzip opentofu.zip +execHandle "Installing opentofu" mv tofu /home/cloudcontrol/bin/tofu + +cd - &>/dev/null || exit +rm -rf "${TEMPDIR}" diff --git a/flavour/aws/Dockerfile.flavour b/flavour/aws/Dockerfile.flavour index 7bfcdf3..2dd1621 100644 --- a/flavour/aws/Dockerfile.flavour +++ b/flavour/aws/Dockerfile.flavour @@ -1,6 +1,6 @@ FROM amazon/aws-cli:latest -RUN yum install -y sudo shadow-utils unzip tar net-tools curl && \ +RUN yum install -y sudo shadow-utils unzip tar net-tools && \ echo "cloudcontrol ALL=(root)NOPASSWD:/usr/bin/yum *" > /etc/sudoers.d/cloudcontrol && \ echo "cloudcontrol ALL=(root)NOPASSWD:/usr/bin/curl *" >> /etc/sudoers.d/cloudcontrol && \ echo "cloudcontrol ALL=(root)NOPASSWD:/usr/bin/mv *" >> /etc/sudoers.d/cloudcontrol && \