Skip to content

Commit cacf302

Browse files
authored
Merge pull request #1100 from a-blender/add-rc-test-script-backport
[Backport release/v2] Add mac/unix and windows RC test scripts
2 parents 0f65f84 + 16f2c6a commit cacf302

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

setup-provider-windows.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<#
2+
This Windows script is to be used to test Terraform RCs locally. It downloads
3+
and installs the given RC.
4+
5+
./setup-provider-windows.ps1 <provider> <version>
6+
7+
Example
8+
9+
./setup-provider-windows.ps1 rancher v3.0.0-rc1
10+
11+
If you get a cert revocation check error when running the script, curl could
12+
not identify a valid certificate to download the zip. Add --ssl-no-revoke or
13+
--insecure to the curl command and rerun. Alternatives such as white listing
14+
the download link may also work.
15+
#>
16+
17+
$PROVIDER=$args[0]
18+
$VERSION=$args[1]
19+
$VERSION_TAG=$VERSION.TrimStart("v")
20+
21+
$DIR="%APPDATA%\terraform.d\plugins\terraform.local\local\${PROVIDER}\${VERSION_TAG}\windows_amd64"
22+
new-item $DIR -itemtype directory
23+
24+
write-host "Downloading zip..."
25+
$URL="https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_windows_amd64.zip"
26+
echo $URL
27+
curl.exe -LO $URL -o terraform-provider-${PROVIDER}_${VERSION_TAG}_windows_amd64.zip
28+
29+
write-host "Expanding zip..."
30+
Expand-Archive -Force -Path terraform-provider-${PROVIDER}_${VERSION_TAG}_windows_amd64.zip -DestinationPath ${DIR}/terraform-provider-${PROVIDER}
31+
32+
write-host "Cleaning up..."
33+
Remove-Item -Force -Path terraform-provider-${PROVIDER}_${VERSION_TAG}_windows_amd64.zip
34+
35+
write-host "Terraform is ready to test!"

setup-provider.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# QA has a new process to test Terraform using RCs. We will not publish RCs
4+
# onto the Terraform registry because Hashicorp could potentially block our
5+
# testing by being slow to publish.
6+
7+
# Instead, we will test using a downloaded binary from the RC. This script
8+
# sets up the correct binary using a defined <provider> <version> to test
9+
# updates locally.
10+
11+
# ./setup-provider.sh <provider> <version>
12+
13+
# Example
14+
# ./setup-provider.sh rancher2 v3.0.0-rc1
15+
16+
set -e
17+
18+
# Validate user input
19+
20+
if [ $# -ne 2 ]; then
21+
echo "Usage: $0 <provider> <version>"
22+
exit 1
23+
fi
24+
25+
# Set global vars
26+
27+
PROVIDER=$1
28+
VERSION=$2
29+
VERSION_TAG=$(echo $2 | cut -c 2-)
30+
31+
# Install gzip
32+
33+
if ! command -v "gzip" &> /dev/null; then
34+
echo "Missing gzip. Installing..."
35+
brew install gzip
36+
fi
37+
38+
# Download binary
39+
40+
OS_PLATFORM=$(uname -sp | tr '[:upper:] ' '[:lower:]_' | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/arm/arm64/')
41+
42+
DIR=~/.terraform.d/plugins/terraform.local/local/${PROVIDER}/${VERSION_TAG}/${OS_PLATFORM}
43+
mkdir -p $DIR
44+
curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_${OS_PLATFORM}.zip | gunzip -c - > ${DIR}/terraform-provider-${PROVIDER}
45+
46+
# Mod binary
47+
chmod +x ${DIR}/terraform-provider-${PROVIDER}
48+
49+
echo -e "Terraform provider ${PROVIDER} ${VERSION} is ready to test!
50+
Please update the required_providers block in your Terraform config file
51+
52+
terraform {
53+
required_providers {
54+
rancher2 = {
55+
source = "terraform.local/local/${PROVIDER}"
56+
version = "${VERSION_TAG}"
57+
}
58+
}
59+
}"

0 commit comments

Comments
 (0)