-
Notifications
You must be signed in to change notification settings - Fork 228
/
setup-provider.sh
executable file
·67 lines (48 loc) · 1.82 KB
/
setup-provider.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# QA has a new process to test Terraform using RCs. We will not publish RCs
# onto the Terraform registry because Hashicorp could potentially block our
# testing by being slow to publish.
# Instead, we will test using a downloaded binary from the RC. This script
# sets up the correct binary using a defined <provider> <version> to test
# updates locally.
# ./setup-provider.sh <provider> <version>
# Example
# ./setup-provider.sh rancher2 v3.0.0-rc1
set -e
# Validate user input
if [ $# -ne 2 ]; then
echo "Usage: $0 <provider> <version>"
exit 1
fi
# Set global vars
PROVIDER=$1
VERSION=$2
VERSION_TAG=$(echo $2 | cut -c 2-)
# Check for unzip
if ! command -v "unzip" &> /dev/null; then
echo "Missing required tool unzip. unzip can be installed via apt on Linux"
exit 1
fi
# Download binary
OS_PLATFORM=$(uname -sp | tr '[:upper:] ' '[:lower:]_' | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/arm/arm64/')
DIR=~/.terraform.d/plugins/terraform.local/local/${PROVIDER}/${VERSION_TAG}/${OS_PLATFORM}
mkdir -p $DIR
# unzip can't handle files from stdin, so we create a temporary file
ZIP_FILE=terraform-provider-${PROVIDER}_${VERSION_TAG}_${OS_PLATFORM}.zip
curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/${ZIP_FILE} -o ${ZIP_FILE}
unzip $ZIP_FILE -d ${DIR}
rm ${ZIP_FILE}
#Note the required 'v' in front of VERSION_TAG
mv ${DIR}/terraform-provider-${PROVIDER}_v${VERSION_TAG} ${DIR}/terraform-provider-${PROVIDER}
# Mod binary
chmod +x ${DIR}/terraform-provider-${PROVIDER}
echo -e "Terraform provider ${PROVIDER} ${VERSION} is ready to test!
Please update the required_providers block in your Terraform config file
terraform {
required_providers {
rancher2 = {
source = "terraform.local/local/${PROVIDER}"
version = "${VERSION_TAG}"
}
}
}"