-
Notifications
You must be signed in to change notification settings - Fork 56
Building Terraform
The instructions provided below specify the steps to build Terraform 1.10.5 on Linux on IBM Z for following distributions:
- RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
- SLES 15 SP6
- Ubuntu (20.04, 22.04, 24.04. 24.10)
General Notes:
- When following the steps below please use a standard permission user unless otherwise specified.
- A directory
/<source_root>/
will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.
If you want to build terraform using manual steps, go to STEP 2.
Use the following commands to build terraform using the build script. Please make sure you have wget installed.
wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Terraform/1.10.5/build_terraform.sh
# Build terraform
bash build_terraform.sh [Provide -t option for executing build with tests]
In case of error, check logs
for more details or go to STEP 2 to follow manual build steps.
export SOURCE_ROOT=/<source_root>/
export PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Terraform/1.10.5/patch"
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y git wget tar gcc diffutils zip unzip
-
SLES 15 SP6
sudo zypper install -y git-core wget tar gcc gzip zip unzip
-
Ubuntu (20.04, 22.04, 24.04, 24.10)
sudo apt-get update sudo apt-get install -y git wget tar gcc zip unzip
-
Install Go version
1.23.3
cd $SOURCE_ROOT export GO_VERSION="1.23.3" wget -q https://storage.googleapis.com/golang/go"$GO_VERSION".linux-s390x.tar.gz chmod ugo+r go"$GO_VERSION".linux-s390x.tar.gz sudo tar -C /usr/local -xzf go"$GO_VERSION".linux-s390x.tar.gz sudo ln -sf /usr/local/go/bin/go /usr/bin/ sudo ln -sf /usr/local/go/bin/gofmt /usr/bin/ sudo ln -sf /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc # (Only on RHEL and SLES) go version
#Download and install terraform
export GOPATH=$SOURCE_ROOT
export PATH=$GOPATH/bin:$PATH
mkdir -p $GOPATH/src/github.com/hashicorp
cd $GOPATH/src/github.com/hashicorp
git clone -b v1.10.5 https://github.com/hashicorp/terraform.git
cd terraform
go install .
The terraform
binary will be created in folder $GOPATH/bin/
-
Copying binary to /usr/bin and verify installation
sudo cp $GOPATH/bin/terraform /usr/bin/ terraform -version terraform -help
cd $GOPATH/src/github.com/hashicorp/terraform
go test -v ./...
cd $GOPATH/src/github.com/hashicorp/terraform
go test -race ./internal/terraform ./internal/command ./internal/states
-
Download and build necessary terraform provider plugins locally
PROVIDER_PLUGIN_LOCAL_MIRROR_PATH="$HOME/.terraform.d/plugins" mkdir -p $PROVIDER_PLUGIN_LOCAL_MIRROR_PATH cd $GOPATH/src/github.com/hashicorp git clone https://github.com/hashicorp/terraform-provider-null.git cd terraform-provider-null git checkout v3.2.3 go build BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/null/3.2.3/linux_s390x" mkdir -p $BIN_PATH mv terraform-provider-null $BIN_PATH/terraform-provider-null_v3.2.3 git checkout v3.1.0 go build mv terraform-provider-null terraform-provider-null_v3.1.0_x5 zip terraform-provider-null_3.1.0_linux_s390x.zip terraform-provider-null_v3.1.0_x5 mv terraform-provider-null_3.1.0_linux_s390x.zip $PROVIDER_PLUGIN_LOCAL_MIRROR_PATH/registry.terraform.io/hashicorp/null/ git checkout v2.1.0 go build BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/null/2.1.0/linux_s390x" mkdir -p $BIN_PATH mv terraform-provider-null $BIN_PATH/terraform-provider-null_v2.1.0_x4 BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/null/1.0.0+local/linux_s390x" mkdir -p $BIN_PATH cp $GOPATH/src/github.com/hashicorp/terraform/internal/command/e2etest/testdata/vendored-provider/terraform.d/plugins/registry.terraform.io/hashicorp/null/1.0.0+local/os_arch/terraform-provider-null_v1.0.0 $BIN_PATH/ cd $GOPATH/src/github.com/hashicorp git clone -b v5.40.0 https://github.com/hashicorp/terraform-provider-aws.git cd terraform-provider-aws go build BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/aws/5.40.0/linux_s390x" mkdir -p $BIN_PATH mv terraform-provider-aws $BIN_PATH/terraform-provider-aws_v5.40.0 cd $GOPATH/src/github.com/hashicorp git clone -b v2.2.0 https://github.com/hashicorp/terraform-provider-template.git cd terraform-provider-template go build BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/template/2.2.0/linux_s390x" mkdir -p $BIN_PATH mv terraform-provider-template $BIN_PATH/terraform-provider-template_v2.2.0 BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/registry.terraform.io/hashicorp/template/2.1.0/linux_s390x" mkdir -p $BIN_PATH mv $GOPATH/src/github.com/hashicorp/terraform/internal/command/e2etest/testdata/plugin-cache/cache/registry.terraform.io/hashicorp/template/2.1.0/os_arch/terraform-provider-template_v2.1.0_x4 $BIN_PATH/ BIN_PATH="${PROVIDER_PLUGIN_LOCAL_MIRROR_PATH}/example.com/awesomecorp/happycloud/1.2.0/linux_s390x" mkdir -p $BIN_PATH mv $GOPATH/src/github.com/hashicorp/terraform/internal/command/e2etest/testdata/local-only-provider/terraform.d/plugins/example.com/awesomecorp/happycloud/1.2.0/os_arch/terraform-provider-happycloud_v1.2.0 $BIN_PATH/
-
Change CLI configurations temporarily to use locally built provider plugins
cd $HOME wget $PATCH_URL/.terraformrc sed -i "s#HOME__PATH#$HOME#g" .terraformrc
-
Run e2e tests
cd $GOPATH/src/github.com/hashicorp/terraform TF_ACC=1 go test -v ./internal/command/e2etest
-
Revert CLI configurations back to default
cd $HOME mv .terraformrc .terraformrc.e2etest
Note: In case of unexpected test failures, please try re-running the test individually. Use the below command to execute the test individually:
go test -v <package_name> -run <failed_test_name>
Please follow the instructions here to verify the built Terraform binary.
Note: The docker
provider (kreuzwerker/docker) used in this tutorial should be built on s390x with steps similar to those in Section 4.3 before running the verification.
The information provided in this article is accurate at the time of writing, but on-going development in the open-source projects involved may make the information incorrect or obsolete. Please open issue or contact us on IBM Z Community if you have any questions or feedback.