Class: RailsTemplate18f::Generators::TerraformGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsTemplate18f::Generators::TerraformGenerator
- Includes:
- Base, CloudGovOptions
- Defined in:
- lib/generators/rails_template18f/terraform/terraform_generator.rb
Instance Method Summary collapse
- #ignore_files ⇒ Object
- #install ⇒ Object
- #install_bootstrap ⇒ Object
- #install_githook ⇒ Object
- #install_shadowenv ⇒ Object
- #update_readme ⇒ Object
Instance Method Details
#ignore_files ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 58 def ignore_files unless skip_git? append_to_file ".gitignore", <<~EOM # Terraform .terraform.lock.hcl **/.terraform/* secrets.*.tfvars terraform.tfstate terraform.tfstate.backup terraform/dist EOM end end |
#install ⇒ Object
18 19 20 21 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 18 def install directory "terraform", mode: :preserve chmod "terraform/terraform.sh", 0o755 end |
#install_bootstrap ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 23 def install_bootstrap if use_gitlab_backend? directory "gitlab_bootstrap", "terraform/bootstrap", mode: :preserve elsif use_s3_backend? directory "s3_bootstrap/common", "terraform/bootstrap", mode: :preserve if terraform_manage_spaces? template "s3_bootstrap/full/main.tf", "terraform/bootstrap/main.tf" copy_file "s3_bootstrap/full/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl" else template "s3_bootstrap/sandbox/main.tf", "terraform/bootstrap/main.tf" copy_file "s3_bootstrap/sandbox/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl" end else remove_dir "terraform/.shadowenv.d" end unless terraform_manage_spaces? remove_file "terraform/bootstrap/users.auto.tfvars" remove_file "terraform/production.tfvars" end end |
#install_githook ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 78 def install_githook githook_file = ".githooks/pre-commit" if File.exist?(File.(githook_file, destination_root)) append_to_file githook_file, "\n#{githook_content}" else create_file githook_file, <<~EOM #! /usr/bin/env bash # # This hook runs on `git commit` and will prevent you from committing without # approval from the linter and tests. # # To run, this file must be symlinked to: # .git/hooks/pre-commit # # To bypass this hook, run: # $ git commit --no-verify # $ git commit -n #{githook_content} EOM chmod githook_file, 0o755 end end |
#install_shadowenv ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 44 def install_shadowenv unless use_local_backend? append_to_file "Brewfile", <<~EOB # shadowenv for loading terraform backend secrets brew "shadowenv" EOB insert_into_file "README.md", indent(<<~EOR), after: /\* Install homebrew dependencies: `brew bundle`\n/ * [shadowenv](https://shopify.github.io/shadowenv/) * See the [quick start](https://shopify.github.io/shadowenv/getting-started/#add-to-your-shell-profile) for instructions on loading shadowenv in your shell EOR end end |
#update_readme ⇒ Object
73 74 75 76 |
# File 'lib/generators/rails_template18f/terraform/terraform_generator.rb', line 73 def update_readme gsub_file "README.md", /^(### Automatic linting)\s*$/, '\1 and terraform formatting' gsub_file "README.md", /(ruby linting) (on every)/, '\1 and terraform formatting \2' end |