rails_template_18f 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +71 -70
- data/README.md +11 -16
- data/lib/generators/rails_template18f/active_storage/active_storage_generator.rb +7 -6
- data/lib/generators/rails_template18f/circleci/circleci_generator.rb +28 -27
- data/lib/generators/rails_template18f/circleci/templates/Dockerfile.ci.tt +0 -1
- data/lib/generators/rails_template18f/circleci/templates/circleci/config.yml.tt +152 -158
- data/lib/generators/rails_template18f/github_actions/github_actions_generator.rb +31 -30
- data/lib/generators/rails_template18f/github_actions/templates/github/actions/compile-assets/action.yml +50 -0
- data/lib/generators/rails_template18f/github_actions/templates/github/actions/setup-project/action.yml.tt +4 -8
- data/lib/generators/rails_template18f/github_actions/templates/github/dependabot.yml.tt +2 -4
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml +72 -0
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml +72 -0
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-daily-scan.yml.tt +10 -1
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-scan.yml.tt +1 -1
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/pa11y.yml.tt +2 -2
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-production.yml +46 -3
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-staging.yml +46 -3
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/validate-ssp.yml +2 -2
- data/lib/generators/rails_template18f/i18n_js/i18n_js_generator.rb +12 -20
- data/lib/generators/rails_template18f/i18n_js/templates/app/javascript/i18n/index.js +11 -0
- data/lib/generators/rails_template18f/i18n_js/templates/config/i18n-js.yml +4 -0
- data/lib/generators/rails_template18f/i18n_js/templates/config/initializers/i18n_js.rb +5 -0
- data/lib/generators/rails_template18f/i18n_js/templates/lib/tasks/i18n.rake +8 -7
- data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +4 -2
- data/lib/generators/rails_template18f/public_egress/public_egress_generator.rb +168 -0
- data/lib/generators/rails_template18f/sidekiq/sidekiq_generator.rb +8 -17
- data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/imports.tf.tftpl +25 -0
- data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/main.tf.tt +159 -0
- data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/imports.tf.tftpl +10 -0
- data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/main.tf.tt +117 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/README.md.tt +77 -93
- data/lib/generators/rails_template18f/terraform/templates/terraform/app.tf.tt +63 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/apply.sh +15 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/backend_config.tftpl +8 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/bot_secrets.tftpl +5 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/users.auto.tfvars +5 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/main.tf.tt +106 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/production.tfvars.tt +10 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/providers.tf.tt +32 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/main.tf +74 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/run.sh +17 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/staging.tfvars.tt +8 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/terraform.sh.tt +135 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/variables.tf.tt +99 -0
- data/lib/generators/rails_template18f/terraform/terraform_generator.rb +13 -4
- data/lib/rails_template18f/generators/base.rb +7 -0
- data/lib/rails_template18f/generators/cloud_gov_options.rb +10 -27
- data/lib/rails_template18f/generators/cloud_gov_parsing.rb +41 -0
- data/lib/rails_template18f/generators.rb +1 -1
- data/lib/rails_template18f/version.rb +1 -1
- data/rails-template-18f.gemspec +4 -4
- data/railsrc +4 -2
- data/railsrc-hotwire +4 -2
- data/template.rb +61 -71
- data/templates/README.md.tt +21 -8
- data/templates/app/assets/stylesheets/uswds-settings.scss +3 -2
- data/templates/app/views/application/_header.html.erb +1 -1
- data/templates/app/views/application/_usa_banner.html.erb +3 -3
- data/templates/bin/ops/create_service_account.sh.tt +30 -9
- data/templates/bin/ops/destroy_service_account.sh.tt +3 -6
- data/templates/browserslistrc +1 -2
- data/templates/doc/compliance/TODO.md +1 -4
- metadata +34 -28
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml.tt +0 -42
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml.tt +0 -42
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/import.sh +0 -13
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/main.tf.tt +0 -22
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/providers.tf +0 -16
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/run.sh.tt +0 -39
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/variables.tf +0 -2
- data/lib/generators/rails_template18f/terraform/templates/terraform/production/main.tf.tt +0 -70
- data/lib/generators/rails_template18f/terraform/templates/terraform/production/providers.tf.tt +0 -23
- data/lib/generators/rails_template18f/terraform/templates/terraform/production/variables.tf +0 -2
- data/lib/generators/rails_template18f/terraform/templates/terraform/staging/main.tf.tt +0 -52
- data/lib/generators/rails_template18f/terraform/templates/terraform/staging/providers.tf.tt +0 -23
- data/lib/generators/rails_template18f/terraform/templates/terraform/staging/variables.tf +0 -2
- data/lib/rails_template18f/generators/pipeline_options.rb +0 -18
- data/templates/app/assets/images/uswds.js +0 -6
- data/templates/config/deployment/production.yml +0 -3
- data/templates/config/deployment/staging.yml +0 -3
- data/templates/manifest.yml.tt +0 -17
@@ -0,0 +1,106 @@
|
|
1
|
+
locals {
|
2
|
+
cf_org_name = "<%= cloud_gov_organization %>"
|
3
|
+
app_name = "<%= app_name %>"
|
4
|
+
space_deployers = setunion([var.cf_user], var.space_deployers)
|
5
|
+
}
|
6
|
+
|
7
|
+
<% if terraform_manage_spaces? %>
|
8
|
+
module "app_space" {
|
9
|
+
source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=v2.1.0"
|
10
|
+
|
11
|
+
cf_org_name = local.cf_org_name
|
12
|
+
cf_space_name = var.cf_space_name
|
13
|
+
allow_ssh = var.allow_space_ssh
|
14
|
+
deployers = local.space_deployers
|
15
|
+
developers = var.space_developers
|
16
|
+
security_group_names = ["trusted_local_networks_egress"]
|
17
|
+
}
|
18
|
+
<% else %>
|
19
|
+
data "cloudfoundry_org" "org" {
|
20
|
+
name = local.cf_org_name
|
21
|
+
}
|
22
|
+
data "cloudfoundry_space" "app_space" {
|
23
|
+
name = var.cf_space_name
|
24
|
+
org = data.cloudfoundry_org.org.id
|
25
|
+
}
|
26
|
+
data "cloudfoundry_security_group" "trusted_egress_security_group" {
|
27
|
+
name = "trusted_local_networks_egress"
|
28
|
+
}
|
29
|
+
resource "cloudfoundry_security_group_space_bindings" "trusted_egress_binding" {
|
30
|
+
security_group = data.cloudfoundry_security_group.trusted_egress_security_group.id
|
31
|
+
running_spaces = [data.cloudfoundry_space.app_space.id]
|
32
|
+
}
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
module "database" {
|
36
|
+
source = "github.com/gsa-tts/terraform-cloudgov//database?ref=v2.1.0"
|
37
|
+
|
38
|
+
cf_space_id = <% if terraform_manage_spaces? %>module.app_space.space_id<% else %>data.cloudfoundry_space.app_space.id<% end %>
|
39
|
+
name = "${local.app_name}-rds-${var.env}"
|
40
|
+
rds_plan_name = var.rds_plan_name<% if terraform_manage_spaces? %>
|
41
|
+
# depends_on line is required only for initial creation and destruction. It can be commented out for updates if you see unwanted cascading effects
|
42
|
+
depends_on = [module.app_space]<% end %>
|
43
|
+
}
|
44
|
+
<% if has_active_job? %>
|
45
|
+
module "redis" {
|
46
|
+
source = "github.com/gsa-tts/terraform-cloudgov//redis?ref=v2.1.0"
|
47
|
+
|
48
|
+
cf_space_id = <% if terraform_manage_spaces? %>module.app_space.space_id<% else %>data.cloudfoundry_space.app_space.id<% end %>
|
49
|
+
name = "${local.app_name}-redis-${var.env}"
|
50
|
+
redis_plan_name = var.redis_plan_name<% if terraform_manage_spaces? %>
|
51
|
+
# depends_on line is required only for initial creation and destruction. It can be commented out for updates if you see unwanted cascading effects
|
52
|
+
depends_on = [module.app_space]<% end %>
|
53
|
+
}
|
54
|
+
<% end %>
|
55
|
+
<% if has_active_storage? %>
|
56
|
+
module "s3" {
|
57
|
+
source = "github.com/gsa-tts/terraform-cloudgov//s3?ref=v2.1.0"
|
58
|
+
|
59
|
+
cf_space_id = <% if terraform_manage_spaces? %>module.app_space.space_id<% else %>data.cloudfoundry_space.app_space.id<% end %>
|
60
|
+
name = "${local.app_name}-s3-${var.env}"
|
61
|
+
s3_plan_name = var.s3_plan_name<% if terraform_manage_spaces? %>
|
62
|
+
# depends_on line is required only for initial creation and destruction. It can be commented out for updates if you see unwanted cascading effects
|
63
|
+
depends_on = [module.app_space]<% end %>
|
64
|
+
}
|
65
|
+
|
66
|
+
module "clamav" {
|
67
|
+
source = "github.com/gsa-tts/terraform-cloudgov//clamav?ref=v2.1.0"
|
68
|
+
|
69
|
+
cf_org_name = local.cf_org_name
|
70
|
+
cf_space_name = var.cf_space_name
|
71
|
+
name = "${local.app_name}-clamapi-${var.env}"
|
72
|
+
clamav_image = "ghcr.io/gsa-tts/clamav-rest/clamav:latest"
|
73
|
+
max_file_size = "30M"<% if terraform_manage_spaces? %>
|
74
|
+
# depends_on line is required only for initial creation and destruction. It can be commented out for updates if you see unwanted cascading effects
|
75
|
+
depends_on = [module.app_space]<% end %>
|
76
|
+
}
|
77
|
+
|
78
|
+
resource "cloudfoundry_network_policy" "clamav_routing" {
|
79
|
+
provider = cloudfoundry-community
|
80
|
+
policy {
|
81
|
+
source_app = cloudfoundry_app.app.id
|
82
|
+
destination_app = module.clamav.app_id
|
83
|
+
port = "61443"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
<% end %>
|
87
|
+
|
88
|
+
###########################################################################
|
89
|
+
# Before setting var.custom_domain_name, perform the following steps:
|
90
|
+
# 1) Domain must be manually created by an OrgManager:
|
91
|
+
# cf create-domain var.cf_org_name var.domain_name
|
92
|
+
# 2) ACME challenge record must be created.
|
93
|
+
# See https://cloud.gov/docs/services/external-domain-service/#how-to-create-an-instance-of-this-service
|
94
|
+
###########################################################################
|
95
|
+
module "domain" {
|
96
|
+
count = (var.custom_domain_name == null ? 0 : 1)
|
97
|
+
source = "github.com/gsa-tts/terraform-cloudgov//domain?ref=v2.1.0"
|
98
|
+
|
99
|
+
cf_org_name = local.cf_org_name
|
100
|
+
cf_space = <% if terraform_manage_spaces? %>module.app_space.space<% else %>data.cloudfoundry_space.app_space<% end %>
|
101
|
+
cdn_plan_name = "domain"
|
102
|
+
domain_name = var.custom_domain_name
|
103
|
+
host_name = var.host_name<% if terraform_manage_spaces? %>
|
104
|
+
# depends_on line is required only for initial creation and destruction. It can be commented out for updates if you see unwanted cascading effects
|
105
|
+
depends_on = [module.app_space]<% end %>
|
106
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
cf_space_name = "<%= cloud_gov_production_space %>"
|
2
|
+
env = "production"
|
3
|
+
rds_plan_name = "TKTK-production-rds-plan"
|
4
|
+
custom_domain_name = null
|
5
|
+
host_name = null
|
6
|
+
web_instances = 2
|
7
|
+
web_memory = "512M"
|
8
|
+
<% if has_active_storage? %>s3_plan_name = "basic"<% end %>
|
9
|
+
<% if has_active_job? %>redis_plan_name = "TKTK-production-redis-plan"<% end %>
|
10
|
+
<% if has_active_job? %>worker_memory = "512M"<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "~> 1.10"
|
3
|
+
required_providers {<% if has_active_storage? %>
|
4
|
+
cloudfoundry-community = {
|
5
|
+
source = "cloudfoundry-community/cloudfoundry"
|
6
|
+
version = "0.53.1"
|
7
|
+
}<% end %>
|
8
|
+
cloudfoundry = {
|
9
|
+
source = "cloudfoundry/cloudfoundry"
|
10
|
+
version = "1.2.0"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
backend "s3" {
|
15
|
+
encrypt = true
|
16
|
+
use_lockfile = true
|
17
|
+
region = "us-gov-west-1"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
provider "cloudfoundry" {
|
22
|
+
api_url = "https://api.fr.cloud.gov"
|
23
|
+
user = var.cf_user
|
24
|
+
password = var.cf_password
|
25
|
+
}
|
26
|
+
<% if has_active_storage? %>
|
27
|
+
provider "cloudfoundry-community" {
|
28
|
+
api_url = "https://api.fr.cloud.gov"
|
29
|
+
user = var.cf_user
|
30
|
+
password = var.cf_password
|
31
|
+
}
|
32
|
+
<% end %>
|
@@ -0,0 +1,74 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "~> 1.10"
|
3
|
+
required_providers {
|
4
|
+
cloudfoundry = {
|
5
|
+
source = "cloudfoundry/cloudfoundry"
|
6
|
+
version = "1.1.0"
|
7
|
+
}
|
8
|
+
}
|
9
|
+
backend "local" {}
|
10
|
+
}
|
11
|
+
# empty config will let terraform borrow cf-cli's auth
|
12
|
+
provider "cloudfoundry" {}
|
13
|
+
|
14
|
+
variable "sandbox_name" {
|
15
|
+
type = string
|
16
|
+
description = "Name of the sandbox environment we're deploying into"
|
17
|
+
}
|
18
|
+
|
19
|
+
locals {
|
20
|
+
sa_service_name = "${var.sandbox_name}-local-deployer"
|
21
|
+
sa_key_name = "deployer-access-key"
|
22
|
+
sa_bot_credentials = jsondecode(data.cloudfoundry_service_credential_binding.runner_sa_key.credential_bindings.0.credential_binding).credentials
|
23
|
+
sa_cf_username = nonsensitive(local.sa_bot_credentials.username)
|
24
|
+
}
|
25
|
+
|
26
|
+
data "cloudfoundry_service_plans" "cg_service_account" {
|
27
|
+
name = "space-deployer"
|
28
|
+
service_offering_name = "cloud-gov-service-account"
|
29
|
+
}
|
30
|
+
data "terraform_remote_state" "bootstrap" {
|
31
|
+
backend = "local"
|
32
|
+
config = {
|
33
|
+
path = "${path.module}/../bootstrap/terraform.tfstate"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
resource "cloudfoundry_service_instance" "runner_service_account" {
|
37
|
+
name = local.sa_service_name
|
38
|
+
type = "managed"
|
39
|
+
space = data.terraform_remote_state.bootstrap.outputs.mgmt_space_id
|
40
|
+
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans.0.id
|
41
|
+
}
|
42
|
+
|
43
|
+
resource "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
44
|
+
name = local.sa_key_name
|
45
|
+
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
46
|
+
type = "key"
|
47
|
+
}
|
48
|
+
data "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
49
|
+
name = local.sa_key_name
|
50
|
+
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
51
|
+
depends_on = [cloudfoundry_service_credential_binding.runner_sa_key]
|
52
|
+
}
|
53
|
+
|
54
|
+
data "cloudfoundry_user" "sa_user" {
|
55
|
+
name = local.sa_cf_username
|
56
|
+
}
|
57
|
+
resource "cloudfoundry_org_role" "sa_org_manager" {
|
58
|
+
user = data.cloudfoundry_user.sa_user.users.0.id
|
59
|
+
type = "organization_manager"
|
60
|
+
org = data.terraform_remote_state.bootstrap.outputs.mgmt_org_id
|
61
|
+
}
|
62
|
+
|
63
|
+
resource "local_sensitive_file" "bot_secrets_file" {
|
64
|
+
filename = "${path.module}/../secrets.auto.tfvars"
|
65
|
+
file_permission = "0600"
|
66
|
+
|
67
|
+
content = <<-EOT
|
68
|
+
# "${local.sa_service_name}"/"${local.sa_key_name}" generated by sandbox_bot terraform module.
|
69
|
+
# Run `./run.sh ${var.sandbox_name} destroy` in that directory to clean up
|
70
|
+
|
71
|
+
cf_user = "${local.sa_cf_username}"
|
72
|
+
cf_password = "${local.sa_bot_credentials.password}"
|
73
|
+
EOT
|
74
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
if [[ $# -lt 2 ]]; then
|
6
|
+
echo "usage: $0 SANDBOX_NAME TERRAFORM_CMD [TERRAFORM_ARGS]"
|
7
|
+
echo "You must pass the sandbox_name as the first argument and terraform command as the second"
|
8
|
+
echo "All other arguments are passed as-is to terraform"
|
9
|
+
exit 1
|
10
|
+
fi
|
11
|
+
|
12
|
+
sandbox_name="$1"
|
13
|
+
cmd="$2"
|
14
|
+
shift 2
|
15
|
+
|
16
|
+
terraform init -backend-config="path=$sandbox_name/terraform.tfstate" -reconfigure
|
17
|
+
terraform "$cmd" -var sandbox_name="$sandbox_name" "$@"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
cf_space_name = "<%= cloud_gov_staging_space %>"
|
2
|
+
env = "staging"
|
3
|
+
allow_space_ssh = true
|
4
|
+
# host_name must be unique across cloud.gov, default is "<%= app_name %>-${var.env}"
|
5
|
+
host_name = null
|
6
|
+
space_developers = [
|
7
|
+
# enter developer emails that should have ssh access to staging
|
8
|
+
]
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
rmk_file="../config/master.key"
|
4
|
+
cmd="plan"
|
5
|
+
|
6
|
+
usage="
|
7
|
+
$0: Run terraform commands against a given environment
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
$0 -h
|
11
|
+
$0 -e <ENV NAME> [-k <RAILS_MASTER_KEY>] [-f] [-c <TERRAFORM-CMD>] [-- <EXTRA CMD ARGUMENTS>]
|
12
|
+
|
13
|
+
Options:
|
14
|
+
-h: show help and exit
|
15
|
+
-e ENV_NAME: The name of the environment to run terraform against
|
16
|
+
-k RAILS_MASTER_KEY: RAILS_MASTER_KEY value. Defaults to contents of $rmk_file
|
17
|
+
-f: Force, pass -auto-approve to all invocations of terraform
|
18
|
+
-c TERRAFORM-CMD: command to run. Defaults to $cmd
|
19
|
+
[<EXTRA CMD ARGUMENTS>]: arguments to pass as-is to terraform
|
20
|
+
"
|
21
|
+
|
22
|
+
|
23
|
+
rmk=`cat $rmk_file || echo -n ""`
|
24
|
+
env=""
|
25
|
+
force=""
|
26
|
+
args_to_shift=0
|
27
|
+
|
28
|
+
set -e
|
29
|
+
while getopts ":he:k:fc:" opt; do
|
30
|
+
case "$opt" in
|
31
|
+
e)
|
32
|
+
env=${OPTARG}
|
33
|
+
args_to_shift=$((args_to_shift + 2))
|
34
|
+
;;
|
35
|
+
k)
|
36
|
+
rmk=${OPTARG}
|
37
|
+
args_to_shift=$((args_to_shift + 2))
|
38
|
+
;;
|
39
|
+
f)
|
40
|
+
force="-auto-approve"
|
41
|
+
args_to_shift=$((args_to_shift + 1))
|
42
|
+
;;
|
43
|
+
c)
|
44
|
+
cmd=${OPTARG}
|
45
|
+
args_to_shift=$((args_to_shift + 2))
|
46
|
+
;;
|
47
|
+
h)
|
48
|
+
echo "$usage"
|
49
|
+
exit 0
|
50
|
+
;;
|
51
|
+
esac
|
52
|
+
done
|
53
|
+
|
54
|
+
shift $args_to_shift
|
55
|
+
if [[ "$1" = "--" ]]; then
|
56
|
+
shift 1
|
57
|
+
fi
|
58
|
+
|
59
|
+
if [[ -z "$env" ]]; then
|
60
|
+
echo "-e <ENV_NAME> is required"
|
61
|
+
echo "$usage"
|
62
|
+
exit 1
|
63
|
+
fi
|
64
|
+
|
65
|
+
if [[ ! -f "$env.tfvars" ]]; then
|
66
|
+
echo "$env.tfvars file is missing. Create it first"
|
67
|
+
exit 1
|
68
|
+
fi
|
69
|
+
|
70
|
+
# ensure we're logged in via cli
|
71
|
+
cf spaces &> /dev/null || cf login -a api.fr.cloud.gov --sso
|
72
|
+
|
73
|
+
tfm_needs_init=true
|
74
|
+
if [[ -f .terraform/terraform.tfstate ]]; then
|
75
|
+
backend_state_env=`cat .terraform/terraform.tfstate | jq -r ".backend.config.key" | cut -d '.' -f3`
|
76
|
+
if [[ "$backend_state_env" = "$env" ]]; then
|
77
|
+
tfm_needs_init=false
|
78
|
+
fi
|
79
|
+
fi
|
80
|
+
|
81
|
+
if [[ $tfm_needs_init = true ]]; then
|
82
|
+
if [[ ! -f secrets.backend.tfvars ]]; then
|
83
|
+
echo "=============================================================================================================="
|
84
|
+
echo "= Recreating backend config file. It is fine if this step wants to delete any local_sensitive_file resources"
|
85
|
+
echo "=============================================================================================================="
|
86
|
+
(cd bootstrap && ./apply.sh $force)
|
87
|
+
fi
|
88
|
+
terraform init -backend-config=secrets.backend.tfvars -backend-config="key=terraform.tfstate.$env" -reconfigure
|
89
|
+
fi
|
90
|
+
|
91
|
+
echo "=============================================================================================================="
|
92
|
+
echo "= Creating a bot deployer for $env"
|
93
|
+
echo "=============================================================================================================="
|
94
|
+
<% if terraform_manage_spaces? %>
|
95
|
+
if [[ "$env" = "staging" ]] || [[ "$env" = "production" ]]; then
|
96
|
+
(cd bootstrap && ./apply.sh -var create_bot_secrets_file=true $force)
|
97
|
+
else
|
98
|
+
(cd sandbox_bot && ./run.sh "$env" apply $force)
|
99
|
+
fi
|
100
|
+
<% else %>
|
101
|
+
if [[ ! -f secrets.auto.tfvars ]]; then
|
102
|
+
../bin/ops/create_service_account.sh -s <%= cloud_gov_staging_space %> -u terraform-deployer -n > secrets.auto.tfvars
|
103
|
+
fi
|
104
|
+
<% end %>
|
105
|
+
|
106
|
+
if [[ -f secrets.backend.tfvars ]]; then
|
107
|
+
rm secrets.backend.tfvars
|
108
|
+
fi
|
109
|
+
|
110
|
+
echo "=============================================================================================================="
|
111
|
+
echo "= Calling $cmd $force on the application infrastructure"
|
112
|
+
echo "=============================================================================================================="
|
113
|
+
terraform "$cmd" -var-file="$env.tfvars" -var rails_master_key="$rmk" $force "$@"
|
114
|
+
|
115
|
+
<% if terraform_manage_spaces? %>
|
116
|
+
if [[ "$cmd" = "destroy" ]] && [[ "$env" != "staging" ]] && [[ "$env" != "production" ]]; then
|
117
|
+
<% else %>
|
118
|
+
if [[ "$cmd" = "destroy" ]]; then
|
119
|
+
<% end %>
|
120
|
+
if [[ -z "$force" ]]; then
|
121
|
+
read -p "Destroy the sandbox_bot user? (y/n) " confirm
|
122
|
+
if [[ "$confirm" != "y" ]]; then
|
123
|
+
exit 0
|
124
|
+
fi
|
125
|
+
fi
|
126
|
+
echo "=============================================================================================================="
|
127
|
+
echo "= Destroying the sandbox_bot user"
|
128
|
+
echo "=============================================================================================================="
|
129
|
+
<% if terraform_manage_spaces? %>
|
130
|
+
(cd sandbox_bot && ./run.sh "$env" destroy -auto-approve)
|
131
|
+
<% else %>
|
132
|
+
../bin/ops/destroy_service_account.sh -s <%= cloud_gov_staging_space %> -u terraform-deployer
|
133
|
+
rm secrets.auto.tfvars
|
134
|
+
<% end %>
|
135
|
+
fi
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Deploy user settings
|
2
|
+
variable "cf_user" {
|
3
|
+
type = string
|
4
|
+
description = "The service account running the terraform"
|
5
|
+
}
|
6
|
+
variable "cf_password" {
|
7
|
+
type = string
|
8
|
+
sensitive = true
|
9
|
+
description = "The service account password"
|
10
|
+
}
|
11
|
+
|
12
|
+
# app_space settings
|
13
|
+
variable "cf_space_name" {
|
14
|
+
type = string
|
15
|
+
description = "The space name to deploy the app into"
|
16
|
+
}
|
17
|
+
variable "space_deployers" {
|
18
|
+
type = set(string)
|
19
|
+
default = []
|
20
|
+
description = "A list of users to be granted SpaceDeveloper & SpaceManager on cf_space_name"
|
21
|
+
}
|
22
|
+
variable "space_developers" {
|
23
|
+
type = set(string)
|
24
|
+
default = []
|
25
|
+
description = "A list of users to be granted SpaceDeveloper on cf_space_name"
|
26
|
+
}
|
27
|
+
variable "allow_space_ssh" {
|
28
|
+
type = bool
|
29
|
+
default = false
|
30
|
+
description = "Whether to allow ssh to cf_space_name"
|
31
|
+
}
|
32
|
+
|
33
|
+
# supporting services settings
|
34
|
+
variable "rds_plan_name" {
|
35
|
+
type = string
|
36
|
+
default = "micro-psql"
|
37
|
+
description = "The name of the rds plan to create"
|
38
|
+
}
|
39
|
+
<% if has_active_job? %>
|
40
|
+
variable "redis_plan_name" {
|
41
|
+
type = string
|
42
|
+
default = "redis-dev"
|
43
|
+
description = "The name of the redis plan to create"
|
44
|
+
}
|
45
|
+
<% end %>
|
46
|
+
<% if has_active_storage? %>
|
47
|
+
variable "s3_plan_name" {
|
48
|
+
type = string
|
49
|
+
default = "basic-sandbox"
|
50
|
+
description = "The name of the s3 plan to use"
|
51
|
+
}
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
# routing settings
|
55
|
+
variable "custom_domain_name" {
|
56
|
+
type = string
|
57
|
+
default = null
|
58
|
+
description = "The custom domain name to associate with the app. Leave as null to disable the domain service and use an *.app.cloud.gov route"
|
59
|
+
}
|
60
|
+
variable "host_name" {
|
61
|
+
type = string
|
62
|
+
default = null
|
63
|
+
description = "An optional hostname to prepend to either the custom domain name or app.cloud.gov"
|
64
|
+
}
|
65
|
+
|
66
|
+
# App environment settings
|
67
|
+
variable "env" {
|
68
|
+
type = string
|
69
|
+
description = "The RAILS_ENV to set for the app (staging or production)"
|
70
|
+
}
|
71
|
+
|
72
|
+
variable "rails_master_key" {
|
73
|
+
type = string
|
74
|
+
sensitive = true
|
75
|
+
description = "config/master.key"
|
76
|
+
}
|
77
|
+
|
78
|
+
variable "web_instances" {
|
79
|
+
type = number
|
80
|
+
default = 1
|
81
|
+
description = "The number of instances of the web process"
|
82
|
+
}
|
83
|
+
variable "web_memory" {
|
84
|
+
type = string
|
85
|
+
default = "256M"
|
86
|
+
description = "The amount of memory to assign to the web processes"
|
87
|
+
}
|
88
|
+
<% if has_active_job? %>
|
89
|
+
variable "worker_instances" {
|
90
|
+
type = number
|
91
|
+
default = 1
|
92
|
+
description = "The number of instances of the worker process"
|
93
|
+
}
|
94
|
+
variable "worker_memory" {
|
95
|
+
type = string
|
96
|
+
default = "256M"
|
97
|
+
description = "The amount of memory to assign to the worker processes"
|
98
|
+
}
|
99
|
+
<% end %>
|
@@ -15,8 +15,17 @@ module RailsTemplate18f
|
|
15
15
|
|
16
16
|
def install
|
17
17
|
directory "terraform", mode: :preserve
|
18
|
-
chmod "terraform/
|
19
|
-
|
18
|
+
chmod "terraform/terraform.sh", 0o755
|
19
|
+
if terraform_manage_spaces?
|
20
|
+
template "full_bootstrap/main.tf", "terraform/bootstrap/main.tf"
|
21
|
+
copy_file "full_bootstrap/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl"
|
22
|
+
else
|
23
|
+
template "sandbox_bootstrap/main.tf", "terraform/bootstrap/main.tf"
|
24
|
+
copy_file "sandbox_bootstrap/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl"
|
25
|
+
remove_file "terraform/bootstrap/users.auto.tfvars"
|
26
|
+
remove_dir "terraform/sandbox_bot"
|
27
|
+
remove_file "terraform/production.tfvars"
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
31
|
def ignore_files
|
@@ -26,9 +35,10 @@ module RailsTemplate18f
|
|
26
35
|
# Terraform
|
27
36
|
.terraform.lock.hcl
|
28
37
|
**/.terraform/*
|
29
|
-
secrets
|
38
|
+
secrets.*.tfvars
|
30
39
|
terraform.tfstate
|
31
40
|
terraform.tfstate.backup
|
41
|
+
terraform/dist
|
32
42
|
EOM
|
33
43
|
end
|
34
44
|
end
|
@@ -36,7 +46,6 @@ module RailsTemplate18f
|
|
36
46
|
def update_readme
|
37
47
|
gsub_file "README.md", /^(### Automatic linting)\s*$/, '\1 and terraform formatting'
|
38
48
|
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
49
|
end
|
41
50
|
|
42
51
|
def install_githook
|
@@ -59,6 +59,13 @@ module RailsTemplate18f
|
|
59
59
|
Dir.exist? file_path("doc/compliance/oscal")
|
60
60
|
end
|
61
61
|
|
62
|
+
def copy_remote_oscal_component(component_name, cd_url)
|
63
|
+
get cd_url, File.join(oscal_component_path, component_name, "component-definition.json")
|
64
|
+
if oscal_dir_exists?
|
65
|
+
insert_into_file "doc/compliance/oscal/trestle-config.yaml", " - #{component_name}\n"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
62
69
|
def copy_oscal_component(component_name)
|
63
70
|
template "oscal/component-definitions/#{component_name}/component-definition.json",
|
64
71
|
File.join(oscal_component_path, component_name, "component-definition.json")
|
@@ -4,6 +4,7 @@ module RailsTemplate18f
|
|
4
4
|
module Generators
|
5
5
|
module CloudGovOptions
|
6
6
|
extend ActiveSupport::Concern
|
7
|
+
include CloudGovParsing
|
7
8
|
|
8
9
|
included do
|
9
10
|
class_option :cg_org, desc: "cloud.gov organization name"
|
@@ -13,40 +14,22 @@ module RailsTemplate18f
|
|
13
14
|
|
14
15
|
private
|
15
16
|
|
17
|
+
def terraform_manage_spaces?
|
18
|
+
# when operating in sandbox-gsa we can't use many features that rely
|
19
|
+
# on being an OrgManager
|
20
|
+
cloud_gov_organization != "sandbox-gsa"
|
21
|
+
end
|
22
|
+
|
16
23
|
def cloud_gov_organization
|
17
|
-
|
18
|
-
return options[:cg_org]
|
19
|
-
elsif terraform_dir_exists?
|
20
|
-
staging_main = file_content("terraform/staging/main.tf")
|
21
|
-
if (matches = staging_main.match(/cf_org_name\s+= "(?<org_name>.*)"/))
|
22
|
-
return matches[:org_name]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
"TKTK-cloud.gov-org-name"
|
24
|
+
@cloud_gov_organization ||= (options[:cg_org].present? ? options[:cg_org] : super)
|
26
25
|
end
|
27
26
|
|
28
27
|
def cloud_gov_staging_space
|
29
|
-
|
30
|
-
return options[:cg_staging]
|
31
|
-
elsif terraform_dir_exists?
|
32
|
-
staging_main = file_content("terraform/staging/main.tf")
|
33
|
-
if (matches = staging_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
34
|
-
return matches[:space_name]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
"staging"
|
28
|
+
@cloud_gov_staging_space ||= (options[:cg_staging].present? ? options[:cg_staging] : super)
|
38
29
|
end
|
39
30
|
|
40
31
|
def cloud_gov_production_space
|
41
|
-
|
42
|
-
return options[:cg_prod]
|
43
|
-
elsif terraform_dir_exists?
|
44
|
-
prod_main = file_content("terraform/production/main.tf")
|
45
|
-
if (matches = prod_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
46
|
-
return matches[:space_name]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
"prod"
|
32
|
+
@cloud_gov_production_space ||= (options[:cg_prod].present? ? options[:cg_prod] : super)
|
50
33
|
end
|
51
34
|
end
|
52
35
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsTemplate18f
|
4
|
+
module Generators
|
5
|
+
module CloudGovParsing
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def cloud_gov_organization
|
11
|
+
if terraform_dir_exists?
|
12
|
+
main_tf = file_content("terraform/main.tf")
|
13
|
+
if (matches = main_tf.match(/cf_org_name\s+= "(?<org_name>.*)"/))
|
14
|
+
return matches[:org_name]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
"TKTK-cloud.gov-org-name"
|
18
|
+
end
|
19
|
+
|
20
|
+
def cloud_gov_staging_space
|
21
|
+
if terraform_dir_exists?
|
22
|
+
staging_vars = file_content("terraform/staging.tfvars")
|
23
|
+
if (matches = staging_vars.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
24
|
+
return matches[:space_name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
"staging"
|
28
|
+
end
|
29
|
+
|
30
|
+
def cloud_gov_production_space
|
31
|
+
if terraform_dir_exists?
|
32
|
+
production_vars = file_content("terraform/production.tfvars")
|
33
|
+
if (matches = production_vars.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
34
|
+
return matches[:space_name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
"production"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|