Skip to content

Commit

Permalink
fix(deployment): improve the provision command to be idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 21, 2021
1 parent 745f90e commit 622bbd8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/deployment/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const waitForStatus = ({ setup, running }) => async (
};

const provisionOutput = async ({ rd, wr, running }) => {
const jsonFile = `${PROVISION_DIR}/terraform.json`;
const jsonFile = `${PROVISION_DIR}/terraform-output.json`;
await makeGuardFile({ rd, wr })(jsonFile, async makeFile => {
const json = await running.needBacktick(`terraform output -json`);
await makeFile(json);
Expand Down Expand Up @@ -859,11 +859,15 @@ ${chalk.yellow.bold(`ag-setup-solo --netconfig='${dwebHost}/network-config'`)}

case 'provision': {
await inited();
if (!(await rd.exists('.terraform'))) {
await needDoRun(['terraform', 'init']);
}

// Remove everything that provisioning affects.
await needDoRun(['rm', '-rf', PROVISION_DIR]);

// It is always safe to init.
await needDoRun(['terraform', 'init']);

// Apply the provisioning plan.
await needDoRun(['terraform', 'apply', ...args.slice(1)]);
await needDoRun(['rm', '-f', `${PROVISION_DIR}/*.stamp`]);
break;
}

Expand Down

0 comments on commit 622bbd8

Please sign in to comment.