1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 | const lib = require('../lib/spaces')
|
6 | const parsers = require('../lib/parsers')()
|
7 | const { flags } = require('@heroku-cli/command')
|
8 | const { RegionCompletion } = require('@heroku-cli/command/lib/completions')
|
9 |
|
10 | function * run (context, heroku) {
|
11 | let space = context.flags.space || context.args.space
|
12 | let dollarAmount = '$1000'
|
13 | let spaceType = 'Standard'
|
14 | if (context.flags['shield']) { dollarAmount = '$3000'; spaceType = 'Shield' }
|
15 | if (!space) throw new Error('Space name required.\nUSAGE: heroku spaces:create --space my-space --team my-team')
|
16 | let team = context.org || context.team || context.flags.team
|
17 | if (!team) throw new Error('No team specified')
|
18 | let request = heroku.request({
|
19 | method: 'POST',
|
20 | path: '/spaces',
|
21 | body: {
|
22 | name: space,
|
23 | team: team,
|
24 | channel_name: context.flags.channel,
|
25 | region: context.flags.region,
|
26 | features: parsers.splitCsv(context.flags.features),
|
27 | log_drain_url: context.flags['log-drain-url'],
|
28 | shield: context.flags['shield'],
|
29 | owner_pool: context.flags['owner-pool'],
|
30 | cidr: context.flags['cidr'],
|
31 | kpi_url: context.flags['kpi-url'],
|
32 | data_cidr: context.flags['data-cidr']
|
33 | }
|
34 | })
|
35 |
|
36 | space = yield cli.action(`Creating space ${cli.color.green(space)} in team ${cli.color.cyan(team)}`, request)
|
37 | cli.warn(`${cli.color.bold('Spend Alert.')} Each Heroku ${spaceType} Private Space costs ${dollarAmount} in Add-on Credits/month (pro-rated to the second).`)
|
38 | cli.warn('Use spaces:wait to track allocation.')
|
39 | cli.styledHeader(space.name)
|
40 | cli.styledObject({
|
41 | ID: space.id,
|
42 | Team: space.team.name,
|
43 | Region: space.region.name,
|
44 | CIDR: space.cidr,
|
45 | 'Data CIDR': space.data_cidr,
|
46 | State: space.state,
|
47 | Shield: lib.displayShieldState(space),
|
48 | 'Created at': space.created_at
|
49 | }, ['ID', 'Team', 'Region', 'CIDR', 'Data CIDR', 'State', 'Shield', 'Created at'])
|
50 | }
|
51 |
|
52 | module.exports = {
|
53 | topic: 'spaces',
|
54 | command: 'create',
|
55 | description: 'create a new space',
|
56 | help: `Example:
|
57 |
|
58 | $ heroku spaces:create --space my-space --team my-team --region oregon
|
59 | Creating space my-space in team my-team... done
|
60 | === my-space
|
61 | ID: e7b99e37-69b3-4475-ad47-a5cc5d75fd9f
|
62 | Team: my-team
|
63 | Region: oregon
|
64 | CIDR: 10.0.0.0/16
|
65 | Data CIDR: 172.23.0.0/20
|
66 | State: allocating
|
67 | Created at: 2016-01-06T03:23:13Z
|
68 |
|
69 | `,
|
70 | needsApp: false,
|
71 | needsAuth: true,
|
72 | wantsOrg: true,
|
73 | args: [{ name: 'space', optional: true, hidden: true }],
|
74 | flags: [
|
75 | { name: 'space', char: 's', hasValue: true, description: 'name of space to create' },
|
76 | { name: 'channel', hasValue: true, hidden: true },
|
77 | { name: 'region', hasValue: true, description: 'region name', completion: RegionCompletion },
|
78 | { name: 'features', hasValue: true, hidden: true, description: 'a list of features separated by commas' },
|
79 | { name: 'log-drain-url', hasValue: true, hidden: true, description: 'direct log drain url' },
|
80 | { name: 'owner-pool', hasValue: true, hidden: true, description: 'owner pool name' },
|
81 | { name: 'shield', hasValue: false, hidden: true, description: 'create a Shield space' },
|
82 | { name: 'cidr', hasValue: true, description: 'RFC-1918 CIDR the space will use' },
|
83 | { name: 'kpi-url', hasValue: true, hidden: true, description: 'self-managed KPI endpoint to use' },
|
84 | { name: 'data-cidr', hasValue: true, description: 'RFC-1918 CIDR used by Heroku Data resources for the space' },
|
85 | flags.team({ name: 'team', hasValue: true })
|
86 | ],
|
87 | run: cli.command(co.wrap(run))
|
88 | }
|