Merge pull request #153118 from qowoz/tf-scripts

terraform-providers: update-provider scripts - misc fixes

authored by zimbatm.tngl.sh and committed by GitHub a475c130 0df76028

+46 -59
+5 -5
pkgs/applications/networking/cluster/terraform-providers/update-all-providers
··· 1 #!/usr/bin/env nix-shell 2 - #! nix-shell -i bash -p jq 3 # shellcheck shell=bash 4 5 # Update all providers which have specified provider source address ··· 14 ) 15 16 echo "Will update providers:" 17 - echo "$providers" 18 19 - for provider in $providers; do 20 - echo "Updating $provider" 21 - ./update-provider "$provider" 22 done
··· 1 #!/usr/bin/env nix-shell 2 + #! nix-shell -I nixpkgs=../../../../.. -i bash -p jq 3 # shellcheck shell=bash 4 5 # Update all providers which have specified provider source address ··· 14 ) 15 16 echo "Will update providers:" 17 + echo "${providers}" 18 19 + for provider in ${providers}; do 20 + echo "Updating ${provider}" 21 + ./update-provider "${provider}" 22 done
+41 -54
pkgs/applications/networking/cluster/terraform-providers/update-provider
··· 1 #!/usr/bin/env nix-shell 2 - #! nix-shell -I nixpkgs=../../../../.. -i bash -p coreutils curl jq moreutils nix 3 # shellcheck shell=bash 4 # vim: ft=sh 5 # ··· 7 # provider source address. 8 # 9 set -euo pipefail 10 11 show_usage() { 12 cat <<DOC ··· 57 shift 2 58 ;; 59 *) 60 - if [[ -n "$provider" ]]; then 61 - echo "ERROR: provider name was passed two times: '$provider' and '$1'" 62 echo "Use --help for more info" 63 exit 1 64 fi 65 provider=$1 66 shift 67 esac 68 done 69 70 - if [[ -z "$provider" ]]; then 71 echo "ERROR: No providers specified!" 72 echo 73 show_usage 74 exit 1 75 fi 76 77 - provider_name=$(basename "$provider") 78 79 # Usage: read_attr <key> 80 read_attr() { 81 - jq -r ".\"$provider_name\".\"$1\"" providers.json 82 } 83 84 # Usage: update_attr <key> <value> 85 update_attr() { 86 - if [[ "$2" == "null" ]]; then 87 - jq -S ".\"$provider_name\".\"$1\" = null" providers.json | sponge providers.json 88 else 89 - jq -S ".\"$provider_name\".\"$1\" = \"$2\"" providers.json | sponge providers.json 90 fi 91 } 92 ··· 96 local owner=$1 97 local repo=$2 98 local rev=$3 99 - nix-prefetch-url --unpack "https://github.com/$owner/$repo/archive/$rev.tar.gz" 100 } 101 102 old_source_address="$(read_attr provider-source-address)" 103 old_vendor_sha256=$(read_attr vendorSha256) 104 old_version=$(read_attr version) 105 106 - if [[ $provider =~ ^[^/]+/[^/]+$ ]]; then 107 - source_address=registry.terraform.io/$provider 108 else 109 - source_address=$old_source_address 110 fi 111 - if [[ "$source_address" == "null" ]]; then 112 - echo "Could not find the source address for provider: $provider" 113 exit 1 114 fi 115 - update_attr "provider-source-address" "$source_address" 116 117 # The provider source address (used inside Terraform `required_providers` block) is 118 # used to compute the registry API endpoint ··· 122 # registry.terraform.io/v1/providers/hashicorp/aws (provider URL for the JSON API) 123 registry_response=$(curl -s https://"${source_address/\///v1/providers/}") 124 125 - version="$(jq -r '.version' <<< "$registry_response")" 126 - if [[ "$old_version" = "$version" && "$force" != 1 && -z "$vendorSha256" && "$old_vendor_sha256" != "$vendorSha256" ]]; then 127 - echo "$provider_name is already at version $version" 128 exit 129 fi 130 - update_attr version "$version" 131 132 - provider_source_url="$(jq -r '.source' <<< "$registry_response")" 133 134 - org="$(echo "$provider_source_url" | cut -d '/' -f 4)" 135 - update_attr owner "$org" 136 - repo="$(echo "$provider_source_url" | cut -d '/' -f 5)" 137 - update_attr repo "$repo" 138 - rev="$(jq -r '.tag' <<< "$registry_response")" 139 - update_attr rev "$rev" 140 - sha256=$(prefetch_github "$org" "$repo" "$rev") 141 - update_attr sha256 "$sha256" 142 143 repo_root=$(git rev-parse --show-toplevel) 144 145 - if [[ -z "$vendorSha256" ]]; then 146 - if [[ "$old_vendor_sha256" == null ]]; then 147 vendorSha256=null 148 - elif [[ -n "$old_vendor_sha256" || "$vendor" = 1 ]]; then 149 echo "=== Calculating vendorSha256 ===" 150 - update_attr vendorSha256 "0000000000000000000000000000000000000000000000000000000000000000" 151 - # Hackish way to find out the desired sha256. First build, then extract the 152 - # error message from the logs. 153 - set +e 154 - nix-build --no-out-link "$repo_root" -A "terraform-providers.$provider_name.go-modules" 2>vendor_log.txt 155 - set -e 156 - logs=$(< vendor_log.txt) 157 - if ! [[ $logs =~ got:\ +([^\ ]+) ]]; then 158 - echo "ERROR: could not find new hash in output:" 159 - cat vendor_log.txt 160 - rm -f vendor_log.txt 161 - exit 1 162 - fi 163 - rm -f vendor_log.txt 164 - # trim the results in case it they have a sha256: prefix or contain more than one line 165 - vendorSha256=$(echo "${BASH_REMATCH[1]#sha256:}" | head -n 1) 166 # Deal with nix unstable 167 - if [[ $vendorSha256 = sha256-* ]]; then 168 - vendorSha256=$(nix --extra-experimental-features nix-command hash to-base32 "$vendorSha256") 169 fi 170 fi 171 fi 172 173 - if [[ -n "$vendorSha256" ]]; then 174 - update_attr vendorSha256 "$vendorSha256" 175 fi 176 177 # Check that the provider builds 178 - echo "=== Building terraform-providers.$provider_name ===" 179 - nix-build "$repo_root" -A "terraform-providers.$provider_name"
··· 1 #!/usr/bin/env nix-shell 2 + #! nix-shell -I nixpkgs=../../../../.. -i bash -p coreutils curl jq moreutils nix nix-prefetch 3 # shellcheck shell=bash 4 # vim: ft=sh 5 # ··· 7 # provider source address. 8 # 9 set -euo pipefail 10 + shopt -s inherit_errexit 11 12 show_usage() { 13 cat <<DOC ··· 58 shift 2 59 ;; 60 *) 61 + if [[ -n ${provider} ]]; then 62 + echo "ERROR: provider name was passed two times: '${provider}' and '$1'" 63 echo "Use --help for more info" 64 exit 1 65 fi 66 provider=$1 67 shift 68 + ;; 69 esac 70 done 71 72 + if [[ -z ${provider} ]]; then 73 echo "ERROR: No providers specified!" 74 echo 75 show_usage 76 exit 1 77 fi 78 79 + provider_name=$(basename "${provider}") 80 81 # Usage: read_attr <key> 82 read_attr() { 83 + jq -r ".\"${provider_name}\".\"$1\"" providers.json 84 } 85 86 # Usage: update_attr <key> <value> 87 update_attr() { 88 + if [[ $2 == "null" ]]; then 89 + jq -S ".\"${provider_name}\".\"$1\" = null" providers.json | sponge providers.json 90 else 91 + jq -S ".\"${provider_name}\".\"$1\" = \"$2\"" providers.json | sponge providers.json 92 fi 93 } 94 ··· 98 local owner=$1 99 local repo=$2 100 local rev=$3 101 + nix-prefetch-url --unpack "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz" 102 } 103 104 old_source_address="$(read_attr provider-source-address)" 105 old_vendor_sha256=$(read_attr vendorSha256) 106 old_version=$(read_attr version) 107 108 + if [[ ${provider} =~ ^[^/]+/[^/]+$ ]]; then 109 + source_address=registry.terraform.io/${provider} 110 else 111 + source_address=${old_source_address} 112 fi 113 + if [[ ${source_address} == "null" ]]; then 114 + echo "Could not find the source address for provider: ${provider}" 115 exit 1 116 fi 117 + update_attr "provider-source-address" "${source_address}" 118 119 # The provider source address (used inside Terraform `required_providers` block) is 120 # used to compute the registry API endpoint ··· 124 # registry.terraform.io/v1/providers/hashicorp/aws (provider URL for the JSON API) 125 registry_response=$(curl -s https://"${source_address/\///v1/providers/}") 126 127 + version="$(jq -r '.version' <<<"${registry_response}")" 128 + if [[ ${old_version} == "${version}" && ${force} != 1 && -z ${vendorSha256} && ${old_vendor_sha256} != "${vendorSha256}" ]]; then 129 + echo "${provider_name} is already at version ${version}" 130 exit 131 fi 132 + update_attr version "${version}" 133 134 + provider_source_url="$(jq -r '.source' <<<"${registry_response}")" 135 136 + org="$(echo "${provider_source_url}" | cut -d '/' -f 4)" 137 + update_attr owner "${org}" 138 + repo="$(echo "${provider_source_url}" | cut -d '/' -f 5)" 139 + update_attr repo "${repo}" 140 + rev="$(jq -r '.tag' <<<"${registry_response}")" 141 + update_attr rev "${rev}" 142 + sha256=$(prefetch_github "${org}" "${repo}" "${rev}") 143 + update_attr sha256 "${sha256}" 144 145 repo_root=$(git rev-parse --show-toplevel) 146 147 + if [[ -z ${vendorSha256} ]]; then 148 + if [[ ${old_vendor_sha256} == null ]]; then 149 vendorSha256=null 150 + elif [[ -n ${old_vendor_sha256} || ${vendor} == 1 ]]; then 151 echo "=== Calculating vendorSha256 ===" 152 + vendorSha256=$(nix-prefetch "{ sha256 }: (import ../../../../.. {}).terraform-providers.${provider_name}.go-modules.overrideAttrs (_: { vendorSha256 = sha256; })") 153 # Deal with nix unstable 154 + if [[ ${vendorSha256} == sha256-* ]]; then 155 + vendorSha256=$(nix --extra-experimental-features nix-command hash to-base32 "${vendorSha256}") 156 fi 157 fi 158 fi 159 160 + if [[ -n ${vendorSha256} ]]; then 161 + update_attr vendorSha256 "${vendorSha256}" 162 fi 163 164 # Check that the provider builds 165 + echo "=== Building terraform-providers.${provider_name} ===" 166 + nix-build --no-out-link "${repo_root}" -A "terraform-providers.${provider_name}"