From 84e93690ba8da07421f1e25fd8f9c6a2d341a5f2 Mon Sep 17 00:00:00 2001 From: Andreas Kohn Date: Sat, 16 Mar 2024 22:22:34 +0100 Subject: [PATCH] Support glob matching for `workspaces` --- migrator.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/migrator.py b/migrator.py index 60a9e62..945d952 100644 --- a/migrator.py +++ b/migrator.py @@ -1,5 +1,6 @@ import binascii import click +import fnmatch import hashlib import json import requests @@ -297,6 +298,12 @@ def migrate_state(): for tf_state in fetch_tfc("state-versions", state_filters)["data"]: create_state(tf_state, workspace["data"]["id"]) + def should_migrate_workspace(workspace_name): + for workspace in workspaces: + if fnmatch.fnmatch(workspace_name, workspace): + return True + return False + def migrate_variables(): print("Migrating variables...") @@ -364,7 +371,8 @@ def migrate_variables(): for tf_workspace in tfc_workspaces["data"]: workspace_name = tf_workspace["attributes"]["name"] - if workspace_name not in workspaces and "*" not in workspaces: + if not should_migrate_workspace(workspace_name): + print(f"Skipping workspace {workspace_name}...") continue workspace_exists = fetch_scalr(