terraspace 0.0.0 → 0.2.1
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 +37 -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 +62 -27
- data/Rakefile +10 -2
- data/exe/terraspace +14 -0
- data/lib/templates/base/git_hook/hook.sh +5 -0
- data/lib/templates/base/project/.gitignore +33 -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/base/shim/terraspace +7 -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 +36 -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 +43 -0
- data/lib/terraspace/bundle.rb +54 -0
- data/lib/terraspace/cli.rb +202 -0
- data/lib/terraspace/cli/base.rb +11 -0
- data/lib/terraspace/cli/build/placeholder.rb +40 -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/cloud.rb +24 -0
- data/lib/terraspace/cli/commander.rb +21 -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/init.rb +67 -0
- data/lib/terraspace/cli/list.rb +13 -0
- data/lib/terraspace/cli/new.rb +40 -0
- data/lib/terraspace/cli/new/git_hook.rb +33 -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/shim.rb +58 -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 +58 -0
- data/lib/terraspace/cli/test.rb +35 -0
- data/lib/terraspace/command.rb +100 -0
- data/lib/terraspace/compiler/backend.rb +38 -0
- data/lib/terraspace/compiler/backend/parser.rb +42 -0
- data/lib/terraspace/compiler/basename.rb +10 -0
- data/lib/terraspace/compiler/builder.rb +78 -0
- data/lib/terraspace/compiler/cleaner.rb +63 -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 +7 -0
- data/lib/terraspace/compiler/dsl/syntax/mod/backend.rb +31 -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 +46 -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 +52 -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 +125 -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 +95 -0
- data/lib/terraspace/plugin/finder.rb +45 -0
- data/lib/terraspace/plugin/infer_provider.rb +15 -0
- data/lib/terraspace/plugin/layer/interface.rb +5 -0
- data/lib/terraspace/plugin/meta.rb +29 -0
- data/lib/terraspace/plugin/summary/interface.rb +130 -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/api.rb +53 -0
- data/lib/terraspace/terraform/api/client.rb +10 -0
- data/lib/terraspace/terraform/api/http.rb +106 -0
- data/lib/terraspace/terraform/api/var.rb +72 -0
- data/lib/terraspace/terraform/api/vars.rb +38 -0
- data/lib/terraspace/terraform/api/vars/base.rb +7 -0
- data/lib/terraspace/terraform/api/vars/json.rb +14 -0
- data/lib/terraspace/terraform/api/vars/rb.rb +21 -0
- data/lib/terraspace/terraform/args/custom.rb +47 -0
- data/lib/terraspace/terraform/args/default.rb +110 -0
- data/lib/terraspace/terraform/args/dsl.rb +30 -0
- data/lib/terraspace/terraform/args/shorthands.rb +47 -0
- data/lib/terraspace/terraform/cloud.rb +25 -0
- data/lib/terraspace/terraform/cloud/workspace.rb +95 -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_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 +32 -15
- metadata +721 -14
- data/.travis.yml +0 -6
@@ -0,0 +1,42 @@
|
|
1
|
+
module Terraspace::Compiler::Strategy
|
2
|
+
class Tfvar
|
3
|
+
def initialize(mod)
|
4
|
+
@mod = mod
|
5
|
+
@order = 0
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
layer_paths.each do |layer_path|
|
10
|
+
ext = File.extname(layer_path).sub('.','')
|
11
|
+
klass = strategy_class(ext)
|
12
|
+
next unless klass
|
13
|
+
|
14
|
+
strategy = klass.new(@mod, layer_path)
|
15
|
+
content = strategy.run
|
16
|
+
|
17
|
+
dest_name = ordered_name(layer_path)
|
18
|
+
writer = Terraspace::Compiler::Writer.new(@mod, dest_name: dest_name)
|
19
|
+
writer.write(content)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Tact on number to ensure that tfvars will be processed in desired order.
|
24
|
+
# Also name auto.tfvars so it will automatically load
|
25
|
+
def ordered_name(layer_path)
|
26
|
+
@order += 1
|
27
|
+
prefix = @order.to_s.rjust(2, '0') # add leading 0 in case there are more than 10 layers
|
28
|
+
name = "#{prefix}-#{File.basename(layer_path)}"
|
29
|
+
name.sub('.tfvars','.auto.tfvars')
|
30
|
+
.sub('.rb','.auto.tfvars.json')
|
31
|
+
end
|
32
|
+
|
33
|
+
def layer_paths
|
34
|
+
Layer.new(@mod).paths
|
35
|
+
end
|
36
|
+
|
37
|
+
def strategy_class(ext)
|
38
|
+
"Terraspace::Compiler::Strategy::Tfvar::#{ext.camelize}".constantize
|
39
|
+
rescue NameError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class Terraspace::Compiler::Strategy::Tfvar
|
2
|
+
class Layer
|
3
|
+
def initialize(mod)
|
4
|
+
@mod = mod
|
5
|
+
end
|
6
|
+
|
7
|
+
def paths
|
8
|
+
layer_paths = layers.map do |layer|
|
9
|
+
[
|
10
|
+
"#{tfvars_dir}/#{layer}.tfvars",
|
11
|
+
"#{tfvars_dir}/#{layer}.rb",
|
12
|
+
]
|
13
|
+
end.flatten
|
14
|
+
|
15
|
+
layer_paths.select do |path|
|
16
|
+
File.exist?(path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Layers in order
|
21
|
+
#
|
22
|
+
# Name / Pattern | Example
|
23
|
+
# -------------------------------|---------------
|
24
|
+
# base | base.tfvars
|
25
|
+
# env | dev.tfvars
|
26
|
+
# region/base | us-west-2/base.tfvars (provider specific)
|
27
|
+
# region/env | us-west-2/dev.tfvars (provider specific)
|
28
|
+
# namespace/base | 112233445566/base.tfvars (provider specific)
|
29
|
+
# namespace/env | 112233445566/dev.tfvars (provider specific)
|
30
|
+
# namespace/region/base | 112233445566/us-west-2/base.tfvars (provider specific)
|
31
|
+
# namespace/region/env | 112233445566/us-west-2/dev.tfvars (provider specific)
|
32
|
+
# provider/base | aws/base.tfvars (provider specific)
|
33
|
+
# provider/env | aws/dev.tfvars (provider specific)
|
34
|
+
# provider/region/base | aws/us-west-2/base.tfvars (provider specific)
|
35
|
+
# provider/region/env | aws/us-west-2/dev.tfvars (provider specific)
|
36
|
+
# provider/namespace/base | aws/112233445566/base.tfvars (provider specific)
|
37
|
+
# provider/namespace/env | aws/112233445566/dev.tfvars (provider specific)
|
38
|
+
# provider/namespace/region/base | aws/112233445566/us-west-2/base.tfvars (provider specific)
|
39
|
+
# provider/namespace/region/env | aws/112233445566/us-west-2/dev.tfvars (provider specific)
|
40
|
+
#
|
41
|
+
# namespace and region depends on the provider. Here an example of the mapping:
|
42
|
+
#
|
43
|
+
# | AWS | Azure | Google
|
44
|
+
# ----------|---------|--------------|-------
|
45
|
+
# namespace | account | subscription | project
|
46
|
+
# region | region | location | region
|
47
|
+
#
|
48
|
+
#
|
49
|
+
def layers
|
50
|
+
layer_levels + plugin_layers
|
51
|
+
end
|
52
|
+
|
53
|
+
def plugin_layers
|
54
|
+
layers = []
|
55
|
+
Terraspace::Plugin.layer_classes.each do |klass|
|
56
|
+
layer = klass.new
|
57
|
+
|
58
|
+
# region is high up because its simpler and the more common case is a single provider
|
59
|
+
layers += layer_levels(layer.region)
|
60
|
+
|
61
|
+
# namespace is a simple way keep different tfvars between different engineers on different accounts
|
62
|
+
layers += layer_levels(layer.namespace)
|
63
|
+
layers += layer_levels("#{layer.namespace}/#{layer.region}")
|
64
|
+
|
65
|
+
# in case using multiple providers and one region
|
66
|
+
layers += layer_levels(layer.provider)
|
67
|
+
layers += layer_levels("#{layer.provider}/#{layer.region}") # also in case another provider has colliding regions
|
68
|
+
|
69
|
+
# Most general layering
|
70
|
+
layers += layer_levels("#{layer.provider}/#{layer.namespace}")
|
71
|
+
layers += layer_levels("#{layer.provider}/#{layer.namespace}/#{layer.region}")
|
72
|
+
end
|
73
|
+
layers
|
74
|
+
end
|
75
|
+
|
76
|
+
# adds prefix and to each layer pair that has base and Terraspace.env. IE:
|
77
|
+
#
|
78
|
+
# "#{prefix}/base"
|
79
|
+
# "#{prefix}/#{Terraspace.env}"
|
80
|
+
#
|
81
|
+
def layer_levels(prefix=nil)
|
82
|
+
levels = ["base", Terraspace.env, @mod.instance] # layer levels
|
83
|
+
env_levels = levels.map { |l| "#{Terraspace.env}/#{l}" } # env folder also
|
84
|
+
levels = levels + env_levels
|
85
|
+
levels.map do |i|
|
86
|
+
[prefix, i].compact.join('/')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# seed dir takes higher precedence than the tfvars folder within the stack module. Example:
|
91
|
+
#
|
92
|
+
# seed/tfvars/stacks/demo (folder must have *.tfvars or *.rb files)
|
93
|
+
# app/stacks/demo/tfvars
|
94
|
+
#
|
95
|
+
# This allows user to take over the tfvars embedded in the stack if they need to. Generally,
|
96
|
+
# putting tfvars in within the app/stacks/MOD/tfvars folder seems cleaner and easier to follow.
|
97
|
+
#
|
98
|
+
# Will also consider app/modules/demo/tfvars. Though modules to be reuseable and stacks is where business logic
|
99
|
+
# should go.
|
100
|
+
#
|
101
|
+
def tfvars_dir
|
102
|
+
seed_dir = "#{Terraspace.root}/seed/tfvars/#{@mod.build_dir(disable_instance: true)}"
|
103
|
+
mod_dir = "#{@mod.root}/tfvars"
|
104
|
+
|
105
|
+
empty = Dir.glob("#{seed_dir}/*").empty?
|
106
|
+
empty ? mod_dir : seed_dir
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Terraspace::Compiler
|
2
|
+
class Writer
|
3
|
+
include Basename
|
4
|
+
include Terraspace::Util
|
5
|
+
|
6
|
+
def initialize(mod, options={})
|
7
|
+
@mod, @options = mod, options
|
8
|
+
@src_path = options[:src_path]
|
9
|
+
@dest_name = options[:dest_name] # override generated name
|
10
|
+
end
|
11
|
+
|
12
|
+
def dest_path
|
13
|
+
name = @dest_name || @src_path.sub('.rb','.tf.json')
|
14
|
+
name = basename(name)
|
15
|
+
"#{dest_dir}/#{name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def dest_dir
|
19
|
+
if @mod.is_a?(Terraspace::Mod::Remote)
|
20
|
+
File.dirname(@src_path) # for Mod::Remote src is dest
|
21
|
+
else
|
22
|
+
@mod.cache_dir
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def write(content)
|
27
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
28
|
+
if content.respond_to?(:path) # IO filehandle
|
29
|
+
FileUtils.cp(content.path, dest_path) # preserves permission
|
30
|
+
else # just content
|
31
|
+
IO.write(dest_path, content)
|
32
|
+
end
|
33
|
+
logger.debug "Created #{Terraspace::Util.pretty_path(dest_path)}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
=begin
|
2
|
+
Code Explanation:
|
3
|
+
|
4
|
+
There are 3 types of things to auto-complete:
|
5
|
+
|
6
|
+
1. command: the command itself
|
7
|
+
2. parameters: command parameters.
|
8
|
+
3. options: command options
|
9
|
+
|
10
|
+
Here's an example:
|
11
|
+
|
12
|
+
mycli hello name --from me
|
13
|
+
|
14
|
+
* command: hello
|
15
|
+
* parameters: name
|
16
|
+
* option: --from
|
17
|
+
|
18
|
+
When command parameters are done processing, the remaining completion words will be options. We can tell that the command params are completed based on the method arity.
|
19
|
+
|
20
|
+
## Arity
|
21
|
+
|
22
|
+
For example, say you had a method for a CLI command with the following form:
|
23
|
+
|
24
|
+
ufo scale service count --cluster dev
|
25
|
+
|
26
|
+
It's equivalent ruby method:
|
27
|
+
|
28
|
+
scale(service, count) = has an arity of 2
|
29
|
+
|
30
|
+
So typing:
|
31
|
+
|
32
|
+
ufo scale service count [TAB] # there are 3 parameters including the "scale" command according to Thor's CLI processing.
|
33
|
+
|
34
|
+
So the completion should only show options, something like this:
|
35
|
+
|
36
|
+
--noop --verbose --cluster
|
37
|
+
|
38
|
+
## Splat Arguments
|
39
|
+
|
40
|
+
When the ruby method has a splat argument, it's arity is negative. Here are some example methods and their arities.
|
41
|
+
|
42
|
+
ship(service) = 1
|
43
|
+
scale(service, count) = 2
|
44
|
+
ships(*services) = -1
|
45
|
+
foo(example, *rest) = -2
|
46
|
+
|
47
|
+
Fortunately, negative and positive arity values are processed the same way. So we take simply take the absolute value of the arity and process it the same.
|
48
|
+
|
49
|
+
Here are some test cases, hit TAB after typing the command:
|
50
|
+
|
51
|
+
terraspace completion
|
52
|
+
terraspace completion hello
|
53
|
+
terraspace completion hello name
|
54
|
+
terraspace completion hello name --
|
55
|
+
terraspace completion hello name --noop
|
56
|
+
|
57
|
+
terraspace completion
|
58
|
+
terraspace completion sub:goodbye
|
59
|
+
terraspace completion sub:goodbye name
|
60
|
+
|
61
|
+
## Subcommands and Thor::Group Registered Commands
|
62
|
+
|
63
|
+
Sometimes the commands are not simple thor commands but are subcommands or Thor::Group commands. A good specific example is the ufo tool.
|
64
|
+
|
65
|
+
* regular command: ufo ship
|
66
|
+
* subcommand: ufo docker
|
67
|
+
* Thor::Group command: ufo init
|
68
|
+
|
69
|
+
Auto-completion accounts for each of these type of commands.
|
70
|
+
=end
|
71
|
+
module Terraspace
|
72
|
+
class Completer
|
73
|
+
def initialize(command_class, *params)
|
74
|
+
@params = params
|
75
|
+
@current_command = @params[0]
|
76
|
+
@command_class = command_class # CLI initiall
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
if subcommand?(@current_command)
|
81
|
+
subcommand_class = @command_class.subcommand_classes[@current_command]
|
82
|
+
@params.shift # destructive
|
83
|
+
Completer.new(subcommand_class, *@params).run # recursively use subcommand
|
84
|
+
return
|
85
|
+
end
|
86
|
+
|
87
|
+
# full command has been found!
|
88
|
+
unless found?(@current_command)
|
89
|
+
puts all_commands
|
90
|
+
return
|
91
|
+
end
|
92
|
+
|
93
|
+
# will only get to here if command aws found (above)
|
94
|
+
arity = @command_class.instance_method(@current_command).arity.abs
|
95
|
+
if @params.size > arity or thor_group_command?
|
96
|
+
puts options_completion
|
97
|
+
else
|
98
|
+
puts params_completion
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def subcommand?(command)
|
103
|
+
@command_class.subcommands.include?(command)
|
104
|
+
end
|
105
|
+
|
106
|
+
# hacky way to detect that command is a registered Thor::Group command
|
107
|
+
def thor_group_command?
|
108
|
+
command_params(raw=true) == [[:rest, :args]]
|
109
|
+
end
|
110
|
+
|
111
|
+
def found?(command)
|
112
|
+
public_methods = @command_class.public_instance_methods(false)
|
113
|
+
command && public_methods.include?(command.to_sym)
|
114
|
+
end
|
115
|
+
|
116
|
+
# all top-level commands
|
117
|
+
def all_commands
|
118
|
+
commands = @command_class.all_commands.reject do |k,v|
|
119
|
+
v.is_a?(Thor::HiddenCommand)
|
120
|
+
end
|
121
|
+
commands.keys
|
122
|
+
end
|
123
|
+
|
124
|
+
def command_params(raw=false)
|
125
|
+
params = @command_class.instance_method(@current_command).parameters
|
126
|
+
# Example:
|
127
|
+
# >> Sub.instance_method(:goodbye).parameters
|
128
|
+
# => [[:req, :name]]
|
129
|
+
# >>
|
130
|
+
raw ? params : params.map!(&:last)
|
131
|
+
end
|
132
|
+
|
133
|
+
def params_completion
|
134
|
+
offset = @params.size - 1
|
135
|
+
offset_params = command_params[offset..-1]
|
136
|
+
command_params[offset..-1].first
|
137
|
+
end
|
138
|
+
|
139
|
+
def options_completion
|
140
|
+
used = ARGV.select { |a| a.include?('--') } # so we can remove used options
|
141
|
+
|
142
|
+
method_options = @command_class.all_commands[@current_command].options.keys
|
143
|
+
class_options = @command_class.class_options.keys
|
144
|
+
|
145
|
+
all_options = method_options + class_options + ['help']
|
146
|
+
|
147
|
+
all_options.map! { |o| "--#{o.to_s.gsub('_','-')}" }
|
148
|
+
filtered_options = all_options - used
|
149
|
+
filtered_options.uniq
|
150
|
+
end
|
151
|
+
|
152
|
+
# Useful for debugging. Using puts messes up completion.
|
153
|
+
def log(msg)
|
154
|
+
File.open("/tmp/complete.log", "a") do |file|
|
155
|
+
file.puts(msg)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
_terraspace() {
|
2
|
+
COMPREPLY=()
|
3
|
+
local word="${COMP_WORDS[COMP_CWORD]}"
|
4
|
+
local words=("${COMP_WORDS[@]}")
|
5
|
+
unset words[0]
|
6
|
+
local completion=$(terraspace completion ${words[@]})
|
7
|
+
COMPREPLY=( $(compgen -W "$completion" -- "$word") )
|
8
|
+
}
|
9
|
+
|
10
|
+
complete -F _terraspace terraspace
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Terraspace
|
2
|
+
module Core
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def env
|
6
|
+
ENV['TS_ENV'] || "dev"
|
7
|
+
end
|
8
|
+
memoize :env
|
9
|
+
|
10
|
+
@@root = nil
|
11
|
+
def root
|
12
|
+
@@root ||= ENV['TS_ROOT'] || Dir.pwd
|
13
|
+
end
|
14
|
+
|
15
|
+
# allow testing frameworks to switch roots
|
16
|
+
def root=(v)
|
17
|
+
@@root = v
|
18
|
+
end
|
19
|
+
|
20
|
+
def cache_root
|
21
|
+
ENV['TS_CACHE_ROOT'] || config.build.cache_root || "#{root}/.terraspace-cache"
|
22
|
+
end
|
23
|
+
memoize :cache_root
|
24
|
+
|
25
|
+
def tmp_root
|
26
|
+
ENV['TS_TMP_ROOT'] || "/tmp/terraspace"
|
27
|
+
end
|
28
|
+
memoize :tmp_root
|
29
|
+
|
30
|
+
def configure(&block)
|
31
|
+
App.instance.configure(&block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generally, use the Terraspace.config instead of App.instance.config since it guarantees the load_project_config call
|
35
|
+
def config
|
36
|
+
App.instance.load_project_config
|
37
|
+
App.instance.config
|
38
|
+
end
|
39
|
+
memoize :config
|
40
|
+
|
41
|
+
def logger
|
42
|
+
config.logger
|
43
|
+
end
|
44
|
+
memoize :logger
|
45
|
+
|
46
|
+
def check_project!
|
47
|
+
return if File.exist?("#{Terraspace.root}/config/app.rb")
|
48
|
+
logger.error "ERROR: It doesnt look like this is a terraspace project. Are you sure you are in a terraspace project?".color(:red)
|
49
|
+
ENV['TS_TEST'] ? raise : exit(1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|