diff --git a/.github/workflows/terraform-compatibility-matrix.yml b/.github/workflows/terraform-compatibility-matrix.yml index 4819f8ad91..40e78bbeb3 100644 --- a/.github/workflows/terraform-compatibility-matrix.yml +++ b/.github/workflows/terraform-compatibility-matrix.yml @@ -26,7 +26,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - output=$(./scripts/get-terraform-supported-versions.sh) + output=$(./scripts/get-terraform-supported-versions.sh "false") quoted_output=$(echo "${output}" | jq -c .) echo "supported_versions=${quoted_output}" >> "${GITHUB_OUTPUT}" outputs: diff --git a/.github/workflows/update_tf_compatibility_matrix.yml b/.github/workflows/update_tf_compatibility_matrix.yml new file mode 100644 index 0000000000..b62e796df0 --- /dev/null +++ b/.github/workflows/update_tf_compatibility_matrix.yml @@ -0,0 +1,30 @@ +name: Update Terraform Compatibility Matrix documentation + +# Checks if any changes are required to be made to our documentation for supported Terraform versions. Runs daily and can be triggered manually. +on: + schedule: + - cron: "0 7 * * *" # Everyday at 7:00 AM + workflow_dispatch: + +jobs: + update-tf-compatibility-matrix: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - name: Update files + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make update-tf-compatibility-matrix + - name: Verify Changed files + uses: tj-actions/verify-changed-files@843c0b95f87cd81a2efe729380c6d1f11fb3ea12 + id: verify-changed-files + - name: Create PR + uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e + if: steps.verify-changed-files.outputs.files_changed == 'true' + with: + title: "doc: Updates Terraform Compatibility Matrix documentation" + commit-message: "doc: Updates Terraform Compatibility Matrix documentation" + delete-branch: true + branch: terraform-compatibility-matrix-update + body: Automatic updates for Terraform Compatibility Matrix documentation diff --git a/GNUmakefile b/GNUmakefile index c69df969e4..95bdc47517 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -134,3 +134,7 @@ scaffold-schemas: .PHONY: generate-doc generate-doc: ## Generate the resource documentation via tfplugindocs ./scripts/generate-doc.sh ${resource_name} + +.PHONY: update-tf-compatibility-matrix +update-tf-compatibility-matrix: ## Update Terraform Compatibility Matrix documentation + ./scripts/update-tf-compatibility-matrix.sh diff --git a/scripts/get-terraform-supported-versions.sh b/scripts/get-terraform-supported-versions.sh index 0b47728365..0ef168a7a6 100755 --- a/scripts/get-terraform-supported-versions.sh +++ b/scripts/get-terraform-supported-versions.sh @@ -14,26 +14,35 @@ # See the License for the specific language governing permissions and # limitations under the License. set -euo pipefail + +usage() { + echo "Usage: $0 [true|false]" + echo " true: Returns details of supported Terraform versions" + echo " false: Returns only supported Terraform version numbers" + exit 1 +} + get_last_day_of_month() { last_day_of_month=0 case $1 in - 01|03|05|07|08|10|12) - last_day_of_month=31 ;; - 04|06|09|11) - last_day_of_month=30 ;; - 02) - # February: check if it's a leap year - if (( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )); then - last_day_of_month=29 - else - last_day_of_month=28 - fi - ;; - esac + 01 | 03 | 05 | 07 | 08 | 10 | 12) + last_day_of_month=31 + ;; + 04 | 06 | 09 | 11) + last_day_of_month=30 + ;; + 02) + # February: check if it's a leap year + if ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))); then + last_day_of_month=29 + else + last_day_of_month=28 + fi + ;; + esac echo $last_day_of_month } - add_end_support_date() { new_json_list=$(echo "$1" | jq -c '.[]' | while IFS= read -r obj; do input_date=$(echo "$obj" | jq -r '.published_at') @@ -55,37 +64,58 @@ add_end_support_date() { echo "$new_json_list" } -page=1 -api_version="2022-11-28" - -while true; do - response=$(curl -s \ - --request GET \ - --url "https://api.github.com/repos/hashicorp/terraform/releases?per_page=100&page=$page" \ - --header "Authorization: Bearer $GITHUB_TOKEN" \ - --header "X-GitHub-Api-Version: $api_version") - if [[ "$(printf '%s\n' "$response" | jq -e 'length == 0')" == "true" ]]; then - break - else - versions=$(echo "$response" | jq -r '.[] | {version: .tag_name, published_at: .published_at}') - filtered_versions_json=$(printf '%s\n' "${versions}" | jq -s '.') - updated_date_versions=$(add_end_support_date "$filtered_versions_json") - filtered_out_deprecated_versions=$(echo "$updated_date_versions" | jq 'map(select((.version | test("alpha|beta|rc"; "i") | not) and ((.end_support_date | fromdate) >= now))) | map(select(.version | endswith(".0")))') - - if [ -z ${json_array+x} ]; then - # If json_array is empty, assign filtered_versions directly - json_array=$(jq -n --argjson filtered_versions "${filtered_out_deprecated_versions}" '$filtered_versions') +get_terraform_supported_versions_details() { + page=1 + api_version="2022-11-28" + + while true; do + response=$(curl -s \ + --request GET \ + --url "https://api.github.com/repos/hashicorp/terraform/releases?per_page=100&page=$page" \ + --header "Authorization: Bearer $GITHUB_TOKEN" \ + --header "X-GitHub-Api-Version: $api_version") + if [[ "$(printf '%s\n' "$response" | jq -e 'length == 0')" == "true" ]]; then + break else - # If json_array is not empty, append filtered_versions to it - json_array=$(echo "$json_array" | jq --argjson filtered_versions "${filtered_out_deprecated_versions}" '. + $filtered_versions') + versions=$(echo "$response" | jq -r '.[] | {version: .tag_name, published_at: .published_at}') + filtered_versions_json=$(printf '%s\n' "${versions}" | jq -s '.') + updated_date_versions=$(add_end_support_date "$filtered_versions_json") + filtered_out_deprecated_versions=$(echo "$updated_date_versions" | jq 'map(select((.version | test("alpha|beta|rc"; "i") | not) and ((.end_support_date | fromdate) >= now))) | map(select(.version | endswith(".0")))') + if [ -z ${json_array+x} ]; then + # If json_array is empty, assign filtered_versions directly + json_array=$(jq -n --argjson filtered_versions "${filtered_out_deprecated_versions}" '$filtered_versions') + else + # If json_array is not empty, append filtered_versions to it + json_array=$(echo "$json_array" | jq --argjson filtered_versions "${filtered_out_deprecated_versions}" '. + $filtered_versions') + fi + + ((page++)) fi + done + + echo "$json_array" +} + +get_terraform_supported_versions() { + json_array=$(get_terraform_supported_versions_details) - ((page++)) - fi -done + versions_array=$(printf '%s\n' "${json_array}" | jq -r '.[] | .version') -versions_array=$(printf '%s\n' "${json_array}" | jq -r '.[] | .version') + formatted_output=$(echo "$versions_array" | awk 'BEGIN { ORS = "" } {gsub(/^v/,"",$1); gsub(/\.0$/,".x",$1); printf("%s\"%s\"", (NR==1?"":", "), $1)}' | sed 's/,"/," /g') + + echo "[$formatted_output]" | jq -c . +} -formatted_output=$(echo "$versions_array" | awk 'BEGIN { ORS = "" } {gsub(/^v/,"",$1); gsub(/\.0$/,".x",$1); printf("%s\"%s\"", (NR==1?"":", "), $1)}' | sed 's/,"/," /g') +if [ $# -ne 1 ]; then + usage +fi -echo "[$formatted_output]" | jq -c . +get_details=$1 +if [ "$get_details" = "true" ]; then + get_terraform_supported_versions_details +elif [ "$get_details" = "false" ]; then + get_terraform_supported_versions +else + echo "Invalid parameter." + usage +fi diff --git a/scripts/update-tf-compatibility-matrix.sh b/scripts/update-tf-compatibility-matrix.sh new file mode 100755 index 0000000000..9d9b172a66 --- /dev/null +++ b/scripts/update-tf-compatibility-matrix.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +# Copyright 2024 MongoDB Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -euo pipefail + +input_array=$(./scripts/get-terraform-supported-versions.sh "true") + +indexFile="website/docs/index.html.markdown" + +transform_array() { + local arr="$1" + local updated_arr="[" + local isFirstElement=true + + for ((i = 0; i < $(jq length <<<"$arr"); i++)); do + version=$(jq -r ".[$i].version" <<<"$arr" | sed 's/^v//;s/\.0/.x/') + published_at=$(jq -r ".[$i].published_at" <<<"$arr" | cut -dT -f1) + end_support_date=$(jq -r ".[$i].end_support_date" <<<"$arr" | cut -dT -f1) + + if [ "$isFirstElement" = false ]; then + updated_arr+="," + fi + updated_arr+="{\"version\": \"$version\", \"published_at\": \"$published_at\", \"end_support_date\": \"$end_support_date\"}" + isFirstElement=false + done + + updated_arr+="]" + + echo "$updated_arr" +} + +generate_matrix_markup() { + local output_array="$1" + + table="| HashiCorp Terraform Release | HashiCorp Terraform Release Date | HashiCorp Terraform Full Support End Date | MongoDB Atlas Support End Date |\n" + table+="|:-------:|:------------:|:------------:|:------------:|\n" + + for ((i = 0; i < $(jq length <<<"$output_array"); i++)); do + version=$(jq -r ".[$i].version" <<<"$output_array") + published_at=$(jq -r ".[$i].published_at" <<<"$output_array") + end_support_date=$(jq -r ".[$i].end_support_date" <<<"$output_array") + + table+="| $version | $published_at | $end_support_date | $end_support_date |\n" + done + + echo -e "$table" +} + +update_index_markdown_file() { + local markup="$1" + local tempFile="$indexFile.tmp" + local placeholderStart="" + local placeholderEnd="" + local inPlaceholder=0 + + # Ensure the temp file is empty or does not exist + : > "$tempFile" + + while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" == "$placeholderStart" ]]; then + inPlaceholder=1 + echo "$line" >>"$tempFile" + echo "$markup" >>"$tempFile" + continue + fi + + if [[ "$line" == "$placeholderEnd" ]]; then + inPlaceholder=0 + echo "$line" >>"$tempFile" + continue + fi + + if [[ $inPlaceholder -eq 0 ]]; then + echo "$line" >>"$tempFile" + fi + done <"$indexFile" + + mv "$tempFile" "$indexFile" + + echo "Updated Terraform version compatibility matrix in $indexFile" +} + +# Transform the array data +updated_array=$(transform_array "$input_array") + +# Generate markup for the compatibility matrix +markup=$(generate_matrix_markup "$updated_array") + +# Update the Markdown file with the generated markup +update_index_markdown_file "$markup" diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 318cbb5c24..bd535a4835 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -180,7 +180,9 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf For more information on configuring and managing programmatic API Keys see the [MongoDB Atlas Documentation](https://docs.atlas.mongodb.com/tutorial/manage-programmatic-access/index.html). ## [HashiCorp Terraform Version](https://www.terraform.io/downloads.html) Compatibility Matrix - + + + | HashiCorp Terraform Release | HashiCorp Terraform Release Date | HashiCorp Terraform Full Support End Date | MongoDB Atlas Support End Date | |:-------:|:------------:|:------------:|:------------:| | 1.7.x | 2024-01-17 | 2026-01-31 | 2026-01-31 | @@ -189,7 +191,7 @@ For more information on configuring and managing programmatic API Keys see the [ | 1.4.x | 2023-03-08 | 2025-03-31 | 2025-03-31 | | 1.3.x | 2022-09-21 | 2024-09-30 | 2024-09-30 | | 1.2.x | 2022-05-18 | 2024-05-31 | 2024-05-31 | - + For the safety of our users, we require only consuming versions of HashiCorp Terraform that are currently receiving Security / Maintenance Updates. For more details see [Support Period and End-of-Life (EOL) Policy](https://support.hashicorp.com/hc/en-us/articles/360021185113-Support-Period-and-End-of-Life-EOL-Policy). HashiCorp Terraform versions that are not listed on this table are no longer supported by MongoDB Atlas. For latest HashiCorp Terraform versions see [here](https://endoflife.date/terraform ).