Skip to content

Commit 248c53d

Browse files
authored
fix: install terraform in base Docker image (#6263)
Updates the base Docker image to install Terraform version 1.3.4 (max supported version) by default. Also updates documentation to reflect this change.
1 parent 0c2b432 commit 248c53d

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

docs/install/offline.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ The following instructions walk you through how to build a custom Coder server i
2020

2121
First, build and push a container image extending our official image with the following:
2222

23-
- Terraform [(supported versions)](https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24)
2423
- CLI config (.tfrc) for Terraform referring to [external mirror](https://www.terraform.io/cli/config/config-file#explicit-installation-method-configuration)
2524
- [Terraform Providers](https://registry.terraform.io) for templates
2625
- 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.
2726

27+
> 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.
28+
> If you need to bundle a different version of terraform, you can do so by customizing the image.
29+
2830
Here's an example:
2931

3032
```Dockerfile
@@ -38,13 +40,16 @@ RUN apk add curl unzip
3840
# Create directory for the Terraform CLI (and assets)
3941
RUN mkdir -p /opt/terraform
4042

41-
# In order to run Coder airgapped or within private networks,
42-
# Terraform has to be bundled into the image in PATH or /opt.
43-
#
43+
# Terraform is already included in the official Coder image.
44+
# See https://github.com/coder/coder/blob/main/scripts/Dockerfile.base#L15
45+
# If you need to install a different version of Terraform, you can do so here.
46+
# The below step is optional if you wish to keep the existing version.
4447
# See https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24
4548
# for supported Terraform versions.
4649
ARG TERRAFORM_VERSION=1.3.0
47-
RUN curl -LOs https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
50+
RUN apk update && \
51+
apk del terraform && \
52+
curl -LOs https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
4853
&& unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
4954
&& mv terraform /opt/terraform \
5055
&& rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip

provisioner/terraform/install.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
var (
1919
// TerraformVersion is the version of Terraform used internally
2020
// when Terraform is not available on the system.
21+
// NOTE: Keep this in sync with the version in scripts/Dockerfile.base.
2122
TerraformVersion = version.Must(version.NewVersion("1.3.4"))
2223

2324
minTerraformVersion = version.Must(version.NewVersion("1.1.0"))

scripts/Dockerfile.base

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
FROM alpine:latest
55

66
# We use a single RUN command to reduce the number of layers in the image.
7+
# NOTE: Keep the Terraform version in sync with minTerraformVersion and
8+
# maxTerraformVersion in provisioner/terraform/install.go.
79
RUN apk add --no-cache \
810
curl \
911
wget \
1012
bash \
1113
git \
12-
openssh-client && \
14+
openssh-client \
15+
terraform=1.3.4-r2 && \
1316
addgroup \
1417
-g 1000 \
1518
coder && \

0 commit comments

Comments
 (0)