terraform-enterprise-cli 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/terraform-enterprise-command-line.rb +2 -78
- data/lib/terraform_enterprise/command_line/command.rb +5 -4
- data/lib/terraform_enterprise/command_line/commands/configuration_versions.rb +26 -24
- data/lib/terraform_enterprise/command_line/commands/main.rb +80 -0
- data/lib/terraform_enterprise/command_line/commands/oauth_tokens.rb +9 -7
- data/lib/terraform_enterprise/command_line/commands/organizations.rb +21 -19
- data/lib/terraform_enterprise/command_line/commands/policies.rb +58 -56
- data/lib/terraform_enterprise/command_line/commands/policy_checks.rb +19 -17
- data/lib/terraform_enterprise/command_line/commands/runs.rb +71 -69
- data/lib/terraform_enterprise/command_line/commands/teams.rb +24 -22
- data/lib/terraform_enterprise/command_line/commands/variables.rb +51 -49
- data/lib/terraform_enterprise/command_line/commands/workspaces.rb +74 -72
- data/lib/terraform_enterprise/command_line/formatter.rb +4 -1
- data/lib/terraform_enterprise/command_line/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f8ce8edb289989b106e16d161d8c7e6429a34fc938c6366ad77c55a266bcb0f
|
4
|
+
data.tar.gz: '029df67dff6d7626a8f021b366cf4eb5e179cf61d48d558be68c1c5259abb082'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a16d986d9358faee6f58e7f5433007f0c946ef920b57a24ed369dcae2026e53a28c65058ec2ac9493d16d646b0033cbe1e693d862acc5012152e2a3fed2b0b0c
|
7
|
+
data.tar.gz: e7eb62c94f4b534d9117548ef68b4e0360fd02d5536721ca1bef33bcedb8c7e8e3148fe9ca1da71eb72e360dec6174e2a2dba3092ffe253b3b0d523fbf4600fa
|
@@ -1,79 +1,3 @@
|
|
1
|
-
require '
|
1
|
+
require 'terraform_enterprise/command_line/commands/main'
|
2
2
|
|
3
|
-
|
4
|
-
require_relative 'terraform_enterprise/command_line/commands/configuration_versions'
|
5
|
-
require_relative 'terraform_enterprise/command_line/commands/oauth_tokens'
|
6
|
-
require_relative 'terraform_enterprise/command_line/commands/organizations'
|
7
|
-
require_relative 'terraform_enterprise/command_line/commands/policies'
|
8
|
-
require_relative 'terraform_enterprise/command_line/commands/policy_checks'
|
9
|
-
require_relative 'terraform_enterprise/command_line/commands/runs'
|
10
|
-
require_relative 'terraform_enterprise/command_line/commands/teams'
|
11
|
-
require_relative 'terraform_enterprise/command_line/commands/variables'
|
12
|
-
require_relative 'terraform_enterprise/command_line/commands/workspaces'
|
13
|
-
|
14
|
-
module TerraformEnterprise
|
15
|
-
# Terraform Enterprise Command Line class
|
16
|
-
class MainCommand < TerraformEnterprise::CommandLine::Command
|
17
|
-
include TerraformEnterprise::CommandLine
|
18
|
-
|
19
|
-
desc 'organizations <subcommand>', 'Manage organizations'
|
20
|
-
subcommand 'organizations', OrganizationsCommand
|
21
|
-
|
22
|
-
desc 'workspaces <subcommand>', 'Manage workspaces'
|
23
|
-
subcommand 'workspaces', WorkspacesCommand
|
24
|
-
|
25
|
-
desc 'oauth-tokens <subcommand>', 'Manage OAuth tokens'
|
26
|
-
subcommand 'oauth_tokens', OAuthTokensCommand
|
27
|
-
|
28
|
-
desc 'teams <subcommand>', 'Manage teams'
|
29
|
-
subcommand 'teams', TeamsCommand
|
30
|
-
|
31
|
-
desc 'variables <subcommand>', 'Manage variables'
|
32
|
-
subcommand 'variables', VariablesCommand
|
33
|
-
|
34
|
-
desc 'configuration-versions <subcommand>', 'Manage configuration versions'
|
35
|
-
subcommand 'configuration_versions', ConfigurationVersionsCommand
|
36
|
-
|
37
|
-
desc 'policies <subcommand>', 'Manage policies'
|
38
|
-
subcommand 'policies', PoliciesCommand
|
39
|
-
|
40
|
-
desc 'policy-checks <subcommand>', 'Manage policy checks'
|
41
|
-
subcommand 'policy_checks', PolicyChecksCommand
|
42
|
-
|
43
|
-
desc 'runs <subcommand>', 'Manage runs'
|
44
|
-
subcommand 'runs', RunsCommand
|
45
|
-
|
46
|
-
desc 'push <organization>/<workspace>', STRINGS[:push][:commands][:push]
|
47
|
-
option :path, required: true, default: '.', desc: STRINGS[:push][:attributes][:path]
|
48
|
-
def push(name)
|
49
|
-
name_parts = name.split('/')
|
50
|
-
organization_name = name_parts[0]
|
51
|
-
workspace_name = name_parts[1]
|
52
|
-
workspace_params = {
|
53
|
-
organization: organization_name,
|
54
|
-
workspace: workspace_name
|
55
|
-
}
|
56
|
-
|
57
|
-
begin
|
58
|
-
content = tarball(options[:path])
|
59
|
-
rescue
|
60
|
-
error! "could not open that file or directory"
|
61
|
-
end
|
62
|
-
|
63
|
-
# Look up the workspace ID
|
64
|
-
workspace_response = client.workspaces.get(workspace_params)
|
65
|
-
workspace_id = workspace_response&.resource&.id
|
66
|
-
error! "workspace '#{organization_name}/#{workspace_name}' was not found!" unless workspace_id
|
67
|
-
|
68
|
-
# Create a configuration version and get upload-url
|
69
|
-
configuration_version_response = client.configuration_versions.create(workspace: workspace_id)
|
70
|
-
upload_url = (configuration_version_response&.resource&.attributes || {})['upload-url']
|
71
|
-
error! "failed creationg configuration version with workspace id `#{workspace_id}`" unless upload_url
|
72
|
-
|
73
|
-
upload_params = { content: content, url: upload_url }
|
74
|
-
render client.configuration_versions.upload(upload_params)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
TerraformEnterprise::MainCommand.start(ARGV)
|
3
|
+
TerraformEnterprise::CommandLine::Commands::MainCommand.start(ARGV)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'thor'
|
1
2
|
require 'json'
|
2
3
|
require 'terraform-enterprise-client'
|
3
4
|
|
@@ -16,12 +17,12 @@ module TerraformEnterprise
|
|
16
17
|
|
17
18
|
class_option :host, type: :string, desc: CMD_STR[:host]
|
18
19
|
class_option :token, type: :string, desc: CMD_STR[:token]
|
19
|
-
class_option :color, type: :boolean,
|
20
|
+
class_option :color, type: :boolean, desc: CMD_STR[:color]
|
20
21
|
class_option :except, type: :array, desc: CMD_STR[:except]
|
21
22
|
class_option :only, type: :array, desc: CMD_STR[:only]
|
22
|
-
class_option :all, type: :boolean,
|
23
|
-
class_option :value, type: :boolean,
|
24
|
-
class_option :debug, type: :boolean,
|
23
|
+
class_option :all, type: :boolean, desc: CMD_STR[:all]
|
24
|
+
class_option :value, type: :boolean, desc: CMD_STR[:value]
|
25
|
+
class_option :debug, type: :boolean, desc: CMD_STR[:debug]
|
25
26
|
|
26
27
|
no_commands do
|
27
28
|
def render(obj, default_options = {})
|
@@ -2,35 +2,37 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Commands
|
6
|
+
# Configuration Version Commoand
|
7
|
+
class ConfigurationVersionsCommand < TerraformEnterprise::CommandLine::Command
|
8
|
+
ATTR_STR = STRINGS[:configuration_versions][:attributes]
|
9
|
+
CMD_STR = STRINGS[:configuration_versions][:commands]
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
desc 'list', CMD_STR[:list]
|
12
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
13
|
+
option :workspace_id, required: true, type: :string, desc: ATTR_STR[:workspace_id]
|
14
|
+
def list
|
15
|
+
render client.configuration_versions.list(workspace: options[:workspace_id])
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
desc 'create', CMD_STR[:list]
|
19
|
+
option :workspace_id, required: true, type: :string, desc: STRINGS[:options][:workspace_id]
|
20
|
+
def create
|
21
|
+
render client.configuration_versions.create(workspace: options[:workspace_id])
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
desc 'get <id>', CMD_STR[:get]
|
25
|
+
def get(id)
|
26
|
+
render client.configuration_versions.get(id: id)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
desc 'upload <path> <upload-url>', CMD_STR[:upload]
|
30
|
+
def upload(path, url)
|
31
|
+
content = tarball(path)
|
32
|
+
params = { content: content, url: url }
|
32
33
|
|
33
|
-
|
34
|
+
render client.configuration_versions.upload(params)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'terraform_enterprise/command_line/command'
|
2
|
+
|
3
|
+
require_relative 'configuration_versions'
|
4
|
+
require_relative 'oauth_tokens'
|
5
|
+
require_relative 'organizations'
|
6
|
+
require_relative 'policies'
|
7
|
+
require_relative 'policy_checks'
|
8
|
+
require_relative 'runs'
|
9
|
+
require_relative 'teams'
|
10
|
+
require_relative 'variables'
|
11
|
+
require_relative 'workspaces'
|
12
|
+
|
13
|
+
module TerraformEnterprise
|
14
|
+
module CommandLine
|
15
|
+
module Commands
|
16
|
+
# Terraform Enterprise Command Line class
|
17
|
+
class MainCommand < TerraformEnterprise::CommandLine::Command
|
18
|
+
include TerraformEnterprise::CommandLine::Commands
|
19
|
+
|
20
|
+
desc 'organizations <subcommand>', 'Manage organizations'
|
21
|
+
subcommand 'organizations', OrganizationsCommand
|
22
|
+
|
23
|
+
desc 'workspaces <subcommand>', 'Manage workspaces'
|
24
|
+
subcommand 'workspaces', WorkspacesCommand
|
25
|
+
|
26
|
+
desc 'oauth-tokens <subcommand>', 'Manage OAuth tokens'
|
27
|
+
subcommand 'oauth_tokens', OAuthTokensCommand
|
28
|
+
|
29
|
+
desc 'teams <subcommand>', 'Manage teams'
|
30
|
+
subcommand 'teams', TeamsCommand
|
31
|
+
|
32
|
+
desc 'variables <subcommand>', 'Manage variables'
|
33
|
+
subcommand 'variables', VariablesCommand
|
34
|
+
|
35
|
+
desc 'configuration-versions <subcommand>', 'Manage configuration versions'
|
36
|
+
subcommand 'configuration_versions', ConfigurationVersionsCommand
|
37
|
+
|
38
|
+
desc 'policies <subcommand>', 'Manage policies'
|
39
|
+
subcommand 'policies', PoliciesCommand
|
40
|
+
|
41
|
+
desc 'policy-checks <subcommand>', 'Manage policy checks'
|
42
|
+
subcommand 'policy_checks', PolicyChecksCommand
|
43
|
+
|
44
|
+
desc 'runs <subcommand>', 'Manage runs'
|
45
|
+
subcommand 'runs', RunsCommand
|
46
|
+
|
47
|
+
desc 'push <organization>/<workspace>', STRINGS[:push][:commands][:push]
|
48
|
+
option :path, required: true, default: '.', desc: STRINGS[:push][:attributes][:path]
|
49
|
+
def push(name)
|
50
|
+
name_parts = name.split('/')
|
51
|
+
organization_name = name_parts[0]
|
52
|
+
workspace_name = name_parts[1]
|
53
|
+
workspace_params = {
|
54
|
+
organization: organization_name,
|
55
|
+
workspace: workspace_name
|
56
|
+
}
|
57
|
+
|
58
|
+
begin
|
59
|
+
content = tarball(options[:path])
|
60
|
+
rescue
|
61
|
+
error! "could not open that file or directory"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Look up the workspace ID
|
65
|
+
workspace_response = client.workspaces.get(workspace_params)
|
66
|
+
workspace_id = workspace_response&.resource&.id
|
67
|
+
error! "workspace '#{organization_name}/#{workspace_name}' was not found!" unless workspace_id
|
68
|
+
|
69
|
+
# Create a configuration version and get upload-url
|
70
|
+
configuration_version_response = client.configuration_versions.create(workspace: workspace_id)
|
71
|
+
upload_url = (configuration_version_response&.resource&.attributes || {})['upload-url']
|
72
|
+
error! "failed creationg configuration version with workspace id `#{workspace_id}`" unless upload_url
|
73
|
+
|
74
|
+
upload_params = { content: content, url: upload_url }
|
75
|
+
render client.configuration_versions.upload(upload_params)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -2,14 +2,16 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
5
|
+
module Commands
|
6
|
+
class OAuthTokensCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
class_option :organization, required: true, type: :string, desc: STRINGS[:oauth_tokens][:attributes][:organization]
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
desc 'list', STRINGS[:oauth_tokens][:commands][:list]
|
10
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
11
|
+
def list
|
12
|
+
render client.oauth_tokens.list(options)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -2,29 +2,31 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
5
|
+
module Commands
|
6
|
+
class OrganizationsCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
CMD_STR = STRINGS[:organizations][:commands]
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
desc 'list', CMD_STR[:list]
|
10
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
11
|
+
def list
|
12
|
+
render client.organizations.list, only: [:id, :name, 'created-at', :email]
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
desc 'create <name> <email>', CMD_STR[:create]
|
16
|
+
def create(name, email)
|
17
|
+
render client.organizations.create(name: name, email: email)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
desc 'get <name>', CMD_STR[:get]
|
21
|
+
def get(name)
|
22
|
+
render client.organizations.get(name:name)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
desc 'delete <name>', CMD_STR[:delete]
|
26
|
+
def delete(name)
|
27
|
+
render client.organizations.delete(name:name)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
@@ -2,71 +2,73 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Commands
|
6
|
+
class PoliciesCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
ATTR_STR = STRINGS[:policies][:attributes]
|
8
|
+
CMD_STR = STRINGS[:policies][:commands]
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
desc 'list', CMD_STR[:list]
|
11
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
12
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
13
|
+
def list
|
14
|
+
render client.policies.list(organization: options[:organization])
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
desc 'create <name>', CMD_STR[:create]
|
18
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
19
|
+
option :mode, type: :string, required: true, enum: ['soft-mandatory', 'hard-mandatory', 'advisory']
|
20
|
+
def create(name)
|
21
|
+
params = {
|
22
|
+
name: name,
|
23
|
+
organization: options[:organization],
|
24
|
+
enforce: [
|
25
|
+
{
|
26
|
+
path: "#{name}.sentinel",
|
27
|
+
mode: options[:mode]
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
31
|
+
render client.policies.create(params)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
desc 'update <id>', CMD_STR[:create]
|
35
|
+
option :mode, type: :string, required: true, enum: ['soft-mandatory', 'hard-mandatory', 'advisory'], desc: ATTR_STR[:mode]
|
36
|
+
def update(id)
|
37
|
+
name = ''
|
38
|
+
params = {
|
39
|
+
id: id,
|
40
|
+
name: name,
|
41
|
+
enforce: [
|
42
|
+
{
|
43
|
+
path: 'default.sentinel',
|
44
|
+
mode: options[:mode]
|
45
|
+
}
|
46
|
+
]
|
47
|
+
}
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
render client.policies.update(params)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
desc 'get <id>', CMD_STR[:get]
|
53
|
+
def get(id)
|
54
|
+
render client.policies.get(id:id)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
desc 'delete <id>', CMD_STR[:delete]
|
58
|
+
def delete(id)
|
59
|
+
render client.policies.delete(id: id)
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
desc 'upload <path> <policy-id>', CMD_STR[:upload]
|
63
|
+
def upload(path, policy_id)
|
64
|
+
full_path = File.expand_path(path)
|
65
|
+
content = File.read(full_path)
|
65
66
|
|
66
|
-
|
67
|
+
params = { content: content, id: policy_id }
|
67
68
|
|
68
|
-
|
69
|
+
render client.policies.upload(params)
|
70
|
+
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
72
|
-
end
|
74
|
+
end
|
@@ -3,26 +3,28 @@ require 'terraform_enterprise/command_line/util'
|
|
3
3
|
|
4
4
|
module TerraformEnterprise
|
5
5
|
module CommandLine
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module Commands
|
7
|
+
# Configuration Version Commoand
|
8
|
+
class PolicyChecksCommand < TerraformEnterprise::CommandLine::Command
|
9
|
+
include TerraformEnterprise::CommandLine::Util::Tar
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
ATTR_STR = STRINGS[:policy_checks][:attributes]
|
12
|
+
CMD_STR = STRINGS[:policy_checks][:commands]
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
desc 'list', CMD_STR[:list]
|
15
|
+
option :table, type: :boolean, default: false, desc: STRINGS[:options][:table]
|
16
|
+
option :run_id, required: true, type: :string, desc: ATTR_STR[:run_id]
|
17
|
+
def list
|
18
|
+
render client.policy_checks.list(run_id: options[:run_id])
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
desc 'override <policy-check-id>', CMD_STR[:override]
|
22
|
+
option :comment, type: :string, desc: ATTR_STR[:comment]
|
23
|
+
def override(id)
|
24
|
+
params = { id: id, action: :override }
|
25
|
+
params[:comment] = options[:comment] if options[:comment]
|
26
|
+
render client.policy_checks.action(params)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -2,87 +2,89 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Commands
|
6
|
+
class RunsCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
ATTR_STR = STRINGS[:runs][:attributes]
|
8
|
+
CMD_STR = STRINGS[:runs][:commands]
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
desc 'list', CMD_STR[:list]
|
11
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
12
|
+
option :workspace_id, required: true, type: :string, desc: ATTR_STR[:workspace_id]
|
13
|
+
def list
|
14
|
+
render client.runs.list(id: options[:workspace_id]), except: [:permissions]
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
desc 'create', CMD_STR[:create]
|
18
|
+
option :workspace_id, required: true, type: :string, desc: ATTR_STR[:workspace_id]
|
19
|
+
option :configuration_version_id, type: :string, desc: ATTR_STR[:configuration_version_id]
|
20
|
+
option :destroy, type: :boolean, default: false, desc: ATTR_STR[:destroy]
|
21
|
+
def create
|
22
|
+
render client.runs.create(options), except: [:permissions]
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
desc 'get <id>', CMD_STR[:get]
|
26
|
+
def get(id)
|
27
|
+
render client.runs.get(id: id), except: [:permissions]
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
desc 'apply <id>', CMD_STR[:apply]
|
31
|
+
option :comment, type: :string, desc: ATTR_STR[:comment]
|
32
|
+
def apply(id)
|
33
|
+
params = { id: id, action: :apply }
|
34
|
+
params[:comment] = options[:comment] if options[:comment]
|
35
|
+
render client.runs.action(params)
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
desc 'discard <id>', CMD_STR[:discard]
|
39
|
+
option :comment, type: :string, desc: ATTR_STR[:comment]
|
40
|
+
def discard(id)
|
41
|
+
params = { id: id, action: :discard }
|
42
|
+
params[:comment] = options[:comment] if options[:comment]
|
43
|
+
render client.runs.action(params)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
desc 'logs <id>', 'Logs'
|
47
|
+
option :event, type: :string, required: true, desc: ATTR_STR[:event], enum:['plan', 'apply']
|
48
|
+
option :follow, type: :boolean, default: false, desc: ATTR_STR[:follow]
|
49
|
+
def logs(id)
|
50
|
+
following = options[:follow]
|
51
|
+
finished = false
|
52
|
+
exit_requested = false
|
53
|
+
finished_states = %w[errored canceled finished]
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
# Listens for "control-c" to exit
|
56
|
+
Kernel.trap('INT') { exit_requested = true }
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
loop do
|
59
|
+
event = get_event_resource(id, options[:event])
|
60
|
+
url = event.attributes['log-read-url']
|
61
|
+
finished = finished_states.include?(event.attributes['status'].to_s)
|
62
|
+
logs = RestClient.get(url).body
|
63
|
+
|
64
|
+
# errase screen and go to (0,0)
|
65
|
+
print "\033[2J" if following
|
66
|
+
print logs
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
break if !following || exit_requested || finished
|
69
|
+
|
70
|
+
sleep 2
|
71
|
+
end
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
+
private
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
def get_event_resource(id, event)
|
77
|
+
event_type = event == 'plan' ? 'plans' : 'applies'
|
78
|
+
error_message = "#{options[:event].to_s.capitalize} not started yet"
|
79
|
+
run_response = client.runs.get(id: id, include: [event.to_sym])
|
80
|
+
render run_response unless run_response.success?
|
81
|
+
event_resource = run_response.resource.included.find do |er|
|
82
|
+
er.type.to_s == event_type
|
83
|
+
end
|
84
|
+
error! error_message unless event_resource
|
85
|
+
event_resource
|
82
86
|
end
|
83
|
-
error! error_message unless event_resource
|
84
|
-
event_resource
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
88
|
-
end
|
90
|
+
end
|
@@ -2,32 +2,34 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Commands
|
6
|
+
class TeamsCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
ATTR_STR = STRINGS[:teams][:attributes]
|
8
|
+
CMD_STR = STRINGS[:teams][:commands]
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
desc 'list', CMD_STR[:list]
|
11
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
12
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
13
|
+
def list
|
14
|
+
render client.teams.list(organization: options[:organization]), except: [:permissions]
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
desc 'create <name>', CMD_STR[:create]
|
18
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
19
|
+
def create(name)
|
20
|
+
render client.teams.create(name: name, organization: options[:organization])
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
desc 'get <id>', CMD_STR[:get]
|
24
|
+
def get(id)
|
25
|
+
render client.teams.get(id:id), except: [:permissions]
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
desc 'delete <id>', CMD_STR[:delete]
|
29
|
+
def delete(id)
|
30
|
+
render client.teams.delete(id: id), except: [:permissions]
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
35
|
+
end
|
@@ -2,60 +2,62 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Commands
|
6
|
+
class VariablesCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
ATTR_STR = STRINGS[:variables][:attributes]
|
8
|
+
CMD_STR = STRINGS[:variables][:commands]
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
desc 'list', CMD_STR[:list]
|
11
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
12
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
13
|
+
option :workspace, type: :string, desc: ATTR_STR[:workspace]
|
14
|
+
def list
|
15
|
+
render client.variables.list(options)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
desc 'create <key> <value>', CMD_STR[:create]
|
19
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
20
|
+
option :workspace, required: true, type: :string, desc: ATTR_STR[:workspace]
|
21
|
+
option :category, default: 'terraform', type: :string, desc: ATTR_STR[:category], enum:['terraform', 'env']
|
22
|
+
option :hcl, default: false, type: :boolean, desc: ATTR_STR[:hcl]
|
23
|
+
option :sensitive, default: false, type: :boolean, desc: ATTR_STR[:sensitive]
|
24
|
+
def create(key, value)
|
25
|
+
params = {
|
26
|
+
category: options[:category],
|
27
|
+
hcl: options[:hcl],
|
28
|
+
key: key,
|
29
|
+
organization: options[:organization],
|
30
|
+
sensitive: options[:sensitive],
|
31
|
+
value: value,
|
32
|
+
workspace: options[:workspace],
|
33
|
+
}
|
34
|
+
render client.variables.create(params)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
desc 'update <id>', CMD_STR[:update]
|
38
|
+
option :hcl, type: :boolean, desc: ATTR_STR[:hcl]
|
39
|
+
option :sensitive, type: :boolean, desc: ATTR_STR[:sensitive]
|
40
|
+
option :key, type: :string, desc: ATTR_STR[:key]
|
41
|
+
option :value, type: :string, desc: ATTR_STR[:value]
|
42
|
+
def update(id)
|
43
|
+
params = {id: id}
|
44
|
+
params[:hcl] = options[:hcl] if options.include?('hcl')
|
45
|
+
params[:key] = options[:key] if options[:key]
|
46
|
+
params[:sensitive] = options[:sensitive] if options.include?('sensitive')
|
47
|
+
params[:value] = options[:value] if options[:value]
|
48
|
+
render client.variables.update(params)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
desc 'get <id>', CMD_STR[:get]
|
52
|
+
def get(id)
|
53
|
+
render client.variables.get(id:id)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
desc 'delete <id>', CMD_STR[:delete]
|
57
|
+
def delete(id)
|
58
|
+
render client.variables.delete(id: id)
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
61
|
-
end
|
63
|
+
end
|
@@ -2,86 +2,88 @@ require 'terraform_enterprise/command_line/command'
|
|
2
2
|
|
3
3
|
module TerraformEnterprise
|
4
4
|
module CommandLine
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Commands
|
6
|
+
class WorkspacesCommand < TerraformEnterprise::CommandLine::Command
|
7
|
+
ATTR_STR = STRINGS[:workspaces][:attributes]
|
8
|
+
CMD_STR = STRINGS[:workspaces][:commands]
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
desc 'create <name>', CMD_STR[:create]
|
17
|
-
option :terraform_version, type: :string, desc: ATTR_STR[:terraform_version]
|
18
|
-
option :working_directory, type: :string, desc: ATTR_STR[:working_directory]
|
19
|
-
option :oauth_token, type: :string, desc: ATTR_STR[:oauth_token]
|
20
|
-
option :branch, type: :string, desc: ATTR_STR[:branch]
|
21
|
-
option :ingress_submodules, type: :boolean, desc: ATTR_STR[:ingress_submodules]
|
22
|
-
option :repo, type: :string, desc: ATTR_STR[:repos]
|
23
|
-
option :import_legacy_environment, type: :string, desc: ATTR_STR[:import_legacy]
|
24
|
-
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
25
|
-
def create(name)
|
26
|
-
params = {
|
27
|
-
organization: options[:organization],
|
28
|
-
name: name,
|
29
|
-
'working-directory' => options[:working_directory] || '',
|
30
|
-
}
|
31
|
-
if options[:repo] && options[:oauth_token]
|
32
|
-
repo = {}
|
33
|
-
repo['branch'] = options[:branch] || ''
|
34
|
-
repo['identifier'] = options[:repo]
|
35
|
-
repo['oauth-token-id'] = options[:oauth_token]
|
36
|
-
repo['ingress-submodules'] = options[:ingress_submodules] || false
|
37
|
-
params['vcs-repo'] = repo
|
10
|
+
desc 'list', CMD_STR[:list]
|
11
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
12
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
13
|
+
def list
|
14
|
+
render client.workspaces.list(options), except:[:permissions, :actions, :environment, 'created-at']
|
38
15
|
end
|
39
16
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
17
|
+
desc 'create <name>', CMD_STR[:create]
|
18
|
+
option :terraform_version, type: :string, desc: ATTR_STR[:terraform_version]
|
19
|
+
option :working_directory, type: :string, desc: ATTR_STR[:working_directory]
|
20
|
+
option :oauth_token, type: :string, desc: ATTR_STR[:oauth_token]
|
21
|
+
option :branch, type: :string, desc: ATTR_STR[:branch]
|
22
|
+
option :ingress_submodules, type: :boolean, desc: ATTR_STR[:ingress_submodules]
|
23
|
+
option :repo, type: :string, desc: ATTR_STR[:repos]
|
24
|
+
option :import_legacy_environment, type: :string, desc: ATTR_STR[:import_legacy]
|
25
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
26
|
+
def create(name)
|
27
|
+
params = {
|
28
|
+
organization: options[:organization],
|
29
|
+
name: name,
|
30
|
+
'working-directory' => options[:working_directory] || '',
|
31
|
+
}
|
32
|
+
if options[:repo] && options[:oauth_token]
|
33
|
+
repo = {}
|
34
|
+
repo['branch'] = options[:branch] || ''
|
35
|
+
repo['identifier'] = options[:repo]
|
36
|
+
repo['oauth-token-id'] = options[:oauth_token]
|
37
|
+
repo['ingress-submodules'] = options[:ingress_submodules] || false
|
38
|
+
params['vcs-repo'] = repo
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
organization: options[:organization],
|
50
|
-
workspace: name
|
51
|
-
}
|
52
|
-
render client.workspaces.get(params), except:[:permissions, :environment]
|
53
|
-
end
|
41
|
+
params['migration-environment'] = options[:import_legacy_environment] if options[:import_legacy_environment]
|
42
|
+
params['terraform_version'] = options[:terraform_version] if options[:terraform_version]
|
43
|
+
render client.workspaces.create(params), except:[:permissions, :actions, :environment]
|
44
|
+
end
|
54
45
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
46
|
+
desc 'get <name>', CMD_STR[:get]
|
47
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
48
|
+
def get(name)
|
49
|
+
params = {
|
50
|
+
organization: options[:organization],
|
51
|
+
workspace: name
|
52
|
+
}
|
53
|
+
render client.workspaces.get(params), except:[:permissions, :environment]
|
54
|
+
end
|
64
55
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
56
|
+
desc 'delete <name>', CMD_STR[:delete]
|
57
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
58
|
+
def delete(name)
|
59
|
+
params = {
|
60
|
+
organization: options[:organization],
|
61
|
+
workspace: name
|
62
|
+
}
|
63
|
+
render client.workspaces.delete(params), except:[:permissions, :actions, :environment]
|
64
|
+
end
|
75
65
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
66
|
+
desc 'update <name>', CMD_STR[:update]
|
67
|
+
option :working_directory, type: :string, desc: ATTR_STR[:working_directory]
|
68
|
+
option :terraform_version, type: :string, desc: ATTR_STR[:terraform_version]
|
69
|
+
option :auto_apply, type: :boolean, desc: ATTR_STR[:auto_apply]
|
70
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
71
|
+
def update(name)
|
72
|
+
params = options
|
73
|
+
params[:workspace] = name
|
74
|
+
render client.workspaces.update(params), except:[:permissions, :environment]
|
75
|
+
end
|
80
76
|
|
81
|
-
|
82
|
-
|
83
|
-
|
77
|
+
desc 'lock <id>', CMD_STR[:lock]
|
78
|
+
def lock(id)
|
79
|
+
render client.workspaces.action(action: :lock, id: id), except:[:permissions, :environment]
|
80
|
+
end
|
81
|
+
|
82
|
+
desc 'unlock <id>', CMD_STR[:unlock]
|
83
|
+
def unlock(id)
|
84
|
+
render client.workspaces.action(action: :unlock, id: id), except:[:permissions, :environment]
|
85
|
+
end
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
87
|
-
end
|
89
|
+
end
|
@@ -9,7 +9,10 @@ module TerraformEnterprise
|
|
9
9
|
# Module with render method to render the Resource object
|
10
10
|
class Formatter
|
11
11
|
def render(obj, options = {})
|
12
|
-
|
12
|
+
|
13
|
+
if options.include?(:color)
|
14
|
+
String.disable_colorization = !options[:color]
|
15
|
+
end
|
13
16
|
|
14
17
|
if !obj.is_a?(TerraformEnterprise::API::Response)
|
15
18
|
unkown_response(obj)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraform-enterprise-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Skierkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terraform-enterprise-client
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/terraform-enterprise-command-line.rb
|
106
106
|
- lib/terraform_enterprise/command_line/command.rb
|
107
107
|
- lib/terraform_enterprise/command_line/commands/configuration_versions.rb
|
108
|
+
- lib/terraform_enterprise/command_line/commands/main.rb
|
108
109
|
- lib/terraform_enterprise/command_line/commands/oauth_tokens.rb
|
109
110
|
- lib/terraform_enterprise/command_line/commands/organizations.rb
|
110
111
|
- lib/terraform_enterprise/command_line/commands/policies.rb
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.7.
|
141
|
+
rubygems_version: 2.7.6
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: CLI tool for interacting with Terraform Enterprise
|