From 4a0a4eb9b0ca8ec806257a899977dd6fb87b7635 Mon Sep 17 00:00:00 2001 From: Jared Watts Date: Mon, 3 Jun 2024 12:44:21 -0700 Subject: [PATCH 1/2] build: add check to enforce max allowed terraform version Signed-off-by: Jared Watts --- Makefile | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7b13e37..70972c2 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,12 @@ PROJECT_NAME ?= provider-spotify PROJECT_REPO ?= github.com/crossplane-contrib/$(PROJECT_NAME) -export TERRAFORM_VERSION ?= 1.7.2 +export TERRAFORM_VERSION ?= 1.5.7 + +# Do not allow a version of terraform greater than 1.5.x, due to versions 1.6+ being +# licensed under BSL, which is not permitted. +export TERRAFORM_VERSION_CEILING ?= 1.6 +TERRAFORM_VERSION_VALID := $(shell [ $(TERRAFORM_VERSION) = `echo "$(TERRAFORM_VERSION)\n$(TERRAFORM_VERSION_CEILING)" | sort -V | head -n1` ] && echo 1 || echo 0) export TERRAFORM_PROVIDER_SOURCE ?= conradludgate/spotify export TERRAFORM_PROVIDER_REPO ?= https://github.com/conradludgate/terraform-provider-spotify @@ -92,7 +97,7 @@ xpkg.build.provider-spotify: do.build.images # NOTE(hasheddan): we ensure up is installed prior to running platform-specific # build steps in parallel to avoid encountering an installation race condition. -build.init: $(UP) +build.init: $(UP) check-terraform-version # ==================================================================================== # Setup Terraform for fetching provider schema @@ -100,7 +105,12 @@ TERRAFORM := $(TOOLS_HOST_DIR)/terraform-$(TERRAFORM_VERSION) TERRAFORM_WORKDIR := $(WORK_DIR)/terraform TERRAFORM_PROVIDER_SCHEMA := config/schema.json -$(TERRAFORM): +check-terraform-version: +ifneq ($(TERRAFORM_VERSION_VALID),1) + $(error invalid TERRAFORM_VERSION $(TERRAFORM_VERSION), must be less than $(TERRAFORM_VERSION_CEILING)) +endif + +$(TERRAFORM): check-terraform-version @$(INFO) installing terraform $(HOSTOS)-$(HOSTARCH) @mkdir -p $(TOOLS_HOST_DIR)/tmp-terraform @curl -fsSL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(SAFEHOST_PLATFORM).zip -o $(TOOLS_HOST_DIR)/tmp-terraform/terraform.zip @@ -126,7 +136,7 @@ pull-docs: generate.init: $(TERRAFORM_PROVIDER_SCHEMA) pull-docs -.PHONY: $(TERRAFORM_PROVIDER_SCHEMA) pull-docs +.PHONY: $(TERRAFORM_PROVIDER_SCHEMA) pull-docs check-terraform-version # ==================================================================================== # Targets From ab054a8fa14c9b39c63eee2bea7f071757cec272 Mon Sep 17 00:00:00 2001 From: Jared Watts Date: Tue, 4 Jun 2024 09:05:58 -0700 Subject: [PATCH 2/2] build: refine terraform version checking logic and messaging Signed-off-by: Jared Watts --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 70972c2..6a38475 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,7 @@ export TERRAFORM_VERSION ?= 1.5.7 # Do not allow a version of terraform greater than 1.5.x, due to versions 1.6+ being # licensed under BSL, which is not permitted. -export TERRAFORM_VERSION_CEILING ?= 1.6 -TERRAFORM_VERSION_VALID := $(shell [ $(TERRAFORM_VERSION) = `echo "$(TERRAFORM_VERSION)\n$(TERRAFORM_VERSION_CEILING)" | sort -V | head -n1` ] && echo 1 || echo 0) +TERRAFORM_VERSION_VALID := $(shell [ "$(TERRAFORM_VERSION)" = "`printf "$(TERRAFORM_VERSION)\n1.6" | sort -V | head -n1`" ] && echo 1 || echo 0) export TERRAFORM_PROVIDER_SOURCE ?= conradludgate/spotify export TERRAFORM_PROVIDER_REPO ?= https://github.com/conradludgate/terraform-provider-spotify @@ -107,7 +106,7 @@ TERRAFORM_PROVIDER_SCHEMA := config/schema.json check-terraform-version: ifneq ($(TERRAFORM_VERSION_VALID),1) - $(error invalid TERRAFORM_VERSION $(TERRAFORM_VERSION), must be less than $(TERRAFORM_VERSION_CEILING)) + $(error invalid TERRAFORM_VERSION $(TERRAFORM_VERSION), must be less than 1.6.0 since that version introduced a not permitted BSL license)) endif $(TERRAFORM): check-terraform-version