diff --git a/codebuild/buildspec.yml b/codebuild/buildspec.yml index 37dd6dc..5412f4d 100644 --- a/codebuild/buildspec.yml +++ b/codebuild/buildspec.yml @@ -59,7 +59,7 @@ phases: echo "No workspace-specific backend config found; using backend.tf" tf init -input=false fi - - tf workspace select -or-create=true "$TF_WORKSPACE" + - tf workspace select "$TF_WORKSPACE" - echo "Active workspace $(tf workspace show)" build: diff --git a/codebuild/tf b/codebuild/tf index 5da0082..3c6b337 100755 --- a/codebuild/tf +++ b/codebuild/tf @@ -252,7 +252,12 @@ def run_terraform(args): return result.returncode elif args[1] == 'select': # Try to select or create workspace - cmd = [terraform_bin, 'workspace', 'select', '-or-create', args[2]] + # Find the workspace name (last non-flag argument) + ws_name = next((a for a in args[2:] if not a.startswith('-')), None) + if not ws_name: + print("Error: workspace select requires a NAME argument", file=sys.stderr) + return 1 + cmd = [terraform_bin, 'workspace', 'select', '-or-create=true', ws_name] result = subprocess.run(cmd, env=env) if result.returncode == 0: setup_workspace_directories(args[2])