@@ -109,30 +109,42 @@ const getScript = (env, reverse) => {
109
109
});
110
110
}
111
111
112
+ const getTerraformOpts = (env) => {
113
+ const i = env.TLN_CLOUDS_INIT?' --init':'';
114
+ const p = env.TLN_CLOUDS_PLAN?' --plan':'';
115
+ const a = env.TLN_CLOUDS_APPLY?' --apply':'';
116
+ const aa = env.TLN_CLOUDS_AUTO_APPROVE?' -auto-approve':'';
117
+ return `${i}${p}${a}${aa}`;
118
+ }
119
+
112
120
module.exports = {
113
121
options: async (tln, args) => {
114
122
args
115
123
.prefix('TLN_CLOUDS')
116
124
.option('backend', { describe: 'Defines which backend provider should be used (cloud, pg)', default: null, type: 'string' })
117
125
.option('tenant', { describe: 'Tenant Id', default: null, type: 'string' })
118
- .option('state', { describe: 'Defines how store name will be built: project,provider,group,env,layer,tenant,<custom_string>', default: 'project,provider,group,env,layer' , type: 'string' })
126
+ .option('state', { describe: 'Defines how store name will be built: project,provider,group,env,layer,tenant,<custom_string>', default: null , type: 'string' })
119
127
.option('init', { describe: 'Run Terraform init', default: false, type: 'boolean' })
120
128
.option('upgrade', { describe: 'Run Terraform upgrade mode for init', default: false, type: 'boolean' })
121
129
.option('plan', { describe: 'Run Terraform plan', default: false, type: 'boolean' })
122
130
.option('apply', { describe: 'Run Terraform apply', default: false, type: 'boolean' })
123
131
.option('auto-approve', { describe: 'Tun on auto approve for apply & destroy', default: false, type: 'boolean' })
124
- .option('layers', { describe: 'Select which layers will be included', default: "network,managed" , type: 'string' })
132
+ .option('layers', { describe: 'Select which layers will be included', default: null , type: 'string' })
125
133
.option('bastion', { describe: 'Bastion address in form user@ip', default: null, type: 'string' })
126
- .option('bridge-port', { describe: 'Local port for bridge to bastion ', default: '8888', type: 'string' })
127
134
.option('deamon', { describe: 'Deamon mode for SSH connection', default: false, type: 'boolean' })
135
+ .option('ci', { describe: 'CI mode', default: false, type: 'boolean' })
136
+ /*
137
+ DEPRIECATED
138
+ .option('bridge-port', { describe: 'Local port for bridge to bastion ', default: '8888', type: 'string' })
139
+ */
128
140
;
129
141
},
130
142
env: async (tln, env) => {
131
143
if (env.TLN_CLOUDS_TENANT) {
132
144
env.TF_VAR_tenant_id = env.TLN_CLOUDS_TENANT;
133
145
}
134
146
},
135
- dotenvs: async (tln) => ['.env'],
147
+ dotenvs: async (tln) => { if (fs.existsSync('.env')) return ['.env']; else return [] } ,
136
148
inherits: async (tln) => [],
137
149
depends: async (tln) => [],
138
150
steps: async (tln) => [
@@ -145,16 +157,15 @@ module.exports = {
145
157
}
146
158
},
147
159
{ id: 'get-bastion', builder: async (tln, script) => {
148
- script.set([
149
- `tln exec -c 'cd network && terraform output bastion_remote_address'`,
150
- ]);
160
+ script.set([`cat './network/${script.env.TF_VAR_env_id}-bastion.addr'`]);
151
161
}},
152
- { id: 'bridge', builder: async (tln, script) => {
153
- const port = script.env.TLN_CLOUDS_BRIDGE_PORT;
162
+ { id: 'sshuttle', builder: async (tln, script) => {
163
+ const daemon = script.env.TLN_CLOUDS_DEAMON ? ' --daemon' : '';
164
+ const ci = script.env.TLN_CLOUDS_CI ? ' -q -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' : '';
154
165
switch (script.env.TLN_COMPONENT_ID) {
155
166
case 'aws':
156
167
script.set([`
157
- ssh -i ./network/ ${script.env.TF_VAR_env_id}-bastion -ssh-key.pem -L${port}:127.0.0.1:${port} ${ script.env.TLN_CLOUDS_BASTION}
168
+ sshuttle --dns${daemon} -vr ${script.env.TLN_CLOUDS_BASTION} 0/0 - -ssh-cmd 'ssh${ci} -i ./network/${ script.env.TF_VAR_env_id}-bastion-ssh-key.pem'
158
169
`]);
159
170
break;
160
171
case 'azure':
@@ -165,27 +176,68 @@ ssh -i ./network/${script.env.TF_VAR_env_id}-bastion-ssh-key.pem -L${port}:127.0
165
176
}
166
177
},
167
178
{ id: 'connect', builder: async (tln, script) => {
179
+ script.set([
180
+ `tln sshuttle -- --bastion $(tln get-bastion)`
181
+ ]);
182
+ }
183
+ },
184
+ { id: 'up', builder: async (tln, script) => {
185
+ const opts = getTerraformOpts(script.env);
186
+ script.set([`
187
+ tln construct -- --backend cloud${opts} --layers provider --state project,provider
188
+ tln construct -- --backend cloud${opts} --layers group --state project,provider,group
189
+ tln construct -- --backend cloud${opts} --layers network,managed --state project,provider,group,env,layer
190
+ ${script.env.TLN_CLOUDS_CI ? 'tln sshuttle -- --bastion \$(tln get-bastion) --deamon' : ''}
191
+ tln construct -- --backend cloud${opts} --layers app --state project,provider,group,env,layer
192
+ `].concat(
193
+ (script.env.TF_VAR_tenant_id) ? [
194
+ `tln construct -- --backend cloud${opts} --layers tenant --state project,provider,group,env,tenant --tenant ${script.env.TF_VAR_tenant_id}`
195
+ ]:[]
196
+ ));
197
+ }
198
+ },
199
+ { id: 'down', builder: async (tln, script) => {
200
+ const opts = getTerraformOpts(script.env);
201
+ script.set([
202
+ `${script.env.TLN_CLOUDS_CI ? 'tln sshuttle -- --bastion \$(tln get-bastion) --deamon' : ''}`,
203
+ ].concat((
204
+ (script.env.TF_VAR_tenant_id) ? [
205
+ `tln deconstruct -- --backend cloud${opts} --layers tenant --state project,provider,group,env,tenant --tenant ${script.env.TF_VAR_tenant_id}`,
206
+ ]:[]
207
+ )).concat([`
208
+ tln deconstruct -- --backend cloud${opts} --layers network,managed,app --state project,provider,group,env,layer
209
+ tln deconstruct -- --backend cloud${opts} --layers group --state project,provider,group
210
+ tln deconstruct -- --backend cloud${opts} --layers provider --state project,provider
211
+ `]
212
+ ));
213
+ }
214
+ },
215
+ /*
216
+ DEPRIECATED
217
+ { id: 'bridge', builder: async (tln, script) => {
168
218
const port = script.env.TLN_CLOUDS_BRIDGE_PORT;
169
219
switch (script.env.TLN_COMPONENT_ID) {
170
220
case 'aws':
171
221
script.set([`
172
- export HTTPS_PROXY=127.0.0.1:${port}
173
- tln shell
222
+ ssh -i ./network/${script.env.TF_VAR_env_id}-bastion-ssh-key.pem -L${port}:127.0.0.1:${port} ${script.env.TLN_CLOUDS_BASTION}
174
223
`]);
175
224
break;
176
225
case 'azure':
177
226
break;
178
227
case 'gcp':
179
228
break;
229
+ case 'do':
230
+ break;
180
231
}
181
232
}
182
233
},
183
- { id: 'sshuttle ', builder: async (tln, script) => {
184
- const daemon = script.env.TLN_CLOUDS_DEAMON ? ' --daemon' : '' ;
234
+ { id: 'connect ', builder: async (tln, script) => {
235
+ const port = script.env.TLN_CLOUDS_BRIDGE_PORT ;
185
236
switch (script.env.TLN_COMPONENT_ID) {
186
237
case 'aws':
187
238
script.set([`
188
- sshuttle --dns${daemon} -vr ${script.env.TLN_CLOUDS_BASTION} 0/0 --ssh-cmd 'ssh -i ./network/${script.env.TF_VAR_env_id}-bastion-ssh-key.pem'
239
+ export HTTPS_PROXY=127.0.0.1:${port}
240
+ tln shell
189
241
`]);
190
242
break;
191
243
case 'azure':
@@ -195,30 +247,7 @@ sshuttle --dns${daemon} -vr ${script.env.TLN_CLOUDS_BASTION} 0/0 --ssh-cmd 'ssh
195
247
}
196
248
}
197
249
},
198
- { id: 'up', builder: async (tln, script) => {
199
- const tenant = (script.env.TF_VAR_tenant_id) ? `tln construct -- --backend cloud --init --apply --layers tenant --state project,provider,group,env,tenant --tenant ${script.env.TF_VAR_tenant_id}` : '';
200
- script.set([`
201
- tln construct -- --backend cloud --init --apply --layers provider --state project,provider
202
- tln construct -- --backend cloud --init --apply --layers group --state project,provider,group
203
- tln construct -- --backend cloud --init --apply --layers network
204
- #tln sshuttle -- --bastion user@ip --deamon
205
- tln construct -- --backend cloud --init --apply --layers managed,app
206
- ${tenant}
207
- `]);
208
- }
209
- },
210
- { id: 'down', builder: async (tln, script) => {
211
- const tenant = (script.env.TF_VAR_tenant_id) ? `tln deconstruct -- --backend cloud --init --apply --layers tenant --state project,provider,group,env,tenant --tenant ${script.env.TF_VAR_tenant_id}` : ''
212
- script.set([`
213
- #tln sshuttle -- --bastion user@ip --deamon
214
- ${tenant}
215
- tln deconstruct -- --backend cloud --init --apply --layers network,managed,app
216
- tln deconstruct -- --backend cloud --init --apply --layers group --state project,provider,group
217
- tln deconstruct -- --backend cloud --init --apply --layers provider --state project,provider
218
- `]);
219
- }
220
- },
221
-
250
+ */
222
251
],
223
252
components: async (tln) => []
224
253
}
0 commit comments