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,106 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class Terraspace::Terraform::Api
|
4
|
+
class Http
|
5
|
+
include Terraspace::Util::Logging
|
6
|
+
|
7
|
+
API = ENV['TERRAFORM_API'] || 'https://app.terraform.io/api/v2'
|
8
|
+
extend Memoist
|
9
|
+
|
10
|
+
def get(path)
|
11
|
+
request(Net::HTTP::Get, path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(path, data={})
|
15
|
+
request(Net::HTTP::Post, path, data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def patch(path, data={})
|
19
|
+
request(Net::HTTP::Patch, path, data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(path, data={})
|
23
|
+
request(Net::HTTP::Delete, path, data)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Always translate raw json response to ruby Hash
|
27
|
+
def request(klass, path, data={})
|
28
|
+
url = url(path)
|
29
|
+
http = http(url)
|
30
|
+
req = build_request(klass, url, data)
|
31
|
+
resp = http.request(req) # send request
|
32
|
+
load_json(resp)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_request(klass, url, data={})
|
36
|
+
req = klass.new(url) # url includes query string and uri.path does not, must used url
|
37
|
+
set_headers!(req)
|
38
|
+
if [Net::HTTP::Delete, Net::HTTP::Patch, Net::HTTP::Post, Net::HTTP::Put].include?(klass)
|
39
|
+
text = JSON.dump(data)
|
40
|
+
req.body = text
|
41
|
+
req.content_length = text.bytesize
|
42
|
+
end
|
43
|
+
req
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_headers!(req)
|
47
|
+
req['Authorization'] = "Bearer #{token}"
|
48
|
+
req['Content-Type'] = "application/vnd.api+json"
|
49
|
+
end
|
50
|
+
|
51
|
+
def http(url)
|
52
|
+
uri = URI(url)
|
53
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
54
|
+
http.open_timeout = http.read_timeout = 30
|
55
|
+
http.use_ssl = true if uri.scheme == 'https'
|
56
|
+
http
|
57
|
+
end
|
58
|
+
memoize :http
|
59
|
+
|
60
|
+
# API does not include the /. IE: https://app.terraform.io/api/v2
|
61
|
+
def url(path)
|
62
|
+
"#{API}/#{path}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_json(res)
|
66
|
+
if res.code == "200"
|
67
|
+
JSON.load(res.body)
|
68
|
+
else
|
69
|
+
if ENV['TERRASPACE_DEBUG_API']
|
70
|
+
puts "Error: Non-successful http response status code: #{res.code}"
|
71
|
+
puts "headers: #{res.each_header.to_h.inspect}"
|
72
|
+
end
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def token
|
78
|
+
token ||= ENV['TERRAFORM_TOKEN']
|
79
|
+
return token if token
|
80
|
+
|
81
|
+
creds_path = "#{ENV['HOME']}/.terraform.d/credentials.tfrc.json"
|
82
|
+
if File.exist?(creds_path)
|
83
|
+
data = JSON.load(IO.read(creds_path))
|
84
|
+
token = data.dig('credentials', 'app.terraform.io', 'token')
|
85
|
+
end
|
86
|
+
|
87
|
+
# Note only way to get here is to bypass init. Example:
|
88
|
+
#
|
89
|
+
# terraspace up demo --no-init
|
90
|
+
#
|
91
|
+
unless token
|
92
|
+
logger.error "ERROR: Unable to not find a Terraform token. A Terraform token is needed for Terraspace to call the Terraform API.".color(:red)
|
93
|
+
logger.error <<~EOL
|
94
|
+
Here are some ways to provide the Terraform token:
|
95
|
+
|
96
|
+
1. By running: terraform login
|
97
|
+
2. With an env variable: export TERRAFORM_TOKEN=xxx
|
98
|
+
|
99
|
+
Please configure a Terraform token and try again.
|
100
|
+
EOL
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
token
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class Terraspace::Terraform::Api
|
2
|
+
class Var
|
3
|
+
extend Memoist
|
4
|
+
include Client
|
5
|
+
include Terraspace::Util::Logging
|
6
|
+
|
7
|
+
def initialize(workspace, attrs={})
|
8
|
+
@workspace, @attrs = workspace, attrs
|
9
|
+
@workspace_id = @workspace['id']
|
10
|
+
end
|
11
|
+
|
12
|
+
def sync
|
13
|
+
exist? ? update : create
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
return unless overwrite?
|
18
|
+
logger.debug "Updating Terraform Cloud #{category} variable: #{@attrs['key']}"
|
19
|
+
variable_id = variable_id(@attrs['key'])
|
20
|
+
payload = payload(variable_id)
|
21
|
+
http.patch("workspaces/#{@workspace_id}/vars/#{variable_id}", payload)
|
22
|
+
end
|
23
|
+
|
24
|
+
def overwrite?
|
25
|
+
cloud = Terraspace.config.cloud
|
26
|
+
if @attrs['sensitive']
|
27
|
+
cloud.overwrite_sensitive
|
28
|
+
else
|
29
|
+
cloud.overwrite
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def variable_id(key)
|
34
|
+
current_var_resp['id']
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
logger.info "Creating Terraform Cloud #{category} variable: #{@attrs['key']}"
|
39
|
+
http.post("workspaces/#{@workspace_id}/vars", payload)
|
40
|
+
end
|
41
|
+
|
42
|
+
def payload(id=nil)
|
43
|
+
data = {
|
44
|
+
type: "vars",
|
45
|
+
attributes: @attrs
|
46
|
+
}
|
47
|
+
data[:id] = id if id
|
48
|
+
{ data: data }
|
49
|
+
end
|
50
|
+
|
51
|
+
def exist?
|
52
|
+
!!current_var_resp
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_var_resp
|
56
|
+
current_vars_resp['data'].find do |item|
|
57
|
+
attributes = item['attributes']
|
58
|
+
attributes['key'] == @attrs['key'] &&
|
59
|
+
attributes['category'] == category
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def category
|
64
|
+
@attrs['category'] || 'terraform' # default category when not set is terraform
|
65
|
+
end
|
66
|
+
|
67
|
+
@@current_vars_resp = nil
|
68
|
+
def current_vars_resp
|
69
|
+
@@current_vars_resp ||= http.get("workspaces/#{@workspace_id}/vars")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Terraspace::Terraform::Api
|
2
|
+
class Vars
|
3
|
+
extend Memoist
|
4
|
+
include Client
|
5
|
+
|
6
|
+
def initialize(mod, workspace)
|
7
|
+
@mod, @workspace = mod, workspace
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
return unless exist?
|
12
|
+
|
13
|
+
vars = vars_class.new(@mod, vars_path).vars
|
14
|
+
vars.each do |attrs|
|
15
|
+
Var.new(@workspace, attrs).sync
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return value examples:
|
20
|
+
#
|
21
|
+
# Terraspace::Terraform::Api::Vars::Json
|
22
|
+
# Terraspace::Terraform::Api::Vars::Rb
|
23
|
+
#
|
24
|
+
def vars_class
|
25
|
+
ext = File.extname(vars_path).sub('.','')
|
26
|
+
"Terraspace::Terraform::Api::Vars::#{ext.camelize}".constantize
|
27
|
+
end
|
28
|
+
|
29
|
+
def exist?
|
30
|
+
!!vars_path
|
31
|
+
end
|
32
|
+
|
33
|
+
def vars_path
|
34
|
+
# .rb takes higher precedence
|
35
|
+
Dir.glob("#{Terraspace.root}/config/terraform/cloud/vars.{rb,json}").first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Terraspace::Terraform::Api::Vars
|
2
|
+
class Json < Base
|
3
|
+
def vars
|
4
|
+
context = Terraspace::Compiler::Erb::Context.new(@mod)
|
5
|
+
result = RenderMePretty.result(@vars_path, context: context)
|
6
|
+
|
7
|
+
data = JSON.load(result)
|
8
|
+
items = data.select do |item|
|
9
|
+
item['data']['type'] == 'vars'
|
10
|
+
end
|
11
|
+
items.map { |i| i['data']['attributes'] }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Terraspace::Terraform::Api::Vars
|
2
|
+
class Rb < Base
|
3
|
+
include DslEvaluator
|
4
|
+
|
5
|
+
def initialize(*)
|
6
|
+
super
|
7
|
+
@vars = [] # holds results
|
8
|
+
end
|
9
|
+
|
10
|
+
def vars
|
11
|
+
evaluate_file(@vars_path)
|
12
|
+
@vars
|
13
|
+
end
|
14
|
+
|
15
|
+
def var(attrs={})
|
16
|
+
default = { category: "terraform" } # required field
|
17
|
+
var = default.deep_merge(attrs).deep_stringify_keys!
|
18
|
+
@vars << var
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Terraspace::Terraform::Args
|
2
|
+
class Custom
|
3
|
+
extend Memoist
|
4
|
+
include Dsl
|
5
|
+
include DslEvaluator
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
def initialize(mod, name)
|
9
|
+
@mod, @name = mod, name
|
10
|
+
@file = "#{Terraspace.root}/config/cli/args.rb"
|
11
|
+
@commands = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def build
|
15
|
+
return @commands unless File.exist?(@file)
|
16
|
+
evaluate_file(@file)
|
17
|
+
@commands.deep_stringify_keys!
|
18
|
+
end
|
19
|
+
memoize :build
|
20
|
+
|
21
|
+
def args
|
22
|
+
build
|
23
|
+
args = dig("args")
|
24
|
+
args.compact.flatten
|
25
|
+
end
|
26
|
+
|
27
|
+
def var_files
|
28
|
+
build
|
29
|
+
var_files = dig("var_files")
|
30
|
+
var_files.select! { |f| var_file_exist?(f) }
|
31
|
+
var_files.map { |f| "-var-file=#{f}" }
|
32
|
+
end
|
33
|
+
|
34
|
+
def env_vars
|
35
|
+
build
|
36
|
+
dig("env", {})
|
37
|
+
end
|
38
|
+
|
39
|
+
def var_file_exist?(var_file)
|
40
|
+
File.exist?("#{@mod.cache_dir}/#{var_file}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def dig(prop, default=[])
|
44
|
+
@commands.dig(@name, prop) || default
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
module Terraspace::Terraform::Args
|
4
|
+
class Default
|
5
|
+
def initialize(mod, name, options={})
|
6
|
+
@mod, @name, @options = mod, name, options
|
7
|
+
@quiet = @options[:quiet].nil? ? true : @options[:quiet]
|
8
|
+
end
|
9
|
+
|
10
|
+
def args
|
11
|
+
# https://terraspace.cloud/docs/ci-automation/
|
12
|
+
ENV['TF_IN_AUTOMATION'] = '1' if @options[:auto]
|
13
|
+
|
14
|
+
if %w[apply destroy init output plan].include?(@name)
|
15
|
+
meth = "#{@name}_args"
|
16
|
+
send(meth)
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def apply_args
|
23
|
+
args = auto_approve_arg
|
24
|
+
var_files = @options[:var_files]
|
25
|
+
if var_files
|
26
|
+
args << var_files.map { |f| "-var-file #{Dir.pwd}/#{f}" }.join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
if @options[:auto] && @options[:input].nil?
|
30
|
+
args << " -input=false"
|
31
|
+
end
|
32
|
+
unless @options[:input].nil?
|
33
|
+
input = @options[:input] ? "true" : "false"
|
34
|
+
args << " -input=#{input}" # = sign required for apply when there's a plan at the end. so input=false works input false doesnt
|
35
|
+
end
|
36
|
+
|
37
|
+
# must be at the end
|
38
|
+
plan = @options[:plan]
|
39
|
+
if plan
|
40
|
+
if plan.starts_with?('/')
|
41
|
+
src = plan
|
42
|
+
dest = src
|
43
|
+
else
|
44
|
+
src = "#{Dir.pwd}/#{plan}"
|
45
|
+
dest = "#{@mod.cache_dir}/#{File.basename(src)}"
|
46
|
+
end
|
47
|
+
FileUtils.cp(src, dest)
|
48
|
+
args << " #{dest}"
|
49
|
+
end
|
50
|
+
args
|
51
|
+
end
|
52
|
+
|
53
|
+
def init_args
|
54
|
+
args = "-get"
|
55
|
+
if @options[:auto] && @options[:input].nil?
|
56
|
+
args << " -input=false"
|
57
|
+
end
|
58
|
+
unless @options[:input].nil?
|
59
|
+
input = @options[:input] ? "true" : "false"
|
60
|
+
args << " -input=#{input}"
|
61
|
+
end
|
62
|
+
|
63
|
+
args << " -reconfigure" if @options[:reconfigure]
|
64
|
+
|
65
|
+
# must be at the end
|
66
|
+
if @quiet && !ENV['TS_INIT_LOUD']
|
67
|
+
out_path = self.class.terraform_init_log
|
68
|
+
FileUtils.mkdir_p(File.dirname(out_path))
|
69
|
+
args << " > #{out_path}"
|
70
|
+
end
|
71
|
+
[args]
|
72
|
+
end
|
73
|
+
|
74
|
+
def plan_args
|
75
|
+
args = []
|
76
|
+
args << "-out #{expanded_out}" if @options[:out]
|
77
|
+
args
|
78
|
+
end
|
79
|
+
|
80
|
+
def output_args
|
81
|
+
args = []
|
82
|
+
args << "-json" if @options[:format] == "json"
|
83
|
+
args << "> #{expanded_out}" if @options[:out]
|
84
|
+
args
|
85
|
+
end
|
86
|
+
|
87
|
+
def expanded_out
|
88
|
+
out = @options[:out]
|
89
|
+
out.starts_with?('/') ? out : "#{Dir.pwd}/#{out}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def destroy_args
|
93
|
+
auto_approve_arg
|
94
|
+
end
|
95
|
+
|
96
|
+
def auto_approve_arg
|
97
|
+
@options[:yes] || @options[:auto] ? ["-auto-approve"] : []
|
98
|
+
end
|
99
|
+
|
100
|
+
class << self
|
101
|
+
# Use different tmp log file in case uses run terraspace up in 2 terminals at the same time
|
102
|
+
@@terraform_init_log = nil
|
103
|
+
def terraform_init_log
|
104
|
+
return @@terraform_init_log if @@terraform_init_log
|
105
|
+
basename = File.basename(Tempfile.new('terraform-init').path)
|
106
|
+
@@terraform_init_log = "#{Terraspace.tmp_root}/out/#{basename}.out"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Terraspace::Terraform::Args
|
2
|
+
module Dsl
|
3
|
+
include Shorthands
|
4
|
+
|
5
|
+
def command(*commands, **props)
|
6
|
+
commands.each do |name|
|
7
|
+
if shorthand?(name)
|
8
|
+
shorthand_commands(name, props)
|
9
|
+
else
|
10
|
+
each_command(name, props)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method :commands, :command
|
15
|
+
|
16
|
+
def shorthand?(name)
|
17
|
+
shorthands.key?(name.to_sym)
|
18
|
+
end
|
19
|
+
|
20
|
+
def shorthand_commands(name, props)
|
21
|
+
shorthands[name].each do |n|
|
22
|
+
each_command(n, props)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_command(name, props={})
|
27
|
+
@commands[name] = props
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|