private createTerraformCommands()

in packages/cli/lib/mdaa-cli.ts [465:509]


  private createTerraformCommands(moduleConfig: ModuleEffectiveConfig): string[] {
    const tfAction = MdaaDeploy.TF_ACTION_MAPPINGS[this.action] ?? this.action;

    this.createTerraformOverride(moduleConfig);
    const tfCmds: string[] = [];
    if (this.config.contents.region && this.config.contents.region.toLowerCase() != 'default') {
      tfCmds.push(`export AWS_DEFAULT_REGION=${this.config.contents.region}`);
    }
    tfCmds.push(`terraform init `);
    const checkovCmd: string[] = [
      `export PYTHONPATH=${this.workingDir}/python && ${this.workingDir}/python/bin/checkov -d ${moduleConfig.modulePath}`,
    ];
    checkovCmd.push('--summary-position bottom');
    checkovCmd.push('--quiet');
    checkovCmd.push('--compact');
    checkovCmd.push('--download-external-modules true');
    tfCmds.push(checkovCmd.join(' \\\n\t'));
    if (tfAction == 'plan') {
      const tfPlanCmd: string[] = [];
      if (this.config.contents.region && this.config.contents.region.toLowerCase() != 'default') {
        tfPlanCmd.push(`export AWS_DEFAULT_REGION=${this.config.contents.region}`);
      }
      tfPlanCmd.push('terraform plan');
      tfPlanCmd.push(...this.createTerraformPlanApplyCmdArgs(moduleConfig));
      tfPlanCmd.push(`--out ${moduleConfig.modulePath}/tfplan.binary`);
      tfCmds.push(tfPlanCmd.join(' \\\n\t'));
    } else if (tfAction == 'apply') {
      const tfApplyCmd: string[] = [];
      if (this.config.contents.region && this.config.contents.region.toLowerCase() != 'default') {
        tfApplyCmd.push(`export AWS_DEFAULT_REGION=${this.config.contents.region}`);
      }
      tfApplyCmd.push('terraform apply');
      tfApplyCmd.push('-auto-approve');
      tfApplyCmd.push(...this.createTerraformPlanApplyCmdArgs(moduleConfig));
      tfCmds.push(tfApplyCmd.join(' \\\n\t'));
    } else {
      const tfCmd: string[] = [];
      if (this.config.contents.region && this.config.contents.region.toLowerCase() != 'default') {
        tfCmd.push(`export AWS_DEFAULT_REGION=${this.config.contents.region}`);
      }
      tfCmd.push(`terraform ${tfAction}`);
      tfCmds.push(tfCmd.join(' \\\n\t'));
    }
    return tfCmds;
  }