terraspace 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/README.md +25 -0
- data/.cody/aws/bin/build.sh +13 -0
- data/.cody/aws/buildspec.yml +10 -0
- data/.cody/aws/project.rb +2 -0
- data/.cody/aws/role.rb +6 -0
- data/.cody/azurerm/bin/az/configure.sh +23 -0
- data/.cody/azurerm/bin/az/install.sh +17 -0
- data/.cody/azurerm/bin/build.sh +20 -0
- data/.cody/azurerm/bin/install.sh +6 -0
- data/.cody/azurerm/buildspec.yml +11 -0
- data/.cody/azurerm/project.rb +2 -0
- data/.cody/azurerm/role.rb +5 -0
- data/.cody/google/bin/build.sh +17 -0
- data/.cody/google/bin/gcloud/configure.sh +15 -0
- data/.cody/google/bin/gcloud/install.sh +18 -0
- data/.cody/google/bin/install.sh +6 -0
- data/.cody/google/buildspec.yml +11 -0
- data/.cody/google/project.rb +2 -0
- data/.cody/google/role.rb +5 -0
- data/.cody/shared/script/install.sh +6 -0
- data/.cody/shared/script/install/terraform.sh +11 -0
- data/.cody/shared/script/install/terraspace.sh +72 -0
- data/.cody/unit/bin/build.sh +4 -0
- data/.cody/unit/buildspec.yml +9 -0
- data/.cody/unit/project.rb +2 -0
- data/.github/ISSUE_TEMPLATE.md +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
- data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
- data/.github/ISSUE_TEMPLATE/question.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
- data/.gitignore +18 -9
- data/.pipedream/README.md +25 -0
- data/.pipedream/pipeline.rb +17 -0
- data/.pipedream/schedule.rb +3 -0
- data/.rspec +2 -2
- data/CHANGELOG.md +7 -0
- data/CONDUCT.md +1 -0
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +1 -4
- data/Guardfile +19 -0
- data/LICENSE.txt +201 -21
- data/README.md +60 -27
- data/Rakefile +10 -2
- data/exe/terraspace +14 -0
- data/lib/templates/base/project/.gitignore +34 -0
- data/lib/templates/base/project/Gemfile.tt +9 -0
- data/lib/templates/base/project/Terrafile +14 -0
- data/lib/templates/base/project/config/app.rb +4 -0
- data/lib/templates/hcl/module/main.tf +1 -0
- data/lib/templates/hcl/module/outputs.tf +1 -0
- data/lib/templates/hcl/module/variables.tf +1 -0
- data/lib/templates/hcl/project/config/terraform/backend.tf.tt +18 -0
- data/lib/templates/hcl/project/config/terraform/provider.tf +16 -0
- data/lib/templates/hcl/stack/main.tf +1 -0
- data/lib/templates/hcl/stack/outputs.tf +1 -0
- data/lib/templates/hcl/stack/variables.tf +1 -0
- data/lib/templates/plugin/.gitignore +12 -0
- data/lib/templates/plugin/.rspec +3 -0
- data/lib/templates/plugin/CHANGELOG.md +7 -0
- data/lib/templates/plugin/Gemfile +7 -0
- data/lib/templates/plugin/LICENSE.txt +201 -0
- data/lib/templates/plugin/README.md.tt +34 -0
- data/lib/templates/plugin/Rakefile +6 -0
- data/{bin/console → lib/templates/plugin/bin/console.tt} +1 -1
- data/{bin → lib/templates/plugin/bin}/setup +0 -0
- data/lib/templates/plugin/lib/templates/hcl/module/main.tf +1 -0
- data/lib/templates/plugin/lib/templates/hcl/module/outputs.tf +1 -0
- data/lib/templates/plugin/lib/templates/hcl/module/variables.tf +1 -0
- data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/backend.tf.tt +6 -0
- data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/provider.tf +3 -0
- data/lib/templates/plugin/lib/templates/hcl/stack/main.tf +1 -0
- data/lib/templates/plugin/lib/templates/hcl/stack/outputs.tf +1 -0
- data/lib/templates/plugin/lib/templates/hcl/stack/variables.tf +1 -0
- data/lib/templates/plugin/lib/templates/ruby/module/main.rb +1 -0
- data/lib/templates/plugin/lib/templates/ruby/module/outputs.rb +1 -0
- data/lib/templates/plugin/lib/templates/ruby/module/variables.rb +1 -0
- data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/backend.rb.tt +4 -0
- data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/provider.rb +3 -0
- data/lib/templates/plugin/lib/templates/ruby/stack/main.rb +1 -0
- data/lib/templates/plugin/lib/templates/ruby/stack/outputs.rb +1 -0
- data/lib/templates/plugin/lib/templates/ruby/stack/variables.rb +1 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/.rspec +3 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/Gemfile +9 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/main.tf +1 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/outputs.tf +1 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf +1 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/main_spec.rb +29 -0
- data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/spec_helper.rb +13 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%.rb.tt +36 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/autoloader.rb.tt +23 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/clients.rb.tt +14 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/backend.rb.tt +12 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/config.rb.tt +18 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/expander.rb.tt +15 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/layer.rb.tt +20 -0
- data/lib/templates/plugin/lib/terraspace_plugin_%name%/version.rb.tt +3 -0
- data/lib/templates/plugin/spec/spec_helper.rb.tt +14 -0
- data/lib/templates/plugin/spec/terraspace_provider_%name%_spec.rb.tt +5 -0
- data/lib/templates/plugin/terraspace_plugin_%name%.gemspec.tt +27 -0
- data/lib/templates/ruby/module/main.rb +1 -0
- data/lib/templates/ruby/module/outputs.rb +1 -0
- data/lib/templates/ruby/module/variables.rb +1 -0
- data/lib/templates/ruby/project/config/terraform/backend.rb.tt +9 -0
- data/lib/templates/ruby/project/config/terraform/provider.rb +7 -0
- data/lib/templates/ruby/stack/main.rb +1 -0
- data/lib/templates/ruby/stack/outputs.rb +1 -0
- data/lib/templates/ruby/stack/variables.rb +1 -0
- data/lib/terraspace.rb +22 -1
- data/lib/terraspace/app.rb +30 -0
- data/lib/terraspace/app/hooks.rb +18 -0
- data/lib/terraspace/autoloader.rb +25 -0
- data/lib/terraspace/booter.rb +19 -0
- data/lib/terraspace/builder.rb +87 -0
- data/lib/terraspace/bundle.rb +54 -0
- data/lib/terraspace/cli.rb +185 -0
- data/lib/terraspace/cli/base.rb +11 -0
- data/lib/terraspace/cli/build.rb +7 -0
- data/lib/terraspace/cli/bundle.rb +28 -0
- data/lib/terraspace/cli/check_setup.rb +73 -0
- data/lib/terraspace/cli/clean.rb +12 -0
- data/lib/terraspace/cli/commander.rb +14 -0
- data/lib/terraspace/cli/help.rb +11 -0
- data/lib/terraspace/cli/help/bundle.md +14 -0
- data/lib/terraspace/cli/help/completion.md +20 -0
- data/lib/terraspace/cli/help/completion_script.md +3 -0
- data/lib/terraspace/cli/help/update.md +5 -0
- data/lib/terraspace/cli/info.rb +30 -0
- data/lib/terraspace/cli/new.rb +32 -0
- data/lib/terraspace/cli/new/helper.rb +15 -0
- data/lib/terraspace/cli/new/helper/plugin_gem.rb +12 -0
- data/lib/terraspace/cli/new/module.rb +26 -0
- data/lib/terraspace/cli/new/plugin.rb +20 -0
- data/lib/terraspace/cli/new/plugin/helper.rb +15 -0
- data/lib/terraspace/cli/new/project.rb +110 -0
- data/lib/terraspace/cli/new/sequence.rb +59 -0
- data/lib/terraspace/cli/new/source/core.rb +63 -0
- data/lib/terraspace/cli/new/source/plugin.rb +20 -0
- data/lib/terraspace/cli/new/source/test.rb +26 -0
- data/lib/terraspace/cli/new/stack.rb +26 -0
- data/lib/terraspace/cli/new/test/base.rb +17 -0
- data/lib/terraspace/cli/new/test/bootstrap.rb +18 -0
- data/lib/terraspace/cli/new/test/module.rb +15 -0
- data/lib/terraspace/cli/new/test/project.rb +15 -0
- data/lib/terraspace/cli/seed.rb +9 -0
- data/lib/terraspace/cli/summary.rb +61 -0
- data/lib/terraspace/cli/test.rb +35 -0
- data/lib/terraspace/command.rb +100 -0
- data/lib/terraspace/compiler/backend.rb +66 -0
- data/lib/terraspace/compiler/basename.rb +10 -0
- data/lib/terraspace/compiler/builder.rb +74 -0
- data/lib/terraspace/compiler/cleaner.rb +46 -0
- data/lib/terraspace/compiler/cleaner/backend_change.rb +45 -0
- data/lib/terraspace/compiler/dsl/base.rb +12 -0
- data/lib/terraspace/compiler/dsl/meta/local.rb +7 -0
- data/lib/terraspace/compiler/dsl/meta/var.rb +7 -0
- data/lib/terraspace/compiler/dsl/mod.rb +19 -0
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +28 -0
- data/lib/terraspace/compiler/dsl/syntax/mod.rb +6 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/backend.rb +18 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/data.rb +9 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/locals.rb +7 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/module.rb +10 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/output.rb +8 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/provider.rb +8 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/resource.rb +24 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/terraform.rb +8 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/variable.rb +12 -0
- data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +5 -0
- data/lib/terraspace/compiler/dsl/syntax/tfvar/common.rb +7 -0
- data/lib/terraspace/compiler/dsl/tfvars.rb +29 -0
- data/lib/terraspace/compiler/erb/context.rb +11 -0
- data/lib/terraspace/compiler/erb/render.rb +12 -0
- data/lib/terraspace/compiler/expander.rb +19 -0
- data/lib/terraspace/compiler/strategy/abstract_base.rb +7 -0
- data/lib/terraspace/compiler/strategy/mod.rb +15 -0
- data/lib/terraspace/compiler/strategy/mod/base.rb +4 -0
- data/lib/terraspace/compiler/strategy/mod/pass.rb +7 -0
- data/lib/terraspace/compiler/strategy/mod/rb.rb +7 -0
- data/lib/terraspace/compiler/strategy/mod/tf.rb +7 -0
- data/lib/terraspace/compiler/strategy/tfvar.rb +42 -0
- data/lib/terraspace/compiler/strategy/tfvar/base.rb +4 -0
- data/lib/terraspace/compiler/strategy/tfvar/layer.rb +110 -0
- data/lib/terraspace/compiler/strategy/tfvar/rb.rb +7 -0
- data/lib/terraspace/compiler/strategy/tfvar/tfvars.rb +7 -0
- data/lib/terraspace/compiler/writer.rb +36 -0
- data/lib/terraspace/completer.rb +159 -0
- data/lib/terraspace/completer/script.rb +6 -0
- data/lib/terraspace/completer/script.sh +10 -0
- data/lib/terraspace/core.rb +46 -0
- data/lib/terraspace/ext.rb +2 -0
- data/lib/terraspace/ext/bundler.rb +7 -0
- data/lib/terraspace/ext/core/module.rb +19 -0
- data/lib/terraspace/logger.rb +26 -0
- data/lib/terraspace/mod.rb +100 -0
- data/lib/terraspace/mod/remote.rb +18 -0
- data/lib/terraspace/plugin.rb +73 -0
- data/lib/terraspace/plugin/backend/interface.rb +8 -0
- data/lib/terraspace/plugin/config/interface.rb +27 -0
- data/lib/terraspace/plugin/decorator/interface.rb +8 -0
- data/lib/terraspace/plugin/expander/generic.rb +5 -0
- data/lib/terraspace/plugin/expander/interface.rb +52 -0
- data/lib/terraspace/plugin/finder.rb +45 -0
- data/lib/terraspace/plugin/meta.rb +29 -0
- data/lib/terraspace/plugin/summary/interface.rb +129 -0
- data/lib/terraspace/seeder.rb +66 -0
- data/lib/terraspace/seeder/actions.rb +24 -0
- data/lib/terraspace/seeder/content.rb +84 -0
- data/lib/terraspace/seeder/where.rb +30 -0
- data/lib/terraspace/terraform/args/custom.rb +47 -0
- data/lib/terraspace/terraform/args/default.rb +96 -0
- data/lib/terraspace/terraform/args/dsl.rb +30 -0
- data/lib/terraspace/terraform/args/shorthands.rb +47 -0
- data/lib/terraspace/terraform/hooks/builder.rb +40 -0
- data/lib/terraspace/terraform/hooks/dsl.rb +19 -0
- data/lib/terraspace/terraform/runner.rb +77 -0
- data/lib/terraspace/tester.rb +29 -0
- data/lib/terraspace/tester/finder.rb +25 -0
- data/lib/terraspace/tester/meta.rb +25 -0
- data/lib/terraspace/util.rb +13 -0
- data/lib/terraspace/util/logging.rb +7 -0
- data/lib/terraspace/util/sh.rb +19 -0
- data/lib/terraspace/util/sure.rb +22 -0
- data/lib/terraspace/version.rb +1 -1
- data/spec/cli_spec.rb +13 -0
- data/spec/fixtures/cache_build_dir/variables.tf +9 -0
- data/spec/fixtures/initialized/modules.json +29 -0
- data/spec/fixtures/orphans/config/backend.rb +8 -0
- data/spec/fixtures/orphans/config/provider.rb +3 -0
- data/spec/fixtures/orphans/config/providers_different.rb +6 -0
- data/spec/fixtures/orphans/config/providers_same.rb +16 -0
- data/spec/fixtures/orphans/data/aws_ami.rb +8 -0
- data/spec/fixtures/orphans/data/aws_instance.rb +16 -0
- data/spec/fixtures/orphans/locals/forum.rb +4 -0
- data/spec/fixtures/orphans/locals/qux.rb +7 -0
- data/spec/fixtures/orphans/module/core/main.rb +5 -0
- data/spec/fixtures/orphans/resource/security_group/hash_example.rb +18 -0
- data/spec/fixtures/orphans/resource/vpc/count_example.rb +7 -0
- data/spec/fixtures/orphans/terraform/terraform.rb +3 -0
- data/spec/fixtures/projects/hcl/aws/app/modules/instance/main.tf +30 -0
- data/spec/fixtures/projects/hcl/aws/app/modules/instance/variables.tf +7 -0
- data/spec/fixtures/projects/hcl/aws/app/modules/vpc/file.txt +1 -0
- data/spec/fixtures/projects/hcl/aws/app/modules/vpc/main.tf +7 -0
- data/spec/fixtures/projects/hcl/aws/app/modules/vpc/variables.tf +11 -0
- data/spec/fixtures/projects/hcl/aws/app/stacks/core/main.tf +3 -0
- data/spec/fixtures/projects/hcl/aws/app/stacks/monolith/main.tf +3 -0
- data/spec/fixtures/projects/hcl/aws/config/backend.tf +9 -0
- data/spec/fixtures/projects/hcl/aws/config/provider.tf +3 -0
- data/spec/fixtures/projects/hcl/google/app/modules/vpc/main.tf +4 -0
- data/spec/fixtures/projects/hcl/google/app/modules/vpc/outputs.tf +4 -0
- data/spec/fixtures/projects/hcl/google/app/modules/vpc/variables.tf +5 -0
- data/spec/fixtures/projects/hcl/google/config/backend.tf +6 -0
- data/spec/fixtures/projects/hcl/google/config/provider.tf +0 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/backend.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/main.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/outputs.rb +4 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/variables.rb +9 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/instance/main.rb +28 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/instance/outputs.rb +3 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/instance/variables.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/security_group/main.rb +16 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/security_group/variables.rb +5 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/main.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/variables.rb +5 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/main.rb +14 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/variables.rb +3 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/vpc/main.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/vpc/outputs.rb +4 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/vpc/variables.rb +9 -0
- data/spec/fixtures/projects/ruby/aws/app/modules/wordpress/main.rb +0 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/core/a.tfvars +0 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/core/b.tfvars +1 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/core/main.rb +6 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/core/outputs.rb +4 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/core/variables.rb +2 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/gke/main.rb +0 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/monolith/main.rb +3 -0
- data/spec/fixtures/projects/ruby/aws/app/stacks/nested/main.rb +5 -0
- data/spec/fixtures/projects/ruby/aws/config/backend.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/config/cli/args.rb +11 -0
- data/spec/fixtures/projects/ruby/aws/config/cli/hooks.rb +8 -0
- data/spec/fixtures/projects/ruby/aws/config/provider.rb +3 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/base.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/dev.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/prod.rb +0 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/base.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/dev.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/base.tfvars +2 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/dev.tfvars +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/prod.tfvars +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/base.rb +4 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/dev.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/prod.rb +1 -0
- data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/main.rb +7 -0
- data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/outputs.rb +4 -0
- data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/variables.rb +9 -0
- data/spec/fixtures/projects/ruby/google/app/modules/firewall/main.rb +17 -0
- data/spec/fixtures/projects/ruby/google/app/modules/network/main.rb +4 -0
- data/spec/fixtures/projects/ruby/google/app/modules/vm-simple/main.rb +28 -0
- data/spec/fixtures/projects/ruby/google/app/modules/vm/main.rb +32 -0
- data/spec/fixtures/projects/ruby/google/app/modules/vm/outputs.rb +3 -0
- data/spec/fixtures/projects/ruby/google/app/modules/vm/variables.rb +19 -0
- data/spec/fixtures/projects/ruby/google/app/stacks/core/main.rb +5 -0
- data/spec/fixtures/projects/ruby/google/config/backend.rb +4 -0
- data/spec/fixtures/projects/ruby/google/config/provider.rb +14 -0
- data/spec/fixtures/terraform/args/multiple.rb +4 -0
- data/spec/fixtures/terraform/args/single.rb +10 -0
- data/spec/fixtures/terraform/hooks/multiple.rb +3 -0
- data/spec/fixtures/terraform/hooks/single.rb +7 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/terraspace/compiler/dsl/backend_spec.rb +33 -0
- data/spec/terraspace/compiler/dsl/data_spec.rb +30 -0
- data/spec/terraspace/compiler/dsl/locals_spec.rb +44 -0
- data/spec/terraspace/compiler/dsl/meta/local_spec.rb +10 -0
- data/spec/terraspace/compiler/dsl/meta/var_spec.rb +10 -0
- data/spec/terraspace/compiler/dsl/module_spec.rb +14 -0
- data/spec/terraspace/compiler/dsl/monolith_spec.rb +23 -0
- data/spec/terraspace/compiler/dsl/output_spec.rb +22 -0
- data/spec/terraspace/compiler/dsl/provider_spec.rb +72 -0
- data/spec/terraspace/compiler/dsl/resource/security_group_spec.rb +43 -0
- data/spec/terraspace/compiler/dsl/resource_spec.rb +64 -0
- data/spec/terraspace/compiler/dsl/terraform_spec.rb +21 -0
- data/spec/terraspace/compiler/dsl/variable_spec.rb +28 -0
- data/spec/terraspace/provider/expander/generic_spec.rb +30 -0
- data/spec/terraspace/seeder/content_spec.rb +49 -0
- data/spec/terraspace/seeder_spec.rb +20 -0
- data/spec/terraspace/terraform/args/custom_spec.rb +48 -0
- data/spec/terraspace/terraform/hooks/builder_spec.rb +35 -0
- data/terraspace.gemspec +31 -15
- metadata +687 -14
- data/.travis.yml +0 -6
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
class Terraspace::CLI::New
|
4
|
+
class Sequence < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
include Helper
|
7
|
+
|
8
|
+
def self.base_options
|
9
|
+
[
|
10
|
+
[:examples, type: :boolean, default: false, desc: "Also generate examples"],
|
11
|
+
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
12
|
+
[:lang, default: "hcl", desc: "Language to use: HCL/ERB or Ruby DSL"],
|
13
|
+
[:plugin, aliases: %w[p], default: "aws", desc: "Cloud Plugin. Supports: aws, google"],
|
14
|
+
[:test, default: !!ENV['TS_NEW_TEST'], type: :boolean, desc: "Whether or not to generate tests"],
|
15
|
+
[:plugin_gem, desc: "Use if provider gem name doesnt follow terraspace_plugin_XXX naming convention. Must specify both --plugin and --plugin-name option"],
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.component_options
|
20
|
+
[
|
21
|
+
[:project_name, desc: "Only used internally", hide: true],
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
base_options.each { |args| class_option(*args) }
|
26
|
+
|
27
|
+
argument :name
|
28
|
+
|
29
|
+
private
|
30
|
+
def component_args(component_name, project_name)
|
31
|
+
args = [
|
32
|
+
component_name,
|
33
|
+
"--project-name", project_name,
|
34
|
+
]
|
35
|
+
|
36
|
+
args += ["--lang", @options[:lang]] if @options[:lang]
|
37
|
+
args += ["--plugin", @options[:plugin]] if @options[:plugin]
|
38
|
+
args += ["--plugin-gem", @options[:plugin_gem]] if @options[:plugin_gem]
|
39
|
+
args += @options[:test] ? ["--test"] : ["--no-test"] # since test may be true by default
|
40
|
+
args += ["--examples"] if @options[:examples]
|
41
|
+
args += ["--force"] if @options[:force]
|
42
|
+
args
|
43
|
+
end
|
44
|
+
|
45
|
+
# friendly method
|
46
|
+
def plugin_template_source(template, type)
|
47
|
+
source = Source::Plugin.new(self, @options)
|
48
|
+
source.set_source_paths(template, type)
|
49
|
+
end
|
50
|
+
|
51
|
+
# A generator script hook to allow for further customizations
|
52
|
+
# The dest folder like app/modules/demo is provided as a first argument to the command.
|
53
|
+
def run_script(script, dest)
|
54
|
+
command = "#{script} #{dest}"
|
55
|
+
puts "Running: #{command}" unless ENV['TS_GENERATOR_MUTE']
|
56
|
+
system(command)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Terraspace::CLI::New::Source
|
2
|
+
class Core
|
3
|
+
include Terraspace::CLI::New::Helper::PluginGem
|
4
|
+
include Terraspace::Util
|
5
|
+
|
6
|
+
def initialize(sequence, options)
|
7
|
+
@sequence, @options = sequence, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_core_source(template, type=nil)
|
11
|
+
template_name = template_name(template, type)
|
12
|
+
template_path = File.expand_path("../../../../templates/#{template_name}", __dir__)
|
13
|
+
override_source_paths(template_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_name(template, type=nil)
|
17
|
+
[template, type].compact.join('/')
|
18
|
+
end
|
19
|
+
|
20
|
+
def require_gem(name)
|
21
|
+
begin
|
22
|
+
require name # require plugin for the templates, this registers the plugin
|
23
|
+
rescue LoadError => e
|
24
|
+
puts "#{e.class}: #{e.message}".color(:red)
|
25
|
+
logger.error "ERROR: Unable to require plugin #{name}.".color(:red)
|
26
|
+
puts "Are you sure you the plugin exists and you specified the right plugin option."
|
27
|
+
puts "You specified --plugin #{@options[:plugin]}"
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_plugin_gem_source(template, type)
|
33
|
+
require_gem(plugin_gem_name)
|
34
|
+
plugin = Terraspace::Plugin.find_with(plugin: @options[:plugin])
|
35
|
+
unless plugin
|
36
|
+
puts "ERROR: Unable to a find plugin for #{@options[:plugin]}. Are you sure the gem for the plugin is correct?".color(:red)
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
template_name = template_name(template, type)
|
40
|
+
template_path = File.expand_path("#{plugin.root}/lib/templates/#{template_name}")
|
41
|
+
override_source_paths(template_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def template_name(template, type)
|
45
|
+
if template == "test"
|
46
|
+
"#{template}/#{Terraspace.config.test_framework}/#{type}"
|
47
|
+
else
|
48
|
+
"#{template}/#{type}" # IE: hcl/module
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def override_source_paths(*paths)
|
53
|
+
# https://github.com/erikhuda/thor/blob/34df888d721ecaa8cf0cea97d51dc6c388002742/lib/thor/actions.rb#L128
|
54
|
+
@sequence.instance_variable_set(:@source_paths, nil) # unset instance variable cache
|
55
|
+
# Using string with instance_eval because block doesnt have access to path at runtime.
|
56
|
+
@sequence.class.instance_eval %{
|
57
|
+
def self.source_paths
|
58
|
+
#{paths.flatten.inspect}
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Terraspace::CLI::New::Source
|
2
|
+
class Plugin < Core
|
3
|
+
# different interface than Source::Test
|
4
|
+
#
|
5
|
+
# template: base, hcl, ruby
|
6
|
+
# type: module, project, stack
|
7
|
+
#
|
8
|
+
def set_source_paths(template, type)
|
9
|
+
# project always uses the examples from the provider gem for configs
|
10
|
+
# base always uses terraspace core templates
|
11
|
+
# examples option always use examples from provider gems
|
12
|
+
if (type == "project" || @options[:examples]) && template != "base"
|
13
|
+
set_plugin_gem_source(template, type) # provider gems has examples
|
14
|
+
else
|
15
|
+
set_core_source(template, type) # terraspace core has empty starter files
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Terraspace::CLI::New::Source
|
2
|
+
class Test < Core
|
3
|
+
# different interface than Source::Plugin
|
4
|
+
#
|
5
|
+
# template: base, hcl, ruby
|
6
|
+
# type: module, project, stack
|
7
|
+
#
|
8
|
+
def set_source_paths(template, type)
|
9
|
+
if @options[:examples]
|
10
|
+
set_plugin_gem_source("test", type)
|
11
|
+
else
|
12
|
+
set_test_framework_gem_source(type) # tester gem like rspec-terraspace has empty starter templates
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_test_framework_gem_source(type)
|
17
|
+
test_gem_name = "rspec/terraspace"
|
18
|
+
|
19
|
+
require_gem(test_gem_name)
|
20
|
+
tester = Terraspace::Tester.find_with(framework: Terraspace.config.test_framework)
|
21
|
+
|
22
|
+
template_path = File.expand_path("#{tester.root}/lib/templates/#{type}")
|
23
|
+
override_source_paths(template_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Terraspace::CLI::New
|
2
|
+
class Stack < Sequence
|
3
|
+
component_options.each { |args| class_option(*args) }
|
4
|
+
|
5
|
+
argument :name
|
6
|
+
|
7
|
+
def create_stack
|
8
|
+
plugin_template_source(@options[:lang], "stack") # IE: plugin_template_source("hcl", "stack")
|
9
|
+
|
10
|
+
puts "=> Creating new stack called #{name}."
|
11
|
+
dest = "app/stacks/#{name}"
|
12
|
+
dest = "#{@options[:project_name]}/#{dest}" if @options[:project_name]
|
13
|
+
directory ".", dest
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_test
|
17
|
+
Test::Project.start(component_args(name, @options[:project_name]))
|
18
|
+
end
|
19
|
+
|
20
|
+
def run_generator_hook_script
|
21
|
+
script = ENV['TS_GENERATOR_STACK']
|
22
|
+
return unless script
|
23
|
+
run_script(script, "app/stacks/#{name}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Terraspace::CLI::New::Test
|
2
|
+
class Base < Thor::Group
|
3
|
+
include Thor::Actions
|
4
|
+
include Terraspace::CLI::New::Helper
|
5
|
+
|
6
|
+
# Reuse options form Sequence. Tried separting them out and it's not worth it.
|
7
|
+
# It introduced too much duplication.
|
8
|
+
Terraspace::CLI::New::Sequence.base_options.each { |args| class_option(*args) }
|
9
|
+
Terraspace::CLI::New::Sequence.component_options.each { |args| class_option(*args) }
|
10
|
+
|
11
|
+
private
|
12
|
+
def test_template_source(template, type)
|
13
|
+
source = Terraspace::CLI::New::Source::Test.new(self, @options)
|
14
|
+
source.set_source_paths(template, type)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Terraspace::CLI::New::Test
|
2
|
+
class Bootstrap < Base
|
3
|
+
def self.options
|
4
|
+
[
|
5
|
+
[:dir, default: ".", desc: "directory to write to"],
|
6
|
+
]
|
7
|
+
end
|
8
|
+
|
9
|
+
options.each { |args| class_option(*args) }
|
10
|
+
|
11
|
+
def create
|
12
|
+
return if @options[:test] == false
|
13
|
+
puts "=> Creating test bootstrap structure"
|
14
|
+
test_template_source(@options[:lang], "bootstrap")
|
15
|
+
directory ".", options[:dir]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Terraspace::CLI::New::Test
|
2
|
+
class Module < Base
|
3
|
+
argument :name
|
4
|
+
|
5
|
+
def create
|
6
|
+
return if @options[:test] == false
|
7
|
+
test_template_source(@options[:lang], "module")
|
8
|
+
|
9
|
+
puts "=> Creating module test: #{name}"
|
10
|
+
dest = "app/modules/#{name}"
|
11
|
+
dest = "#{@options[:project_name]}/#{dest}" if @options[:project_name]
|
12
|
+
directory ".", dest
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Terraspace::CLI::New::Test
|
2
|
+
class Project < Base
|
3
|
+
argument :name
|
4
|
+
|
5
|
+
def create
|
6
|
+
return if @options[:test] == false
|
7
|
+
test_template_source(@options[:lang], "project")
|
8
|
+
|
9
|
+
puts "=> Creating project test: #{name}"
|
10
|
+
dest = "."
|
11
|
+
dest = "#{@options[:project_name]}/#{dest}" if @options[:project_name]
|
12
|
+
directory ".", dest
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "hcl_parser"
|
2
|
+
require "json"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
class Terraspace::CLI
|
6
|
+
class Summary
|
7
|
+
include Terraspace::Util::Logging
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
build
|
15
|
+
puts "Summary of resources based on backend storage statefiles"
|
16
|
+
backend_expr = '.terraspace-cache/**/backend.*'
|
17
|
+
backends = Dir.glob(backend_expr)
|
18
|
+
backends.each do |backend|
|
19
|
+
process(backend)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Grab the last module and build that.
|
24
|
+
# Assume the backend key has the same prefix
|
25
|
+
def build
|
26
|
+
return if ENV['TS_SUMMARY_BUILD'] == '0'
|
27
|
+
|
28
|
+
mod = @options[:mod]
|
29
|
+
unless mod
|
30
|
+
mod_path = Dir.glob("{app,vendor}/{modules,stacks}/*").last
|
31
|
+
mod = File.basename(mod_path)
|
32
|
+
end
|
33
|
+
Build.new(@options.merge(mod: mod)).run # generate and init
|
34
|
+
end
|
35
|
+
|
36
|
+
def process(path)
|
37
|
+
ext = File.extname(path)
|
38
|
+
code = IO.read(path)
|
39
|
+
data = ext == ".tf" ? HclParser.load(code) : JSON.load(code)
|
40
|
+
|
41
|
+
backend = data['terraform']['backend']
|
42
|
+
name = backend.keys.first # backend name. IE: s3, gcs, azurerm
|
43
|
+
|
44
|
+
info = backend.values.first # structure within the s3 or gcs key
|
45
|
+
klass = summary_class(name)
|
46
|
+
summary = klass.new(info)
|
47
|
+
summary.call
|
48
|
+
end
|
49
|
+
|
50
|
+
def summary_class(name)
|
51
|
+
return unless name
|
52
|
+
# IE: TerraspacePluginAws::Interfaces::Summary
|
53
|
+
klass_name = Terraspace::Plugin.klass("Summary", backend: name)
|
54
|
+
klass_name.constantize if klass_name
|
55
|
+
rescue NameError => e
|
56
|
+
logger.error "#{e.class}: #{e.message}"
|
57
|
+
logger.error "ERROR: No summary class implementation provided by plugins installed for this backend: #{name}".color(:red)
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Terraspace::CLI
|
2
|
+
class Test
|
3
|
+
def initialize(options={})
|
4
|
+
@options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
config = Terraspace.config
|
9
|
+
test_command = config.test_framework_command || config.test_framework
|
10
|
+
execute(test_command)
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(command)
|
14
|
+
command = adjust_command(command)
|
15
|
+
puts "=> #{command}"
|
16
|
+
Kernel.exec(command)
|
17
|
+
end
|
18
|
+
|
19
|
+
def adjust_command(command)
|
20
|
+
if cd_into_test?
|
21
|
+
command = "bundle exec #{command}" unless command.include?("bundle exec")
|
22
|
+
command = "cd test && #{command}"
|
23
|
+
else
|
24
|
+
command
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Automatically cd into the test folder in case running within the root of a module.
|
29
|
+
# Detect/guess that we're in a module folder vs the terraspace project
|
30
|
+
def cd_into_test?
|
31
|
+
!File.exist?("app") && File.exist?("test") &&
|
32
|
+
(File.exist?("main.tf") || File.exist?("main.rb"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
# Override thor's long_desc identation behavior
|
4
|
+
# https://github.com/erikhuda/thor/issues/398
|
5
|
+
class Thor
|
6
|
+
module Shell
|
7
|
+
class Basic
|
8
|
+
def print_wrapped(message, options = {})
|
9
|
+
message = "\n#{message}" unless message[0] == "\n"
|
10
|
+
stdout.puts message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Gets rid of the c_l_i extra commands in the help menu. Seems like thor_classes_in is only used
|
17
|
+
# for this purpose. More details: https://gist.github.com/tongueroo/ee92ec28a4d3eed301d88e8ccdd2fe10
|
18
|
+
module ThorPrepend
|
19
|
+
module Util
|
20
|
+
def thor_classes_in(klass)
|
21
|
+
klass.name.include?("CLI") ? [] : super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Thor::Util.singleton_class.prepend(ThorPrepend::Util)
|
26
|
+
|
27
|
+
module Terraspace
|
28
|
+
class Command < Thor
|
29
|
+
class << self
|
30
|
+
def dispatch(m, args, options, config)
|
31
|
+
# Allow calling for help via:
|
32
|
+
# terraspace command help
|
33
|
+
# terraspace command -h
|
34
|
+
# terraspace command --help
|
35
|
+
# terraspace command -D
|
36
|
+
#
|
37
|
+
# as well thor's normal way:
|
38
|
+
#
|
39
|
+
# terraspace help command
|
40
|
+
help_flags = Thor::HELP_MAPPINGS + ["help"]
|
41
|
+
if args.length > 1 && !(args & help_flags).empty?
|
42
|
+
args -= help_flags
|
43
|
+
args.insert(-2, "help")
|
44
|
+
end
|
45
|
+
|
46
|
+
# terraspace version
|
47
|
+
# terraspace --version
|
48
|
+
# terraspace -v
|
49
|
+
version_flags = ["--version", "-v"]
|
50
|
+
if args.length == 1 && !(args & version_flags).empty?
|
51
|
+
args = ["version"]
|
52
|
+
end
|
53
|
+
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
# Override command_help to include the description at the top of the
|
58
|
+
# long_description.
|
59
|
+
def command_help(shell, command_name)
|
60
|
+
meth = normalize_command_name(command_name)
|
61
|
+
command = all_commands[meth]
|
62
|
+
alter_command_description(command)
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
def alter_command_description(command)
|
67
|
+
return unless command
|
68
|
+
|
69
|
+
# Add description to beginning of long_description
|
70
|
+
long_desc = if command.long_description
|
71
|
+
"#{command.description}\n\n#{command.long_description}"
|
72
|
+
else
|
73
|
+
command.description
|
74
|
+
end
|
75
|
+
|
76
|
+
# add reference url to end of the long_description
|
77
|
+
unless website.empty?
|
78
|
+
full_command = [command.ancestor_name, command.name].compact.join('-')
|
79
|
+
url = "#{website}/reference/terraspace-#{full_command}"
|
80
|
+
long_desc += "\n\nHelp also available at: #{url}"
|
81
|
+
end
|
82
|
+
|
83
|
+
command.long_description = long_desc
|
84
|
+
end
|
85
|
+
private :alter_command_description
|
86
|
+
|
87
|
+
# meant to be overriden
|
88
|
+
def website
|
89
|
+
""
|
90
|
+
end
|
91
|
+
|
92
|
+
# https://github.com/erikhuda/thor/issues/244
|
93
|
+
# Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?` in `Lono::CLI`
|
94
|
+
# You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.
|
95
|
+
def exit_on_failure?
|
96
|
+
true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|