Skip to content

Commit

Permalink
Merge pull request #13 from karmaniverous:bugfix/GH-12-metastructure-…
Browse files Browse the repository at this point in the history
…attempts-to-switch-workspaces-before-terraform-init

[GH-12] excluded terraform init from workspace switch
  • Loading branch information
karmaniverous authored Aug 12, 2024
2 parents 68a1984 + 137519c commit 4d39171
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/cli/metastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,27 @@ const cli = new Command()
});

// Check workspace & switch if necessary.
const { stdout } = await $`terraform workspace show`;
if (stdout !== workspace) {
console.log(chalk.black.bold('Switching workspace...\n'));
await $({
stdio: 'inherit',
})`terraform workspace select -or-create=true ${workspace}`;
const flatCmd = command.join(' ');

const cleanCmd = flatCmd.toLowerCase().replace(/\s+/g, ' ');

if (!cleanCmd.includes('terraform init')) {
const { stdout } = await $`terraform workspace show`;

if (stdout !== workspace) {
console.log(chalk.black.bold('Switching workspace...\n'));
await $({
stdio: 'inherit',
})`terraform workspace select -or-create=true ${workspace}`;
}
}

console.log(chalk.black.bold('Running command...\n'));

await $({
stdio: 'inherit',
})(command.join(' '));
})(flatCmd);

console.log(chalk.green.bold('\nDone!\n'));
} catch (error) {
console.log(chalk.red.bold('\nCommand failed!\n'));
Expand Down

0 comments on commit 4d39171

Please sign in to comment.