terraspace 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/aws/bin/build.sh +2 -0
- data/.cody/azurerm/bin/build.sh +2 -0
- data/.cody/google/bin/build.sh +2 -0
- data/CHANGELOG.md +38 -0
- data/README.md +2 -2
- data/lib/templates/base/project/README.md +1 -1
- data/lib/terraspace.rb +2 -0
- data/lib/terraspace/all/preview.rb +1 -1
- data/lib/terraspace/all/runner.rb +1 -0
- data/lib/terraspace/all/summary.rb +29 -2
- data/lib/terraspace/app.rb +9 -5
- data/lib/terraspace/builder.rb +11 -12
- data/lib/terraspace/cli.rb +33 -39
- data/lib/terraspace/cli/all.rb +15 -9
- data/lib/terraspace/cli/bundle.rb +2 -1
- data/lib/terraspace/cli/clean.rb +18 -6
- data/lib/terraspace/cli/clean/all.rb +18 -0
- data/lib/terraspace/cli/clean/base.rb +15 -0
- data/lib/terraspace/cli/clean/cache.rb +25 -0
- data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
- data/lib/terraspace/cli/cloud.rb +3 -9
- data/lib/terraspace/cli/cloud/runs.rb +0 -2
- data/lib/terraspace/cli/help/all/down.md +32 -0
- data/lib/terraspace/cli/help/all/graph.md +21 -0
- data/lib/terraspace/cli/help/all/output.md +22 -0
- data/lib/terraspace/cli/help/all/plan.md +25 -0
- data/lib/terraspace/cli/help/all/providers.md +21 -0
- data/lib/terraspace/cli/help/all/refresh.md +17 -0
- data/lib/terraspace/cli/help/all/show.md +21 -0
- data/lib/terraspace/cli/help/all/up.md +27 -0
- data/lib/terraspace/cli/help/all/validate.md +21 -0
- data/lib/terraspace/cli/help/build.md +6 -0
- data/lib/terraspace/cli/help/bundle.md +9 -5
- data/lib/terraspace/cli/help/check_setup.md +9 -0
- data/lib/terraspace/cli/help/clean/all.md +10 -0
- data/lib/terraspace/cli/help/clean/cache.md +12 -0
- data/lib/terraspace/cli/help/clean/logs.md +17 -0
- data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
- data/lib/terraspace/cli/help/cloud/list.md +7 -0
- data/lib/terraspace/cli/help/cloud/runs/list.md +3 -3
- data/lib/terraspace/cli/help/cloud/runs/prune.md +2 -2
- data/lib/terraspace/cli/help/cloud/sync.md +26 -2
- data/lib/terraspace/cli/help/console.md +8 -0
- data/lib/terraspace/cli/help/down.md +26 -0
- data/lib/terraspace/cli/help/info.md +43 -0
- data/lib/terraspace/cli/help/init.md +37 -0
- data/lib/terraspace/cli/help/list.md +20 -0
- data/lib/terraspace/cli/help/logs.md +48 -0
- data/lib/terraspace/cli/help/logs/remove.md +5 -0
- data/lib/terraspace/cli/help/logs/truncate.md +5 -0
- data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
- data/lib/terraspace/cli/help/new/example.md +8 -0
- data/lib/terraspace/cli/help/new/git_hook.md +6 -0
- data/lib/terraspace/cli/help/new/module.md +9 -0
- data/lib/terraspace/cli/help/new/module_test.md +12 -0
- data/lib/terraspace/cli/help/new/plugin.md +49 -0
- data/lib/terraspace/cli/help/new/project.md +40 -0
- data/lib/terraspace/cli/help/new/project_test.md +8 -0
- data/lib/terraspace/cli/help/new/shim.md +21 -0
- data/lib/terraspace/cli/help/new/stack.md +9 -0
- data/lib/terraspace/cli/help/output.md +6 -0
- data/lib/terraspace/cli/help/plan.md +29 -0
- data/lib/terraspace/cli/help/providers.md +18 -0
- data/lib/terraspace/cli/help/refresh.md +11 -0
- data/lib/terraspace/cli/help/seed.md +7 -0
- data/lib/terraspace/cli/help/show.md +36 -0
- data/lib/terraspace/cli/help/summary.md +11 -0
- data/lib/terraspace/cli/help/test.md +35 -0
- data/lib/terraspace/cli/help/up.md +30 -0
- data/lib/terraspace/cli/help/validate.md +9 -0
- data/lib/terraspace/cli/info.rb +4 -16
- data/lib/terraspace/cli/init.rb +3 -7
- data/lib/terraspace/cli/logs.rb +106 -9
- data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
- data/lib/terraspace/cli/new.rb +18 -18
- data/lib/terraspace/cli/new/git_hook.rb +4 -1
- data/lib/terraspace/cli/new/helper.rb +9 -2
- data/lib/terraspace/cli/new/project.rb +1 -1
- data/lib/terraspace/cli/summary.rb +2 -2
- data/lib/terraspace/command.rb +1 -1
- data/lib/terraspace/compiler/backend.rb +10 -0
- data/lib/terraspace/compiler/builder.rb +2 -1
- data/lib/terraspace/compiler/commands_concern.rb +18 -0
- data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
- data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
- data/lib/terraspace/compiler/erb/context.rb +1 -1
- data/lib/terraspace/compiler/erb/helpers.rb +6 -0
- data/lib/terraspace/dependency/graph.rb +2 -1
- data/lib/terraspace/dependency/helper/base.rb +7 -0
- data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
- data/lib/terraspace/dependency/helper/output.rb +11 -0
- data/lib/terraspace/hooks/builder.rb +52 -0
- data/lib/terraspace/hooks/concern.rb +9 -0
- data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
- data/lib/terraspace/hooks/runner.rb +23 -0
- data/lib/terraspace/mod.rb +11 -2
- data/lib/terraspace/plugin/summary/interface.rb +4 -2
- data/lib/terraspace/shell.rb +50 -17
- data/lib/terraspace/terraform/args/custom.rb +1 -1
- data/lib/terraspace/terraform/cloud/runs/lister.rb +0 -2
- data/lib/terraspace/terraform/cloud/syncer.rb +2 -2
- data/lib/terraspace/terraform/cloud/workspace.rb +0 -9
- data/lib/terraspace/terraform/remote_state/fetcher.rb +37 -7
- data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
- data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
- data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
- data/lib/terraspace/terraform/runner.rb +2 -7
- data/lib/terraspace/version.rb +1 -1
- data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
- data/spec/fixtures/fetcher/c1.json +4 -0
- data/spec/terraspace/all/summary_spec.rb +1 -1
- data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
- data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
- data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
- data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
- data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
- data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
- data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
- data/terraspace.gemspec +1 -1
- metadata +78 -13
- data/lib/terraspace/cli/help/log.md +0 -42
- data/lib/terraspace/cli/help/update.md +0 -5
- data/lib/terraspace/cli/log.rb +0 -112
- data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -0,0 +1,49 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace new plugin mycloud
|
4
|
+
=> Creating new plugin: mycloud
|
5
|
+
create terraspace_plugin_mycloud
|
6
|
+
create terraspace_plugin_mycloud/.gitignore
|
7
|
+
create terraspace_plugin_mycloud/.rspec
|
8
|
+
create terraspace_plugin_mycloud/CHANGELOG.md
|
9
|
+
create terraspace_plugin_mycloud/Gemfile
|
10
|
+
create terraspace_plugin_mycloud/LICENSE.txt
|
11
|
+
create terraspace_plugin_mycloud/README.md
|
12
|
+
create terraspace_plugin_mycloud/Rakefile
|
13
|
+
create terraspace_plugin_mycloud/bin/console
|
14
|
+
create terraspace_plugin_mycloud/bin/setup
|
15
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/module/main.tf
|
16
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/module/outputs.tf
|
17
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/module/variables.tf
|
18
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/project/config/terraform/backend.tf
|
19
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/project/config/terraform/provider.tf
|
20
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/stack/main.tf
|
21
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/stack/outputs.tf
|
22
|
+
create terraspace_plugin_mycloud/lib/templates/hcl/stack/variables.tf
|
23
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/module/main.rb
|
24
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/module/outputs.rb
|
25
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/module/variables.rb
|
26
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/project/config/terraform/backend.rb
|
27
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/project/config/terraform/provider.rb
|
28
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/stack/main.rb
|
29
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/stack/outputs.rb
|
30
|
+
create terraspace_plugin_mycloud/lib/templates/ruby/stack/variables.rb
|
31
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/.rspec
|
32
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/Gemfile
|
33
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/spec/fixtures/stack/main.tf
|
34
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/spec/fixtures/stack/outputs.tf
|
35
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf
|
36
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/spec/main_spec.rb
|
37
|
+
create terraspace_plugin_mycloud/lib/templates/test/rspec/module/test/spec/spec_helper.rb
|
38
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud.rb
|
39
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/autoloader.rb
|
40
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/clients.rb
|
41
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/interfaces/backend.rb
|
42
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/interfaces/config.rb
|
43
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/interfaces/expander.rb
|
44
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/interfaces/layer.rb
|
45
|
+
create terraspace_plugin_mycloud/lib/terraspace_plugin_mycloud/version.rb
|
46
|
+
create terraspace_plugin_mycloud/spec/spec_helper.rb
|
47
|
+
create terraspace_plugin_mycloud/spec/terraspace_provider_mycloud_spec.rb
|
48
|
+
create terraspace_plugin_mycloud/terraspace_plugin_mycloud.gemspec
|
49
|
+
$
|
@@ -0,0 +1,40 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace new project infra --plugin aws --examples
|
4
|
+
=> Creating new project called infra.
|
5
|
+
create infra
|
6
|
+
create infra/.gitignore
|
7
|
+
create infra/Gemfile
|
8
|
+
create infra/README.md
|
9
|
+
create infra/Terrafile
|
10
|
+
create infra/config/app.rb
|
11
|
+
exist infra
|
12
|
+
create infra/config/terraform/backend.tf
|
13
|
+
create infra/config/terraform/provider.tf
|
14
|
+
=> Creating test for new module: example
|
15
|
+
create infra/app/modules/example
|
16
|
+
create infra/app/modules/example/main.tf
|
17
|
+
create infra/app/modules/example/outputs.tf
|
18
|
+
create infra/app/modules/example/variables.tf
|
19
|
+
=> Creating new stack called demo.
|
20
|
+
create infra/app/stacks/demo
|
21
|
+
create infra/app/stacks/demo/main.tf
|
22
|
+
create infra/app/stacks/demo/outputs.tf
|
23
|
+
create infra/app/stacks/demo/variables.tf
|
24
|
+
=> Creating test bootstrap structure
|
25
|
+
exist infra
|
26
|
+
create infra/.rspec
|
27
|
+
create infra/spec/spec_helper.rb
|
28
|
+
=> Installing dependencies with: bundle install
|
29
|
+
Bundle complete! 3 Gemfile dependencies, 88 gems now installed.
|
30
|
+
Use `bundle info [gemname]` to see where a bundled gem is installed.
|
31
|
+
================================================================
|
32
|
+
Congrats! You have successfully created a terraspace project.
|
33
|
+
Check out the created files. Adjust to the examples and then deploy with:
|
34
|
+
|
35
|
+
cd infra
|
36
|
+
terraspace up demo -y # to deploy
|
37
|
+
terraspace down demo -y # to destroy
|
38
|
+
|
39
|
+
More info: https://terraspace.cloud/
|
40
|
+
$
|
@@ -0,0 +1,21 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace new shim
|
4
|
+
A terraspace shim as been generated at /usr/local/bin/terraspace
|
5
|
+
Please make sure that it is found in the $PATH.
|
6
|
+
|
7
|
+
You can double check with:
|
8
|
+
|
9
|
+
which terraspace
|
10
|
+
|
11
|
+
You should see
|
12
|
+
|
13
|
+
$ which terraspace
|
14
|
+
/usr/local/bin/terraspace
|
15
|
+
|
16
|
+
If you do not, please add /usr/local/bin to your PATH.
|
17
|
+
You can usually do so by adding this line to ~/.bash_profile and opening a new terminal to check.
|
18
|
+
|
19
|
+
export PATH=/usr/local/bin:/$PATH
|
20
|
+
|
21
|
+
$
|
@@ -0,0 +1,29 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace plan demo
|
4
|
+
=> terraform plan
|
5
|
+
Refreshing Terraform state in-memory prior to plan...
|
6
|
+
The refreshed state will be used to calculate this plan, but will not be
|
7
|
+
persisted to local or remote state storage.
|
8
|
+
|
9
|
+
random_pet.this: Refreshing state... [id=fond-sheep]
|
10
|
+
module.bucket.aws_s3_bucket.this: Refreshing state... [id=bucket-fond-sheep]
|
11
|
+
|
12
|
+
------------------------------------------------------------------------
|
13
|
+
|
14
|
+
An execution plan has been generated and is shown below.
|
15
|
+
Resource actions are indicated with the following symbols:
|
16
|
+
-/+ destroy and then create replacement
|
17
|
+
...
|
18
|
+
Plan: 2 to add, 0 to change, 2 to destroy.
|
19
|
+
|
20
|
+
Changes to Outputs:
|
21
|
+
~ bucket_name = "bucket-fond-sheep" -> (known after apply)
|
22
|
+
|
23
|
+
------------------------------------------------------------------------
|
24
|
+
|
25
|
+
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
|
26
|
+
can't guarantee that exactly these actions will be performed if
|
27
|
+
"terraform apply" is subsequently run.
|
28
|
+
|
29
|
+
$
|
@@ -0,0 +1,18 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace providers demo
|
4
|
+
=> terraform providers
|
5
|
+
|
6
|
+
Providers required by configuration:
|
7
|
+
.
|
8
|
+
├── provider[registry.terraform.io/hashicorp/random]
|
9
|
+
└── module.bucket
|
10
|
+
└── provider[registry.terraform.io/hashicorp/aws]
|
11
|
+
|
12
|
+
Providers required by state:
|
13
|
+
|
14
|
+
provider[registry.terraform.io/hashicorp/aws]
|
15
|
+
|
16
|
+
provider[registry.terraform.io/hashicorp/random]
|
17
|
+
|
18
|
+
$
|
@@ -0,0 +1,36 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace show demo
|
4
|
+
=> terraform show
|
5
|
+
# random_pet.this:
|
6
|
+
resource "random_pet" "this" {
|
7
|
+
id = "fond-sheep"
|
8
|
+
length = 2
|
9
|
+
separator = "-"
|
10
|
+
}
|
11
|
+
|
12
|
+
# module.bucket.aws_s3_bucket.this:
|
13
|
+
resource "aws_s3_bucket" "this" {
|
14
|
+
acl = "private"
|
15
|
+
arn = "arn:aws:s3:::bucket-fond-sheep"
|
16
|
+
bucket = "bucket-fond-sheep"
|
17
|
+
bucket_domain_name = "bucket-fond-sheep.s3.amazonaws.com"
|
18
|
+
bucket_regional_domain_name = "bucket-fond-sheep.s3.us-west-2.amazonaws.com"
|
19
|
+
force_destroy = false
|
20
|
+
hosted_zone_id = "Z3BJ6K6RIION7M"
|
21
|
+
id = "bucket-fond-sheep"
|
22
|
+
region = "us-west-2"
|
23
|
+
request_payer = "BucketOwner"
|
24
|
+
tags = {}
|
25
|
+
|
26
|
+
versioning {
|
27
|
+
enabled = false
|
28
|
+
mfa_delete = false
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
Outputs:
|
34
|
+
|
35
|
+
bucket_name = "bucket-fond-sheep"
|
36
|
+
$
|
@@ -0,0 +1,11 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace summary
|
4
|
+
Summary of resources based on backend storage statefiles
|
5
|
+
Downloading statefiles to /tmp/terraspace/statefiles/terraform-state-111111111111-us-west-2-dev/us-west-2/dev/
|
6
|
+
stacks/demo/terraform.tfstate
|
7
|
+
random_pet this: sunny-chicken
|
8
|
+
aws_s3_bucket this: bucket-sunny-chicken
|
9
|
+
$
|
10
|
+
|
11
|
+
Also, check out `terraspace all show`.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
Terraspace test just calls the configured test framework, by default, rspec.
|
4
|
+
Here's an example with output cleaned up to reduce noise:
|
5
|
+
|
6
|
+
$ terraspace test
|
7
|
+
=> rspec
|
8
|
+
|
9
|
+
main
|
10
|
+
Building test harness...
|
11
|
+
...
|
12
|
+
Test harness built: /tmp/terraspace/test-harnesses/demo-harness
|
13
|
+
=> terraspace up demo -y
|
14
|
+
Building .terraspace-cache/us-west-2/test/stacks/demo
|
15
|
+
Built in .terraspace-cache/us-west-2/test/stacks/demo
|
16
|
+
Current directory: .terraspace-cache/us-west-2/test/stacks/demo
|
17
|
+
=> terraform init -get >> /tmp/terraspace/log/init/demo.log
|
18
|
+
=> terraform plan -out /tmp/terraspace/plans/demo-20200920160313.plan
|
19
|
+
...
|
20
|
+
=> terraform apply -auto-approve /tmp/terraspace/plans/demo-20200920160313.plan
|
21
|
+
...
|
22
|
+
=> terraform destroy -auto-approve
|
23
|
+
random_pet.this: Refreshing state... [id=hopelessly-outgoing-serval]
|
24
|
+
module.bucket.aws_s3_bucket.this: Refreshing state... [id=bucket-hopelessly-outgoing-serval]
|
25
|
+
module.bucket.aws_s3_bucket.this: Destroying... [id=bucket-hopelessly-outgoing-serval]
|
26
|
+
module.bucket.aws_s3_bucket.this: Destruction complete after 0s
|
27
|
+
random_pet.this: Destroying... [id=hopelessly-outgoing-serval]
|
28
|
+
random_pet.this: Destruction complete after 0s
|
29
|
+
|
30
|
+
Destroy complete! Resources: 2 destroyed.
|
31
|
+
Time took: 5s
|
32
|
+
|
33
|
+
Finished in 22.08 seconds (files took 0.48602 seconds to load)
|
34
|
+
1 example, 0 failures
|
35
|
+
$
|
@@ -0,0 +1,30 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace up demo
|
4
|
+
Building .terraspace-cache/us-west-2/dev/stacks/demo
|
5
|
+
Built in .terraspace-cache/us-west-2/dev/stacks/demo
|
6
|
+
Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
|
7
|
+
=> terraform apply
|
8
|
+
...
|
9
|
+
Plan: 2 to add, 0 to change, 0 to destroy.
|
10
|
+
|
11
|
+
Changes to Outputs:
|
12
|
+
+ bucket_name = (known after apply)
|
13
|
+
|
14
|
+
Do you want to perform these actions?
|
15
|
+
Terraform will perform the actions described above.
|
16
|
+
Only 'yes' will be accepted to approve.
|
17
|
+
Enter a value: yes
|
18
|
+
|
19
|
+
random_pet.this: Creating...
|
20
|
+
random_pet.this: Creation complete after 0s [id=trusty-marmoset]
|
21
|
+
module.bucket.aws_s3_bucket.this: Creating...
|
22
|
+
module.bucket.aws_s3_bucket.this: Creation complete after 2s [id=bucket-trusty-marmoset]
|
23
|
+
|
24
|
+
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
|
25
|
+
|
26
|
+
Outputs:
|
27
|
+
|
28
|
+
bucket_name = bucket-trusty-marmoset
|
29
|
+
Time took: 39s
|
30
|
+
$
|
@@ -0,0 +1,9 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
$ terraspace validate demo
|
4
|
+
Building .terraspace-cache/us-west-2/dev/stacks/demo
|
5
|
+
Built in .terraspace-cache/us-west-2/dev/stacks/demo
|
6
|
+
Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
|
7
|
+
=> terraform validate
|
8
|
+
Success! The configuration is valid.
|
9
|
+
$
|
data/lib/terraspace/cli/info.rb
CHANGED
@@ -3,26 +3,14 @@ class Terraspace::CLI
|
|
3
3
|
extend Memoist
|
4
4
|
|
5
5
|
def run
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def json_output
|
11
|
-
puts JSON.pretty_generate(info)
|
12
|
-
end
|
13
|
-
|
14
|
-
def text_output
|
6
|
+
presenter = CliFormat::Presenter.new(@options)
|
7
|
+
presenter.header = %w[Name Value]
|
15
8
|
info.each do |k,v|
|
16
|
-
|
17
|
-
puts "#{k} #{v}"
|
9
|
+
presenter.rows << [k, v]
|
18
10
|
end
|
11
|
+
presenter.show
|
19
12
|
end
|
20
13
|
|
21
|
-
def rpad
|
22
|
-
info.keys.map(&:size).max
|
23
|
-
end
|
24
|
-
memoize :rpad
|
25
|
-
|
26
14
|
def info
|
27
15
|
@mod.to_info
|
28
16
|
end
|
data/lib/terraspace/cli/init.rb
CHANGED
@@ -67,7 +67,7 @@ class Terraspace::CLI
|
|
67
67
|
mode = ENV['TS_INIT_MODE'] || Terraspace.config.init.mode
|
68
68
|
case mode.to_sym
|
69
69
|
when :auto
|
70
|
-
!
|
70
|
+
!already_init?
|
71
71
|
when :always
|
72
72
|
true
|
73
73
|
when :never
|
@@ -80,16 +80,12 @@ class Terraspace::CLI
|
|
80
80
|
# Traverse symlink dirs also: linux_amd64 is a symlink
|
81
81
|
# plugins/registry.terraform.io/hashicorp/google/3.39.0/linux_amd64/terraform-provider-google_v3.39.0_x5
|
82
82
|
#
|
83
|
-
|
84
|
-
# So init happens again during the second pass.
|
85
|
-
#
|
86
|
-
def already_initialized?
|
83
|
+
def already_init?
|
87
84
|
terraform = "#{@mod.cache_dir}/.terraform"
|
88
85
|
provider = Dir.glob("#{terraform}/**{,/*/**}/*").find do |path|
|
89
86
|
path.include?("terraform-provider-")
|
90
87
|
end
|
91
|
-
|
92
|
-
!!(provider && modules)
|
88
|
+
!!provider
|
93
89
|
end
|
94
90
|
end
|
95
91
|
end
|
data/lib/terraspace/cli/logs.rb
CHANGED
@@ -1,15 +1,112 @@
|
|
1
|
+
require "eventmachine"
|
2
|
+
require "eventmachine-tail"
|
3
|
+
|
1
4
|
class Terraspace::CLI
|
2
|
-
class Logs <
|
3
|
-
|
4
|
-
|
5
|
-
def
|
6
|
-
|
5
|
+
class Logs < Base
|
6
|
+
include Concern
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
super
|
10
|
+
@action, @stack = options[:action], options[:stack]
|
11
|
+
@action ||= '**'
|
12
|
+
@stack ||= '*'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
check_logs!
|
17
|
+
if @options[:follow]
|
18
|
+
follow_logs
|
19
|
+
else
|
20
|
+
all_log_paths.each { |path| show_log(path) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def follow_logs
|
25
|
+
glob_path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
|
26
|
+
Dir.glob(glob_path).each do |path|
|
27
|
+
puts "Following #{pretty(path)}".color(:purple)
|
28
|
+
end
|
29
|
+
EventMachine.run do
|
30
|
+
interval = Integer(ENV['TS_LOG_GLOB_INTERNAL'] || 1)
|
31
|
+
EventMachine::FileGlobWatchTail.new(glob_path, nil, interval) do |filetail, line|
|
32
|
+
puts line # always show timestamp in follow mode
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_log(path)
|
38
|
+
report_log(path)
|
39
|
+
lines = readlines(path)
|
40
|
+
lines = apply_limit(lines)
|
41
|
+
lines.each do |line|
|
42
|
+
puts format(line)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def report_log(path)
|
47
|
+
pretty_path = pretty(path)
|
48
|
+
if File.exist?(path)
|
49
|
+
puts "Showing: #{pretty_path}".color(:purple)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def format(line)
|
54
|
+
if timestamps
|
55
|
+
line
|
56
|
+
else
|
57
|
+
line.sub(/.*\]: /,'')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def all_log_paths
|
62
|
+
Dir.glob("#{Terraspace.log_root}/#{@action}/#{@stack}.log")
|
7
63
|
end
|
8
64
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
65
|
+
def check_logs!
|
66
|
+
return unless all_log_paths.empty?
|
67
|
+
puts "WARN: No logs found".color(:yellow)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Only need to check if both action and stack are provided. Otherwise the Dir.globs are used to discover the files
|
71
|
+
def check_log!
|
72
|
+
return unless single_log?
|
73
|
+
path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
|
74
|
+
return if File.exist?(path)
|
75
|
+
puts "ERROR: Log file was not found: #{pretty(path)}".color(:red)
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
|
79
|
+
def single_log?
|
80
|
+
@action != '**' && @stack != '*'
|
81
|
+
end
|
82
|
+
|
83
|
+
def apply_limit(lines)
|
84
|
+
return lines if all
|
85
|
+
left = limit * -1
|
86
|
+
lines[left..-1] || []
|
87
|
+
end
|
88
|
+
|
89
|
+
def all
|
90
|
+
if single_log?
|
91
|
+
@options[:all].nil? ? true : @options[:all]
|
92
|
+
else # multiple
|
93
|
+
@options[:all].nil? ? false : @options[:all]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def limit
|
98
|
+
@options[:limit].nil? ? 10 : @options[:limit]
|
99
|
+
end
|
100
|
+
|
101
|
+
def timestamps
|
102
|
+
if single_log?
|
103
|
+
@options[:timestamps].nil? ? false : @options[:timestamps]
|
104
|
+
else
|
105
|
+
@options[:timestamps].nil? ? true : @options[:timestamps]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
def pretty(path)
|
109
|
+
Terraspace::Util.pretty_path(path)
|
13
110
|
end
|
14
111
|
end
|
15
112
|
end
|