polkadot-secure-validator
Advanced tools
Comparing version 0.1.3 to 0.2.0
{ | ||
"name": "polkadot-secure-validator", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"main": "src/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/w3f/polkadot-secure-validator", |
@@ -62,4 +62,5 @@ const fs = require('fs-extra'); | ||
const tfPath = this._terraformNodeDirPath(type, counter); | ||
const backendConfig = this._backendConfig(nodes[counter]); | ||
createPromises.push(this._createPromise(tfPath, sshKey, nodes[counter], backendConfig)); | ||
const backendConfig = this._backendConfig(type, counter); | ||
const nodeName = this._nodeName(type, counter); | ||
createPromises.push(this._createPromise(tfPath, sshKey, nodes[counter], backendConfig, nodeName)); | ||
} | ||
@@ -69,7 +70,7 @@ return Promise.all(createPromises); | ||
async _createPromise(cwd, sshKey, node, backendConfig) { | ||
async _createPromise(cwd, sshKey, node, backendConfig, nodeName) { | ||
const options = { cwd }; | ||
await this._cmd(`init -var state_project=${this.config.state.project} -backend-config=bucket=${backendConfig.bucket} -backend-config=prefix=${backendConfig.prefix}`, options); | ||
this._createVarsFile(cwd, node, sshKey); | ||
this._createVarsFile(cwd, node, sshKey, nodeName); | ||
@@ -84,3 +85,3 @@ return this._cmd(`apply -auto-approve`, options); | ||
const tfPath = this._terraformNodeDirPath(type, counter) | ||
const backendConfig = this._backendConfig(nodes[counter]); | ||
const backendConfig = this._backendConfig(type, counter); | ||
destroyPromises.push(this._destroyPromise(tfPath, backendConfig)); | ||
@@ -108,6 +109,7 @@ } | ||
await this._cmd(`init -var state_project=${this.config.state.project}`, options); | ||
return this._cmd(`apply -var state_project=${this.config.state.project} -var name=${this.config.project} -auto-approve`, options); | ||
const bucketName = this._bucketName() | ||
return this._cmd(`apply -var state_project=${this.config.state.project} -var name=${bucketName} -auto-approve`, options); | ||
} | ||
_createVarsFile(cwd, node, sshKey) { | ||
_createVarsFile(cwd, node, sshKey, nodeName) { | ||
const data = { | ||
@@ -122,3 +124,3 @@ stateProject: this.config.state.project, | ||
nodeCount: node.count || 1, | ||
name: this.config.project | ||
name: nodeName | ||
} | ||
@@ -149,17 +151,36 @@ | ||
const originDirPath = path.join(this.terraformOriginPath, provider); | ||
fs.ensureDirSync(targetDirPath); | ||
fs.copySync(originDirPath, targetDirPath); | ||
const name = this._nodeName(type, counter); | ||
fs.readdirSync(originDirPath).forEach((item) => { | ||
const origin = path.join(originDirPath, item); | ||
const target = path.join(targetDirPath, item); | ||
const data = { | ||
name | ||
}; | ||
tpl.create(origin, target, data); | ||
}); | ||
} | ||
_terraformNodeDirPath(type, counter=0) { | ||
const dirName = `${type}-${counter}`; | ||
const dirName = this._nodeName(type, counter); | ||
return path.join(this.terraformFilesPath, dirName); | ||
} | ||
_backendConfig(node) { | ||
const bucket = `${this.config.project}-sv-tf-state`; | ||
const prefix = node.provider; | ||
_backendConfig(type, counter) { | ||
const bucket = this._bucketName(); | ||
const prefix = this._nodeName(type, counter); | ||
return { bucket, prefix }; | ||
} | ||
_bucketName() { | ||
return `${this.config.project}-sv-tf-state` | ||
} | ||
_nodeName(type, counter) { | ||
const name = `${type}${counter}`; | ||
return name.toLowerCase(); | ||
} | ||
} | ||
@@ -166,0 +187,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
122050
585