From 11aabb6ca172839b63d97b4201dfcdb4bf3ed702 Mon Sep 17 00:00:00 2001 From: Anna Blendermann Date: Wed, 1 Mar 2023 17:03:44 -0500 Subject: [PATCH 1/2] Add script for QA to test Terraform rcs locally --- setup-provider.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 setup-provider.sh diff --git a/setup-provider.sh b/setup-provider.sh new file mode 100755 index 000000000..9d06b1f91 --- /dev/null +++ b/setup-provider.sh @@ -0,0 +1,74 @@ +#!/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 to test +# updates locally. + +# Example +# ./setup-provider.sh rancher2 v3.0.0-rc1 + +# Validate user input + +if [ -z "$1" ] || [ -z "$2" ]; then + echo -e "Please specify a Terraform provider and version tag." + echo -e "./setup-provider.sh " + exit 1 +fi + +# Set global vars + +PROVIDER=$1 +VERSION=$2 +VERSION_TAG=$(echo $2 | cut -c 2-) +BASE=~/.terraform.d/plugins/terraform.example.com/local/${PROVIDER}/${VERSION_TAG} + +# Install gzip + +brew install gzip + +# Pull and copy the binary + +case $OSTYPE in + + "linux-gnu"*) + curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_linux_amd64.zip | gunzip -c - > terraform-provider-${PROVIDER}_${VERSION} + if [ ! $? -eq 0 ]; then + echo "Error: incomplete download. Did you specify the correct provider and version?" + rm terraform-provider-${PROVIDER}_${VERSION} + exit 1 + fi + DIR=${BASE}/linux_amd64 + mkdir -p $DIR && cp terraform-provider-${PROVIDER}_${VERSION} $DIR/terraform-provider-${PROVIDER} + ;; + + "darwin"*) + curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_darwin_amd64.zip | gunzip -c - > terraform-provider-${PROVIDER}_${VERSION} + if [ ! $? -eq 0 ]; then + echo "Error: incomplete download. Did you specify the correct provider and version?" + rm terraform-provider-${PROVIDER}_${VERSION} + exit 1 + fi + DIR=${BASE}/darwin_amd64 + mkdir -p $DIR && cp terraform-provider-${PROVIDER}_${VERSION} $DIR/terraform-provider-${PROVIDER} + ;; +esac + +# Clean up + +rm terraform-provider-${PROVIDER}_${VERSION} + +echo -e "Terraform provider ${PROVIDER} ${VERSION} is ready to test! +Please update the required_providers block in your Terraform config file. Example: + +terraform { + required_providers { + rancher2 = { + source = "terraform.example.com/local/rancher2" + version = "3.0.0-rc1" + } + } +}" From f498e697eff38ce878852836773684f5edf326e8 Mon Sep 17 00:00:00 2001 From: Anna Blendermann Date: Thu, 2 Mar 2023 13:11:31 -0500 Subject: [PATCH 2/2] Address comments --- setup-provider.sh | 60 +++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/setup-provider.sh b/setup-provider.sh index 9d06b1f91..a4ab559d5 100755 --- a/setup-provider.sh +++ b/setup-provider.sh @@ -11,12 +11,13 @@ # Example # ./setup-provider.sh rancher2 v3.0.0-rc1 +set -e + # Validate user input -if [ -z "$1" ] || [ -z "$2" ]; then - echo -e "Please specify a Terraform provider and version tag." - echo -e "./setup-provider.sh " - exit 1 +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 fi # Set global vars @@ -24,51 +25,38 @@ fi PROVIDER=$1 VERSION=$2 VERSION_TAG=$(echo $2 | cut -c 2-) -BASE=~/.terraform.d/plugins/terraform.example.com/local/${PROVIDER}/${VERSION_TAG} # Install gzip -brew install gzip - -# Pull and copy the binary - -case $OSTYPE in +if ! command -v "gzip" &> /dev/null; then + echo "Missing gzip. Installing..." + brew install gzip +fi - "linux-gnu"*) - curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_linux_amd64.zip | gunzip -c - > terraform-provider-${PROVIDER}_${VERSION} - if [ ! $? -eq 0 ]; then - echo "Error: incomplete download. Did you specify the correct provider and version?" - rm terraform-provider-${PROVIDER}_${VERSION} - exit 1 - fi - DIR=${BASE}/linux_amd64 - mkdir -p $DIR && cp terraform-provider-${PROVIDER}_${VERSION} $DIR/terraform-provider-${PROVIDER} - ;; +# Download binary - "darwin"*) - curl -sfL https://github.com/rancher/terraform-provider-${PROVIDER}/releases/download/${VERSION}/terraform-provider-${PROVIDER}_${VERSION_TAG}_darwin_amd64.zip | gunzip -c - > terraform-provider-${PROVIDER}_${VERSION} - if [ ! $? -eq 0 ]; then - echo "Error: incomplete download. Did you specify the correct provider and version?" - rm terraform-provider-${PROVIDER}_${VERSION} - exit 1 - fi - DIR=${BASE}/darwin_amd64 - mkdir -p $DIR && cp terraform-provider-${PROVIDER}_${VERSION} $DIR/terraform-provider-${PROVIDER} - ;; -esac +OS_PLATFORM=$(uname -sp | tr '[:upper:] ' '[:lower:]_' | sed 's/x86_64/amd64/') -# Clean up +if [[ $OS_PLATFORM == "darwin"* ]] +then + OS_PLATFORM="darwin_amd64" +elif [[ $OS_PLATFORM == "linux"* ]] +then + OS_PLATFORM="linux_amd64" +fi -rm terraform-provider-${PROVIDER}_${VERSION} +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. Example: +Please update the required_providers block in your Terraform config file terraform { required_providers { rancher2 = { - source = "terraform.example.com/local/rancher2" - version = "3.0.0-rc1" + source = "terraform.local/local/${PROVIDER}" + version = "${VERSION_TAG}" } } }"