rails_template_18f 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +3 -1
  5. data/README.md +4 -4
  6. data/lib/generators/rails_template18f/circleci/circleci_generator.rb +26 -10
  7. data/lib/generators/rails_template18f/dap/dap_generator.rb +72 -0
  8. data/lib/generators/rails_template18f/github_actions/github_actions_generator.rb +27 -11
  9. data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +79 -0
  10. data/{templates/config/newrelic.yml → lib/generators/rails_template18f/newrelic/templates/config/newrelic.yml.tt} +7 -7
  11. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/README.md.tt +0 -0
  12. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/import.sh +0 -0
  13. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/main.tf.tt +3 -3
  14. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/providers.tf +0 -0
  15. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/run.sh.tt +1 -1
  16. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +5 -0
  17. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/variables.tf +0 -0
  18. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/create_space_deployer.sh +0 -0
  19. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/destroy_space_deployer.sh +0 -0
  20. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/production/main.tf.tt +4 -4
  21. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/production/providers.tf.tt +0 -0
  22. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/production/variables.tf +0 -0
  23. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/database/main.tf.tt +0 -0
  24. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/database/providers.tf +0 -0
  25. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/database/variables.tf +0 -0
  26. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/domain/main.tf.tt +1 -1
  27. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/domain/providers.tf +0 -0
  28. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/domain/variables.tf +0 -0
  29. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/main.tf +0 -0
  30. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/providers.tf +0 -0
  31. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/variables.tf +0 -0
  32. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/staging/main.tf.tt +4 -4
  33. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/staging/providers.tf.tt +0 -0
  34. data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/staging/variables.tf +0 -0
  35. data/lib/generators/rails_template18f/terraform/terraform_generator.rb +95 -0
  36. data/lib/rails_template18f/generators/base.rb +36 -0
  37. data/lib/rails_template18f/generators/cloud_gov_options.rb +57 -0
  38. data/lib/rails_template18f/generators/pipeline_options.rb +18 -0
  39. data/lib/rails_template18f/generators.rb +11 -0
  40. data/lib/rails_template18f/version.rb +1 -1
  41. data/lib/rails_template_18f.rb +1 -4
  42. data/template.rb +17 -61
  43. data/templates/README.md.tt +7 -44
  44. data/templates/doc/compliance/apps/application.boundary.md.tt +4 -24
  45. data/templates/githooks/{pre-commit.tt → pre-commit} +0 -15
  46. data/templates/manifest.yml.tt +1 -2
  47. metadata +35 -29
  48. data/lib/rails_template18f/terraform_options.rb +0 -68
  49. data/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa50caac6d934e7a1d6611ac427068601ad836f81fab7b088aed2b47de3724b
4
- data.tar.gz: 7dd5b479db57b51ce6eadbe53134605a346db5de2e4c490510a59c3ec56f644b
3
+ metadata.gz: f3b689fcfbc4d7ed1a476adc0b415ed0cbbfc24828937431820b5850db77e564
4
+ data.tar.gz: 5f95740853330bc904b23c67059a578b3f616cea6228c7c99a19d4eee5c26518
5
5
  SHA512:
6
- metadata.gz: '08bba6304087afcfda8ac54101628312329963338a36ed488768bdfdc2a296a9b54140df951108eaa8cbc563d29cd35a461379e6039d17a4f910a50b60313890'
7
- data.tar.gz: ad54e4be93ee88883503ed96f6a7ace02f00509d584b02e122b7fb66117a2baf6cd19f444f3f74f26c3209280be0204926e3ab2e8c217a1a59d600572b7f9abe
6
+ metadata.gz: 6c350c36aeddf44806c2ddbd36dbacd626f361890a9a648ec6e58e4dbeba5b60928ece499542bae318f7f7f644af52b55c7b9e9f6639291f7dd00c00229f5334
7
+ data.tar.gz: 75079b3718a90069ae1484b54b86dac37c89be836bd132afc8bd936fb0e1451aa85882a5fafa8a980f60094ce352fb933d7ae0179a557a9b6196d018d2a681c1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2022-02-16
4
+
5
+ - terraform generator
6
+ - DAP generator
7
+ - Newrelic generator
8
+
3
9
  ## [0.1.0] - 2022-02-14
4
10
 
5
11
  - Initial release
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "colorize", "~> 0.8"
11
+
12
+ gem "byebug"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_template_18f (0.1.0)
4
+ rails_template_18f (0.2.0)
5
5
  activesupport (~> 7.0.0)
6
6
  railties (~> 7.0.0)
7
7
 
@@ -32,6 +32,7 @@ GEM
32
32
  rspec-rails (>= 2.2)
33
33
  ast (2.4.2)
34
34
  builder (3.2.4)
35
+ byebug (11.1.3)
35
36
  colorize (0.8.1)
36
37
  concurrent-ruby (1.1.9)
37
38
  crass (1.0.6)
@@ -122,6 +123,7 @@ PLATFORMS
122
123
 
123
124
  DEPENDENCIES
124
125
  ammeter (~> 1.1)
126
+ byebug
125
127
  colorize (~> 0.8)
126
128
  rails_template_18f!
127
129
  rake (~> 13.0)
data/README.md CHANGED
@@ -97,10 +97,10 @@ ActionCable is included to enable the [Turbo Streams](https://turbo.hotwired.dev
97
97
  1. Optionally create Github Actions workflows for testing and cloud.gov deploy
98
98
  1. Optionally create terraform modules supporting staging & production cloud.gov spaces
99
99
  1. Optionally create CircleCI workflows for testing and cloud.gov deploy
100
- 1. Optionally create [Architecture Decision Records](https://adr.github.io/) for above setup
101
100
  1. Optionally create a New Relic config with FEDRAMP-specific host
102
101
  1. Optionally configure DAP (Digital Analytics Program)
103
102
  1. Optionally add base translation files and routes for Spanish, French, and Simplified Chinese (es.yml, fr.yml, and zh.yml)
103
+ 1. Create [Architecture Decision Records](https://adr.github.io/) for above setup
104
104
  1. Commit the resulting project with git (unless `--skip-git` is passed)
105
105
 
106
106
  ## Use for an existing Rails project
@@ -110,7 +110,7 @@ ActionCable is included to enable the [Turbo Streams](https://turbo.hotwired.dev
110
110
  Add this line to your application's Gemfile:
111
111
 
112
112
  ```ruby
113
- gem "rails-template-18f"
113
+ gem "rails_template_18f", group: :development
114
114
  ```
115
115
 
116
116
  And then run:
@@ -119,7 +119,7 @@ And then run:
119
119
 
120
120
  Or install it yourself as:
121
121
 
122
- $ gem install rails-template-18f
122
+ $ gem install rails_template_18f
123
123
 
124
124
  ### Usage
125
125
 
@@ -133,7 +133,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
133
133
 
134
134
  ## Contributing
135
135
 
136
- Bug reports and pull requests are welcome on GitHub at https://github.com/rahearn/rails-template-18f. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rahearn/rails-template-18f/blob/main/CODE_OF_CONDUCT.md).
136
+ Bug reports and pull requests are welcome on GitHub at https://github.com/18f/rails-template. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/18f/rails-template/blob/main/CODE_OF_CONDUCT.md).
137
137
 
138
138
  ## Code of Conduct
139
139
 
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators"
4
+
3
5
  module RailsTemplate18f
4
6
  module Generators
5
7
  class CircleciGenerator < ::Rails::Generators::Base
6
- include ::Rails::Generators::AppName
7
- include RailsTemplate18f::TerraformOptions
8
+ include Base
9
+ include PipelineOptions
8
10
 
9
11
  desc <<~DESC
10
12
  Description:
11
13
  Install CircleCI pipeline files
12
14
  DESC
13
15
 
14
- def self.source_root
15
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), "templates"))
16
- end
17
-
18
16
  def install_needed_gems
19
17
  gem "rspec_junit_formatter", "~> 0.5", group: :test
20
18
  end
@@ -27,10 +25,28 @@ module RailsTemplate18f
27
25
  end
28
26
 
29
27
  def update_readme
30
- insert_into_file "README.md", readme_cicd, after: "## CI/CD\n"
31
- insert_into_file "README.md", readme_staging_deploy, after: "#### Staging\n"
32
- insert_into_file "README.md", readme_prod_deploy, after: "#### Production\n"
33
- insert_into_file "README.md", readme_credentials, after: "#### Credentials and other Secrets\n"
28
+ if file_content("README.md").match?(/^## CI\/CD$/)
29
+ insert_into_file "README.md", readme_cicd, after: "## CI/CD\n"
30
+ insert_into_file "README.md", readme_staging_deploy, after: "#### Staging\n"
31
+ insert_into_file "README.md", readme_prod_deploy, after: "#### Production\n"
32
+ insert_into_file "README.md", readme_credentials, after: "#### Credentials and other Secrets\n"
33
+ else
34
+ append_to_file "README.md", <<~EOM
35
+ ## CI/CD
36
+ #{readme_cicd}
37
+
38
+ ### Deployment
39
+
40
+ #### Staging
41
+ #{readme_staging_deploy}
42
+
43
+ #### Production
44
+ #{readme_prod_deploy}
45
+
46
+ #### Credentials and other Secrets
47
+ #{readme_credentials}
48
+ EOM
49
+ end
34
50
  end
35
51
 
36
52
  def update_boundary_diagram
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module RailsTemplate18f
6
+ module Generators
7
+ class DapGenerator < ::Rails::Generators::Base
8
+ include Base
9
+
10
+ class_option :agency_code, default: "GSA", desc: "Agency code to track DAP metrics"
11
+
12
+ desc <<~DESC
13
+ Description:
14
+ Install JS snippet for Digital Analytics Program (DAP)
15
+ DESC
16
+
17
+ def update_content_security_policy
18
+ csp_file = "config/initializers/content_security_policy.rb"
19
+ gsub_file csp_file, /(policy.img_src .*)$/, '\1, "https://www.google-analytics.com"'
20
+ gsub_file csp_file, /(policy.script_src .*)$/, '\1, "https://dap.digitalgov.gov", "https://www.google-analytics.com"'
21
+ if file_content(csp_file).match?(/policy.connect_src/)
22
+ gsub_file csp_file, /(policy.connect_src .*)$/, '\1, "https://dap.digitalgov.gov", "https://www.google-analytics.com"'
23
+ else
24
+ gsub_file csp_file, /((#?)(\s+)policy.script_src .*)$/, "\\1\n\\2\\3policy.connect_src :self, \"https://dap.digitalgov.gov\", \"https://www.google-analytics.com\""
25
+ end
26
+ end
27
+
28
+ def install_js_snippet
29
+ insert_into_file "app/views/layouts/application.html.erb", <<EODAP, before: /^\s+<\/head>/
30
+
31
+ <% if Rails.env.production? %>
32
+ <!-- We participate in the US government's analytics program. See the data at analytics.usa.gov. -->
33
+ <%= javascript_include_tag "https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=#{options[:agency_code]}", async: true, id:"_fed_an_ua_tag" %>
34
+ <% end %>
35
+ EODAP
36
+ end
37
+
38
+ def update_readme
39
+ insertion_regex = /^## Documentation$/
40
+ if file_content("README.md").match?(insertion_regex)
41
+ insert_into_file "README.md", readme, before: insertion_regex
42
+ else
43
+ append_to_file "README.md", readme
44
+ end
45
+ end
46
+
47
+ def update_boundary_diagram
48
+ boundary_filename = "doc/compliance/apps/application.boundary.md"
49
+ insert_into_file boundary_filename, <<EOB, after: "Boundary(gsa_saas, \"GSA-authorized SaaS\") {\n"
50
+ System_Ext(dap, "DAP", "Analytics collection")
51
+ EOB
52
+ insert_into_file boundary_filename, <<~EOB, before: "@enduml"
53
+ Rel(browser, dap, "reports usage", "https (443)")
54
+ Rel(developer, dap, "View traffic statistics", "https GET (443)")
55
+ EOB
56
+ end
57
+
58
+ no_tasks do
59
+ def readme
60
+ <<~EOM
61
+ ## Analytics
62
+
63
+ Digital Analytics Program (DAP) code has been included for the Production environment, associated with #{options[:agency_code]}.
64
+
65
+ If #{app_name.titleize} is for another agency, update the agency line in `app/views/layouts/application.html.erb`
66
+
67
+ EOM
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators"
4
+
3
5
  module RailsTemplate18f
4
6
  module Generators
5
7
  class GithubActionsGenerator < ::Rails::Generators::Base
6
- include ::Rails::Generators::AppName
7
- include RailsTemplate18f::TerraformOptions
8
+ include Base
9
+ include PipelineOptions
8
10
 
9
11
  class_option :node_version, desc: "Node version to test against in actions"
10
12
 
@@ -13,10 +15,6 @@ module RailsTemplate18f
13
15
  Install Github Actions workflow files
14
16
  DESC
15
17
 
16
- def self.source_root
17
- @source_root ||= File.expand_path("templates", __dir__)
18
- end
19
-
20
18
  def install_actions
21
19
  directory "github", ".github"
22
20
  if !terraform?
@@ -26,10 +24,28 @@ module RailsTemplate18f
26
24
  end
27
25
 
28
26
  def update_readme
29
- insert_into_file "README.md", readme_cicd, after: "## CI/CD\n"
30
- insert_into_file "README.md", readme_staging_deploy, after: "#### Staging\n"
31
- insert_into_file "README.md", readme_prod_deploy, after: "#### Production\n"
32
- insert_into_file "README.md", readme_credentials, after: "#### Credentials and other Secrets\n"
27
+ if file_content("README.md").match?(/^## CI\/CD$/)
28
+ insert_into_file "README.md", readme_cicd, after: "## CI/CD\n"
29
+ insert_into_file "README.md", readme_staging_deploy, after: "#### Staging\n"
30
+ insert_into_file "README.md", readme_prod_deploy, after: "#### Production\n"
31
+ insert_into_file "README.md", readme_credentials, after: "#### Credentials and other Secrets\n"
32
+ else
33
+ append_to_file "README.md", <<~EOM
34
+ ## CI/CD
35
+ #{readme_cicd}
36
+
37
+ ### Deployment
38
+
39
+ #### Staging
40
+ #{readme_staging_deploy}
41
+
42
+ #### Production
43
+ #{readme_prod_deploy}
44
+
45
+ #### Credentials and other Secrets
46
+ #{readme_credentials}
47
+ EOM
48
+ end
33
49
  end
34
50
 
35
51
  def update_boundary_diagram
@@ -48,7 +64,7 @@ EOB
48
64
  readme_filename = "terraform/README.md"
49
65
  insert_into_file readme_filename, " |- .force-action-apply\n", after: " |- secrets.auto.tfvars\n"
50
66
  insert_into_file readme_filename, <<~EOM, after: /- `secrets.auto.tfvars`.*$/
51
- - `.force-action-apply` is a file that can be updated to force GitHub Actions to run `terraform apply` during the deploy phase
67
+ \n- `.force-action-apply` is a file that can be updated to force GitHub Actions to run `terraform apply` during the deploy phase
52
68
  EOM
53
69
  end
54
70
 
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module RailsTemplate18f
6
+ module Generators
7
+ class NewrelicGenerator < ::Rails::Generators::Base
8
+ include Base
9
+
10
+ desc <<~DESC
11
+ Description:
12
+ Install NewRelic config for FedRAMP collection
13
+ DESC
14
+
15
+ def update_content_security_policy
16
+ csp_file = "config/initializers/content_security_policy.rb"
17
+ gsub_file csp_file, /(policy.script_src .*)$/, '\1, "https://js-agent.newrelic.com", "https://*.nr-data.net"'
18
+ if file_content(csp_file).match?(/policy.connect_src/)
19
+ gsub_file csp_file, /(policy.connect_src .*)$/, '\1, "https://*.nr-data.net"'
20
+ else
21
+ gsub_file csp_file, /((#?)(\s+)policy.script_src .*)$/, "\\1\n\\2\\3policy.connect_src :self, \"https://*.nr-data.net\""
22
+ end
23
+ end
24
+
25
+ def install_gem
26
+ gem "newrelic_rpm", "~> 8.4"
27
+ end
28
+
29
+ def install_config
30
+ template "config/newrelic.yml"
31
+ end
32
+
33
+ def update_cloud_gov_manifest
34
+ insert_into_file "manifest.yml", " NEW_RELIC_LOG: stdout\n", before: /^\s+processes:/
35
+ end
36
+
37
+ def update_readme
38
+ insertion_regex = /^## Documentation$/
39
+ if file_content("README.md").match?(insertion_regex)
40
+ insert_into_file "README.md", readme, before: insertion_regex
41
+ else
42
+ append_to_file "README.md", readme
43
+ end
44
+ end
45
+
46
+ def update_boundary_diagram
47
+ boundary_filename = "doc/compliance/apps/application.boundary.md"
48
+ insert_into_file boundary_filename, <<EOB, after: "Boundary(gsa_saas, \"GSA-authorized SaaS\") {\n"
49
+ System_Ext(newrelic, "New Relic", "Monitoring SaaS")
50
+ EOB
51
+ insert_into_file boundary_filename, <<~EOB, before: "@enduml"
52
+ Rel(app, newrelic, "reports telemetry (ruby agent)", "tcp (443)")
53
+ Rel(browser, newrelic, "reports ux metrics (javascript agent)", "https (443)")
54
+ Rel(developer, newrelic, "Manage performance", "https (443)")
55
+ EOB
56
+ end
57
+
58
+ no_tasks do
59
+ def readme
60
+ <<~EOM
61
+ ## Monitoring with New Relic
62
+
63
+ The [New Relic Ruby agent](https://docs.newrelic.com/docs/apm/agents/ruby-agent/getting-started/introduction-new-relic-ruby) has been installed for monitoring this application.
64
+
65
+ The config lives at `config/newrelic.yml`, and points to a [FEDRAMP version of the New Relic service as its host](https://docs.newrelic.com/docs/security/security-privacy/compliance/fedramp-compliant-endpoints/). To access the metrics dashboard, you will need to be connected to VPN.
66
+
67
+ ### Getting started
68
+
69
+ To get started sending metrics via New Relic APM:
70
+ 1. Add your New Relic license key to the Rails credentials with key `new_relic_key`.
71
+ 1. Optionally, update `app_name` entries in `config/newrelic.yml` with what is registered for your application in New Relic
72
+ 1. Comment out the `agent_enabled: false` line in `config/newrelic.yml`
73
+ 1. Add the [Javascript snippet provided by New Relic](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent) into `application.html.erb`. It is recommended to vary this based on environment (i.e. include one snippet for staging and another for production).
74
+ EOM
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -10,14 +10,14 @@
10
10
 
11
11
  common: &default_settings
12
12
  # Required license key associated with your New Relic account.
13
- license_key: <%= Rails.application.credentials.new_relic_key %>
13
+ license_key: <%%= Rails.application.credentials.new_relic_key %>
14
14
  # FEDRAMP-specific New Relic host
15
15
  # https://docs.newrelic.com/docs/security/security-privacy/compliance/fedramp-compliant-endpoints/
16
16
  host: 'gov-collector.newrelic.com'
17
17
 
18
18
  # Your application name. Renaming here affects where data displays in New
19
19
  # Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
20
- app_name: <APPNAME>
20
+ app_name: <%= app_name.titleize %>
21
21
 
22
22
  monitor_mode: true
23
23
 
@@ -30,8 +30,8 @@ common: &default_settings
30
30
 
31
31
  # This line disables agent regardless of other settings.
32
32
  # To enable the New Relic agent:
33
- # 1) Replace <APPNAME> in this file with the application name you want to show in New Relic
34
- # 2) add the New Relic license keys to the appropriate encrypted credentials file(s)
33
+ # 1) add the New Relic license keys to the appropriate encrypted credentials file(s)
34
+ # 2) Optionally, update app_name entries in this file with the application name you want to show in New Relic
35
35
  # 3) Comment out the line below
36
36
  agent_enabled: false
37
37
 
@@ -44,7 +44,7 @@ common: &default_settings
44
44
  # If your application has other named environments, configure them here.
45
45
  development:
46
46
  <<: *default_settings
47
- app_name: <APPNAME> (Development)
47
+ app_name: <%= app_name.titleize %> (Development)
48
48
 
49
49
  test:
50
50
  <<: *default_settings
@@ -58,8 +58,8 @@ ci:
58
58
 
59
59
  staging:
60
60
  <<: *default_settings
61
- app_name: <APPNAME> (Staging)
61
+ app_name: <%= app_name.titleize %> (Staging)
62
62
 
63
63
  production:
64
64
  <<: *default_settings
65
- app_name: <APPNAME> (Production)
65
+ app_name: <%= app_name.titleize %> (Production)
@@ -9,9 +9,9 @@ module "s3" {
9
9
  cf_api_url = local.cf_api_url
10
10
  cf_user = var.cf_user
11
11
  cf_password = var.cf_password
12
- cf_org_name = "<%= @cloud_gov_organization %>"
13
- cf_space_name = "<%= @cloud_gov_production_space %>"
14
- s3_service_name = local.s3_service_name<% if @cloud_gov_organization == "sandbox-gsa" %>
12
+ cf_org_name = "<%= cloud_gov_organization %>"
13
+ cf_space_name = "<%= cloud_gov_production_space %>"
14
+ s3_service_name = local.s3_service_name<% if cloud_gov_organization == "sandbox-gsa" %>
15
15
  s3_plan_name = "basic-sandbox"<% end %>
16
16
  }
17
17
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  if [[ ! -f "secrets.auto.tfvars" ]]; then
4
- ../create_space_deployer.sh <%= @cloud_gov_production_space %> config-bootstrap-deployer > secrets.auto.tfvars
4
+ ../create_space_deployer.sh <%= cloud_gov_production_space %> config-bootstrap-deployer > secrets.auto.tfvars
5
5
  fi
6
6
 
7
7
  if [[ $# -gt 0 ]]; then
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ../destroy_space_deployer.sh <%= cloud_gov_production_space %> config-bootstrap-deployer
4
+
5
+ rm secrets.auto.tfvars
@@ -1,6 +1,6 @@
1
1
  locals {
2
- cf_org_name = "<%= @cloud_gov_organization %>"
3
- cf_space_name = "<%= @cloud_gov_production_space %>"
2
+ cf_org_name = "<%= cloud_gov_organization %>"
3
+ cf_space_name = "<%= cloud_gov_production_space %>"
4
4
  env = "production"
5
5
  recursive_delete = false
6
6
  }
@@ -17,7 +17,7 @@ module "database" {
17
17
  rds_plan_name = "TKTK-production-rds-plan"
18
18
  }
19
19
 
20
- <% if !skip_active_storage? %>
20
+ <% if has_active_storage? %>
21
21
  module "s3" {
22
22
  source = "../shared/s3"
23
23
 
@@ -34,7 +34,7 @@ module "s3" {
34
34
  # It can be re-enabled after:
35
35
  # 1) the app has first been deployed
36
36
  # 2) the route has been manually created by an OrgManager:
37
- # `cf create-domain <%= @cloud_gov_organization %> TKTK-production-domain-name`
37
+ # `cf create-domain <%= cloud_gov_organization %> TKTK-production-domain-name`
38
38
  ###########################################################################
39
39
  # module "domain" {
40
40
  # source = "../shared/domain"
@@ -19,7 +19,7 @@ data "cloudfoundry_app" "app" {
19
19
  ###########################################################################
20
20
  # Route must be manually created by an OrgManager before terraform is run:
21
21
  #
22
- # cf create-domain <%= @cloud_gov_organization %> TKTK-production-domain-name
22
+ # cf create-domain <%= cloud_gov_organization %> TKTK-production-domain-name
23
23
  ###########################################################################
24
24
  data "cloudfoundry_domain" "origin_url" {
25
25
  name = var.domain_name
@@ -1,6 +1,6 @@
1
1
  locals {
2
- cf_org_name = "<%= @cloud_gov_organization %>"
3
- cf_space_name = "<%= @cloud_gov_staging_space %>"
2
+ cf_org_name = "<%= cloud_gov_organization %>"
3
+ cf_space_name = "<%= cloud_gov_staging_space %>"
4
4
  env = "staging"
5
5
  recursive_delete = true
6
6
  }
@@ -17,7 +17,7 @@ module "database" {
17
17
  rds_plan_name = "micro-psql"
18
18
  }
19
19
 
20
- <% if !skip_active_storage? %>
20
+ <% if has_active_storage? %>
21
21
  module "s3" {
22
22
  source = "../shared/s3"
23
23
 
@@ -27,4 +27,4 @@ module "s3" {
27
27
  cf_space_name = local.cf_space_name
28
28
  s3_service_name = "<%= app_name %>-s3-${local.env}"
29
29
  }
30
- <% end %>
30
+ <% end %>
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module RailsTemplate18f
6
+ module Generators
7
+ class TerraformGenerator < ::Rails::Generators::Base
8
+ include Base
9
+ include CloudGovOptions
10
+
11
+ desc <<~DESC
12
+ Description:
13
+ Install terraform files for cloud.gov database and s3 services
14
+ DESC
15
+
16
+ def install
17
+ directory "terraform", mode: :preserve
18
+ chmod "terraform/bootstrap/run.sh", 0o755
19
+ chmod "terraform/bootstrap/teardown_creds.sh", 0o755
20
+ end
21
+
22
+ def ignore_files
23
+ unless skip_git?
24
+ append_to_file ".gitignore", <<~EOM
25
+
26
+ # Terraform
27
+ .terraform.lock.hcl
28
+ **/.terraform/*
29
+ secrets.auto.tfvars
30
+ terraform.tfstate
31
+ terraform.tfstate.backup
32
+ EOM
33
+ end
34
+ end
35
+
36
+ def update_readme
37
+ gsub_file "README.md", /^(### Automatic linting)/, '\1 and terraform formatting'
38
+ gsub_file "README.md", /(ruby linting) (on every)/, '\1 and terraform formatting \2'
39
+ gsub_file "README.md", /^Before the first deploy only.*$/, "Follow the instructions in `terraform/README.md` to create the supporting services."
40
+ end
41
+
42
+ def install_githook
43
+ githook_file = ".githooks/pre-commit"
44
+ if File.exist?(File.expand_path(githook_file, destination_root))
45
+ append_to_file githook_file, "\n#{githook_content}"
46
+ else
47
+ create_file githook_file, <<~EOM
48
+ #! /usr/bin/env bash
49
+ #
50
+ # This hook runs on `git commit` and will prevent you from committing without
51
+ # approval from the linter and tests.
52
+ #
53
+ # To run, this file must be symlinked to:
54
+ # .git/hooks/pre-commit
55
+ #
56
+ # To bypass this hook, run:
57
+ # $ git commit --no-verify
58
+ # $ git commit -n
59
+
60
+ #{githook_content}
61
+ EOM
62
+ chmod githook_file, 0o755
63
+ end
64
+ end
65
+
66
+ no_tasks do
67
+ def githook_content
68
+ <<~EOM
69
+ echo "Running Terraform formatter"
70
+ files=$(git diff --cached --name-only terraform)
71
+ for f in $files
72
+ do
73
+ # Format any *.tf files that were cached/staged
74
+ if [ -e "$f" ] && [[ $f == *.tf ]]; then
75
+ terraform fmt "$f"
76
+ git add "$f"
77
+ fi
78
+ done
79
+ EOM
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def terraform_dir_exists?
86
+ # prevents cloud_gov_* helpers from trying to read non-existant .tf files
87
+ false
88
+ end
89
+
90
+ def has_active_storage?
91
+ defined?(::ActiveStorage)
92
+ end
93
+ end
94
+ end
95
+ end