From 544bf01fbbea0b8c60a3ea2ea71d169b13f8a92e Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 19 Aug 2022 17:18:11 +0300 Subject: [PATCH] chore: Update `coder/coder` provider in example templates (#3581) Additionally, a convenience script was added to `examples/update_template_versions.sh` to keep the templates up-to-date. Fixes #2966 --- examples/templates/aws-linux/main.tf | 2 +- examples/templates/aws-windows/main.tf | 2 +- examples/templates/azure-linux/main.tf | 2 +- examples/templates/do-linux/main.tf | 2 +- examples/templates/docker-code-server/main.tf | 2 +- .../templates/docker-image-builds/main.tf | 2 +- .../templates/docker-with-dotfiles/main.tf | 2 +- examples/templates/docker/main.tf | 2 +- examples/templates/gcp-linux/main.tf | 2 +- examples/templates/gcp-vm-container/main.tf | 2 +- examples/templates/gcp-windows/main.tf | 2 +- .../kubernetes-multi-service/main.tf | 2 +- examples/update_template_versions.sh | 37 +++++++++++++++++++ 13 files changed, 49 insertions(+), 12 deletions(-) create mode 100755 examples/update_template_versions.sh diff --git a/examples/templates/aws-linux/main.tf b/examples/templates/aws-linux/main.tf index 3cc75d4513..6208ccc0fd 100644 --- a/examples/templates/aws-linux/main.tf +++ b/examples/templates/aws-linux/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } } } diff --git a/examples/templates/aws-windows/main.tf b/examples/templates/aws-windows/main.tf index d783e98518..2a72693aa2 100644 --- a/examples/templates/aws-windows/main.tf +++ b/examples/templates/aws-windows/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } } } diff --git a/examples/templates/azure-linux/main.tf b/examples/templates/azure-linux/main.tf index 667a29eb06..f5f82ae20e 100644 --- a/examples/templates/azure-linux/main.tf +++ b/examples/templates/azure-linux/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } azurerm = { source = "hashicorp/azurerm" diff --git a/examples/templates/do-linux/main.tf b/examples/templates/do-linux/main.tf index 9a8de352fe..6af96c9e6b 100644 --- a/examples/templates/do-linux/main.tf +++ b/examples/templates/do-linux/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } digitalocean = { source = "digitalocean/digitalocean" diff --git a/examples/templates/docker-code-server/main.tf b/examples/templates/docker-code-server/main.tf index 0597afc4eb..5b443045a3 100644 --- a/examples/templates/docker-code-server/main.tf +++ b/examples/templates/docker-code-server/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } docker = { source = "kreuzwerker/docker" diff --git a/examples/templates/docker-image-builds/main.tf b/examples/templates/docker-image-builds/main.tf index bccd2ddbe7..8f9a17bc2f 100644 --- a/examples/templates/docker-image-builds/main.tf +++ b/examples/templates/docker-image-builds/main.tf @@ -3,7 +3,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } docker = { source = "kreuzwerker/docker" diff --git a/examples/templates/docker-with-dotfiles/main.tf b/examples/templates/docker-with-dotfiles/main.tf index f8157ae20f..f09cdc4a6f 100644 --- a/examples/templates/docker-with-dotfiles/main.tf +++ b/examples/templates/docker-with-dotfiles/main.tf @@ -9,7 +9,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } docker = { source = "kreuzwerker/docker" diff --git a/examples/templates/docker/main.tf b/examples/templates/docker/main.tf index 9d39a9388a..1f494737c5 100644 --- a/examples/templates/docker/main.tf +++ b/examples/templates/docker/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } docker = { source = "kreuzwerker/docker" diff --git a/examples/templates/gcp-linux/main.tf b/examples/templates/gcp-linux/main.tf index e009116ce0..465441c43d 100644 --- a/examples/templates/gcp-linux/main.tf +++ b/examples/templates/gcp-linux/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } google = { source = "hashicorp/google" diff --git a/examples/templates/gcp-vm-container/main.tf b/examples/templates/gcp-vm-container/main.tf index 59b0b266f0..c186a8c09c 100644 --- a/examples/templates/gcp-vm-container/main.tf +++ b/examples/templates/gcp-vm-container/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } google = { source = "hashicorp/google" diff --git a/examples/templates/gcp-windows/main.tf b/examples/templates/gcp-windows/main.tf index 3a0d2dd0b5..1850a86861 100644 --- a/examples/templates/gcp-windows/main.tf +++ b/examples/templates/gcp-windows/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "0.4.5" + version = "0.4.9" } google = { source = "hashicorp/google" diff --git a/examples/templates/kubernetes-multi-service/main.tf b/examples/templates/kubernetes-multi-service/main.tf index 1ee9533c4b..118c258bc2 100644 --- a/examples/templates/kubernetes-multi-service/main.tf +++ b/examples/templates/kubernetes-multi-service/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "~> 0.4.3" + version = "0.4.9" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/examples/update_template_versions.sh b/examples/update_template_versions.sh new file mode 100755 index 0000000000..d747b36460 --- /dev/null +++ b/examples/update_template_versions.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -euo pipefail + +EXAMPLES_DIR=$(dirname "${BASH_SOURCE[0]}") +PROJECT_ROOT=$(cd "$EXAMPLES_DIR" && git rev-parse --show-toplevel) + +# shellcheck source=scripts/lib.sh +source "$PROJECT_ROOT/scripts/lib.sh" + +dependencies curl jq sed + +sed_args=(-i) +if isdarwin; then + sed_args=(-i '') +fi + +main() { + pushd "$EXAMPLES_DIR/templates" + + # Fetch the latest release of terraform-provider-coder from GitHub. + latest_provider_coder="$(curl --fail -sSL https://api.github.com/repos/coder/terraform-provider-coder/releases/latest | jq -r .tag_name)" + latest_provider_coder=${latest_provider_coder#v} + + # Update all terraform files that contain ~ the following lines: + # source = "coder/coder" + # version = "[version]" + find . -type f -name "*.tf" -print0 | while read -r -d $'\0' f; do + current_version_raw="$(grep -n -A 1 'source *= *"coder/coder"' "$f" | tail -n 1)" + if [[ $current_version_raw = *version* ]]; then + line="${current_version_raw%%-*}" + sed "${sed_args[@]}" "$line s/\".*\"/\"$latest_provider_coder\"/" "$f" + fi + done +} + +# Wrap the main function in a subshell to restore the working directory. +(main)