Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for QA to test Terraform rcs locally #1082

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions setup-provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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.

# Example
# ./setup-provider.sh rancher2 v3.0.0-rc1

set -e

# Validate user input

a-blender marked this conversation as resolved.
Show resolved Hide resolved
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-)

# Install gzip

if ! command -v "gzip" &> /dev/null; then
echo "Missing gzip. Installing..."
brew install gzip
fi

# Download binary

OS_PLATFORM=$(uname -sp | tr '[:upper:] ' '[:lower:]_' | sed 's/x86_64/amd64/')

if [[ $OS_PLATFORM == "darwin"* ]]
then
OS_PLATFORM="darwin_amd64"
elif [[ $OS_PLATFORM == "linux"* ]]
then
OS_PLATFORM="linux_amd64"
fi

DIR=~/.terraform.d/plugins/terraform.local/local/${PROVIDER}/${VERSION_TAG}/${OS_PLATFORM}
mkdir -p $DIR
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}

echo -e "Terraform provider ${PROVIDER} ${VERSION} is ready to test!
Please update the required_providers block in your Terraform config file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary for now, but would be cool to have an optional variable to add this to the user's config file for them. i.e.

usage: $0 <provider> <version> <terraform_config_path>


terraform {
required_providers {
rancher2 = {
source = "terraform.local/local/${PROVIDER}"
version = "${VERSION_TAG}"
}
}
}"