From b33249645b8c17b2500613e504dd73a3b5d15538 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 17 Feb 2023 17:43:23 +0000 Subject: [PATCH 1/4] fix: install terraform in base Docker image --- scripts/Dockerfile.base | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/Dockerfile.base b/scripts/Dockerfile.base index 8d926fe8eac55..f61f6c7cdc9dd 100644 --- a/scripts/Dockerfile.base +++ b/scripts/Dockerfile.base @@ -9,7 +9,8 @@ RUN apk add --no-cache \ wget \ bash \ git \ - openssh-client && \ + openssh-client \ + terraform && \ addgroup \ -g 1000 \ coder && \ From ed7415706a6ec7849589ae41e423038ae4d80e42 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 17 Feb 2023 18:20:15 +0000 Subject: [PATCH 2/4] Add providers and local filesystem mirror --- scripts/Dockerfile.base | 21 ++++++++++++++++++++- scripts/files/terraform-config.tfrc | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 scripts/files/terraform-config.tfrc diff --git a/scripts/Dockerfile.base b/scripts/Dockerfile.base index f61f6c7cdc9dd..c84d151b66348 100644 --- a/scripts/Dockerfile.base +++ b/scripts/Dockerfile.base @@ -10,7 +10,7 @@ RUN apk add --no-cache \ bash \ git \ openssh-client \ - terraform && \ + terraform=1.3.4-r2 && \ addgroup \ -g 1000 \ coder && \ @@ -22,6 +22,25 @@ RUN apk add --no-cache \ -G coder \ coder +# Install Terraform plugins +RUN mkdir -p /opt/terraform/plugins/registry.terraform.io +# Add config for local terraform +ADD files/terraform-config.tfrc /opt/terraform/config.tfrc +ARG CODER_PROVIDER_VERSION=0.6.12 +RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/coder/coder +WORKDIR /opt/terraform/plugins/registry.terraform.io/coder/coder +RUN curl -LOs https://github.com/coder/terraform-provider-coder/releases/download/v${CODER_PROVIDER_VERSION}/terraform-provider-coder_${CODER_PROVIDER_VERSION}_linux_amd64.zip +ARG DOCKER_PROVIDER_VERSION=3.0.1 +RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/kreuzwerker/docker +WORKDIR /opt/terraform/plugins/registry.terraform.io/kreuzwerker/docker +RUN curl -LOs https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v${DOCKER_PROVIDER_VERSION}/terraform-provider-docker_${DOCKER_PROVIDER_VERSION}_linux_amd64.zip +RUN chown -R coder:coder /opt/terraform/plugins +ARG KUBERNETES_PROVIDER_VERSION=2.18.0 +RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/hashicorp/kubernetes +WORKDIR /opt/terraform/plugins/registry.terraform.io/hashicorp/kubernetes +# TODO: What is the URL? +RUN curl -LOs $KUBERNETES_URL_GOES_HERE + USER 1000:1000 ENV HOME=/home/coder ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt diff --git a/scripts/files/terraform-config.tfrc b/scripts/files/terraform-config.tfrc new file mode 100644 index 0000000000000..d3585e39ea682 --- /dev/null +++ b/scripts/files/terraform-config.tfrc @@ -0,0 +1,5 @@ +provider_installation { + filesystem_mirror { + path = "/opt/terraform/plugins" + } +} From e4a1ab88557424f3204679a33a5b051cdaaafeac Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 21 Feb 2023 09:55:43 -0700 Subject: [PATCH 3/4] remove providers --- provisioner/terraform/install.go | 1 + scripts/Dockerfile.base | 21 ++------------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/provisioner/terraform/install.go b/provisioner/terraform/install.go index 08b2796d4753a..ddaf4024731d3 100644 --- a/provisioner/terraform/install.go +++ b/provisioner/terraform/install.go @@ -18,6 +18,7 @@ import ( var ( // TerraformVersion is the version of Terraform used internally // when Terraform is not available on the system. + // NOTE: Keep this in sync with the version in scripts/Dockerfile.base. TerraformVersion = version.Must(version.NewVersion("1.3.4")) minTerraformVersion = version.Must(version.NewVersion("1.1.0")) diff --git a/scripts/Dockerfile.base b/scripts/Dockerfile.base index c84d151b66348..9e0de834ae0b2 100644 --- a/scripts/Dockerfile.base +++ b/scripts/Dockerfile.base @@ -4,6 +4,8 @@ FROM alpine:latest # We use a single RUN command to reduce the number of layers in the image. +# NOTE: Keep the Terraform version in sync with minTerraformVersion and +# maxTerraformVersion in provisioner/terraform/install.go. RUN apk add --no-cache \ curl \ wget \ @@ -22,25 +24,6 @@ RUN apk add --no-cache \ -G coder \ coder -# Install Terraform plugins -RUN mkdir -p /opt/terraform/plugins/registry.terraform.io -# Add config for local terraform -ADD files/terraform-config.tfrc /opt/terraform/config.tfrc -ARG CODER_PROVIDER_VERSION=0.6.12 -RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/coder/coder -WORKDIR /opt/terraform/plugins/registry.terraform.io/coder/coder -RUN curl -LOs https://github.com/coder/terraform-provider-coder/releases/download/v${CODER_PROVIDER_VERSION}/terraform-provider-coder_${CODER_PROVIDER_VERSION}_linux_amd64.zip -ARG DOCKER_PROVIDER_VERSION=3.0.1 -RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/kreuzwerker/docker -WORKDIR /opt/terraform/plugins/registry.terraform.io/kreuzwerker/docker -RUN curl -LOs https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v${DOCKER_PROVIDER_VERSION}/terraform-provider-docker_${DOCKER_PROVIDER_VERSION}_linux_amd64.zip -RUN chown -R coder:coder /opt/terraform/plugins -ARG KUBERNETES_PROVIDER_VERSION=2.18.0 -RUN mkdir -p /opt/terraform/plugins/registry.terraform.io/hashicorp/kubernetes -WORKDIR /opt/terraform/plugins/registry.terraform.io/hashicorp/kubernetes -# TODO: What is the URL? -RUN curl -LOs $KUBERNETES_URL_GOES_HERE - USER 1000:1000 ENV HOME=/home/coder ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt From a6ab95f138128452aff9e8078f5b1a9e5bd84ef7 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 6 Mar 2023 17:39:27 +0000 Subject: [PATCH 4/4] update docs --- docs/install/offline.md | 15 ++++++++++----- scripts/files/terraform-config.tfrc | 5 ----- 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 scripts/files/terraform-config.tfrc diff --git a/docs/install/offline.md b/docs/install/offline.md index 94e856a364e03..e0bff646ef4ba 100644 --- a/docs/install/offline.md +++ b/docs/install/offline.md @@ -6,11 +6,13 @@ Coder can run in offline / air-gapped environments. First, build and push a container image extending our official image with the following: -- Terraform [(supported versions)](https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24) - CLI config (.tfrc) for Terraform referring to [external mirror](https://www.terraform.io/cli/config/config-file#explicit-installation-method-configuration) - [Terraform Providers](https://registry.terraform.io) for templates - These could also be specified via a volume mount (Docker) or [network mirror](https://www.terraform.io/internals/provider-network-mirror-protocol). See below for details. +> Note: Coder includes the latest [supported version](https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24) of Terraform in the official Docker images. +> If you need to bundle a different version of terraform, you can do so by customizing the image. + Here's an example: ```Dockerfile @@ -24,13 +26,16 @@ RUN apk add curl unzip # Create directory for the Terraform CLI (and assets) RUN mkdir -p /opt/terraform -# In order to run Coder airgapped or within private networks, -# Terraform has to be bundled into the image in PATH or /opt. -# +# Terraform is already included in the official Coder image. +# See https://github.com/coder/coder/blob/main/scripts/Dockerfile.base#L15 +# If you need to install a different version of Terraform, you can do so here. +# The below step is optional if you wish to keep the existing version. # See https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24 # for supported Terraform versions. ARG TERRAFORM_VERSION=1.3.0 -RUN curl -LOs https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ +RUN apk update && \ + apk del terraform && \ + curl -LOs https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ && unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ && mv terraform /opt/terraform \ && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip diff --git a/scripts/files/terraform-config.tfrc b/scripts/files/terraform-config.tfrc deleted file mode 100644 index d3585e39ea682..0000000000000 --- a/scripts/files/terraform-config.tfrc +++ /dev/null @@ -1,5 +0,0 @@ -provider_installation { - filesystem_mirror { - path = "/opt/terraform/plugins" - } -}