terraform-providers: remove explicit version

not needed when we can just remove v from the front of rev
This commit is contained in:
zowoq 2022-11-26 15:27:43 +10:00
parent d13437b014
commit 70f5922404
3 changed files with 150 additions and 294 deletions

View File

@ -17,7 +17,7 @@ let
({ owner
, repo
, rev
, version
, version ? lib.removePrefix "v" rev
, hash ? throw "use hash instead of sha256" # added 2202/09
, vendorHash ? throw "use vendorHash instead of vendorSha256" # added 2202/09
, deleteVendor ? false

View File

@ -107,7 +107,6 @@ if [[ ${provider} =~ ^[^/]+/[^/]+$ ]]; then
source_address=registry.terraform.io/${provider}
provider=$(basename "${provider}")
update_attr "provider-source-address" "${source_address}"
update_attr version "0"
# create empty stings so nix-prefetch works
update_attr hash ""
update_attr vendorHash ""
@ -116,7 +115,7 @@ else
fi
old_vendor_hash=$(read_attr vendorHash)
old_version=$(read_attr version)
old_rev=$(read_attr rev)
# The provider source address (used inside Terraform `required_providers` block) is
# used to compute the registry API endpoint
@ -126,17 +125,17 @@ old_version=$(read_attr version)
# registry.terraform.io/v1/providers/hashicorp/aws (provider URL for the JSON API)
registry_response=$(curl -s https://"${source_address/\///v1/providers/}")
version="$(jq -r '.version' <<<"${registry_response}")"
if [[ ${old_version} == "${version}" && ${force} != 1 && -z ${vendorHash} && ${old_vendor_hash} != "${vendorHash}" ]]; then
echo_provider "already at version ${version}"
rev="$(jq -r '.tag' <<<"${registry_response}")"
if [[ ${old_rev} == "${rev}" && ${force} != 1 && -z ${vendorHash} && ${old_vendor_hash} != "${vendorHash}" ]]; then
echo_provider "already at version ${rev}"
exit
fi
if [[ ${version} =~ [[:alpha:]] && ${force} != 1 ]]; then
echo_provider "not updating to unstable version ${version}"
if [[ ${rev//v/} =~ [[:alpha:]] && ${force} != 1 ]]; then
echo_provider "not updating to unstable version ${rev}"
exit
fi
echo_provider "updating from ${old_version} to ${version}"
update_attr version "${version}"
echo_provider "updating from ${old_rev} to ${rev}"
update_attr rev "${rev}"
provider_source_url="$(jq -r '.source' <<<"${registry_response}")"
@ -144,8 +143,6 @@ org="$(echo "${provider_source_url}" | cut -d '/' -f 4)"
update_attr owner "${org}"
repo="$(echo "${provider_source_url}" | cut -d '/' -f 5)"
update_attr repo "${repo}"
rev="$(jq -r '.tag' <<<"${registry_response}")"
update_attr rev "${rev}"
echo_provider "calculating hash"
hash=$(generate_hash src)
update_attr hash "${hash}"