rails_template_18f 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +82 -69
- data/lib/generators/rails_template18f/auditree/auditree_generator.rb +2 -2
- data/lib/generators/rails_template18f/circleci/templates/circleci/config.yml.tt +6 -2
- data/lib/generators/rails_template18f/github_actions/templates/github/dependabot.yml.tt +16 -0
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml +4 -1
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml +4 -1
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-production.yml +4 -1
- data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-staging.yml +4 -1
- data/lib/generators/rails_template18f/gitlab_ci/gitlab_ci_generator.rb +9 -9
- data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/{node.yml.tt → node.yml} +1 -1
- data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/rails.yml +11 -18
- data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab-ci.yml.tt +81 -154
- data/lib/generators/rails_template18f/public_egress/public_egress_generator.rb +1 -1
- data/lib/generators/rails_template18f/terraform/templates/gitlab_bootstrap/apply.sh +4 -4
- data/lib/generators/rails_template18f/terraform/templates/gitlab_bootstrap/main.tf.tt +42 -26
- data/lib/generators/rails_template18f/terraform/templates/gitlab_bootstrap/setup_shadowenv.sh +4 -2
- data/lib/generators/rails_template18f/terraform/templates/s3_bootstrap/full/main.tf.tt +6 -19
- data/lib/generators/rails_template18f/terraform/templates/s3_bootstrap/sandbox/main.tf.tt +5 -18
- data/lib/generators/rails_template18f/terraform/templates/terraform/README.md.tt +4 -4
- data/lib/generators/rails_template18f/terraform/templates/terraform/app.tf.tt +6 -6
- data/lib/generators/rails_template18f/terraform/templates/terraform/main.tf.tt +15 -13
- data/lib/generators/rails_template18f/terraform/templates/terraform/{production.tfvars.tt → production.env.tfvars.tt} +0 -1
- data/lib/generators/rails_template18f/terraform/templates/terraform/providers.tf.tt +5 -1
- data/lib/generators/rails_template18f/terraform/templates/terraform/{staging.tfvars.tt → staging.env.tfvars.tt} +1 -2
- data/lib/generators/rails_template18f/terraform/templates/terraform/terraform.sh.tt +15 -6
- data/lib/generators/rails_template18f/terraform/templates/terraform/variables.tf.tt +9 -5
- data/lib/generators/rails_template18f/terraform/terraform_generator.rb +2 -1
- data/lib/rails_template18f/generators/cloud_gov_parsing.rb +2 -2
- data/lib/rails_template18f/version.rb +1 -1
- data/template.rb +1 -1
- data/templates/README.md.tt +1 -1
- metadata +5 -7
- data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/terraform.yml +0 -33
- data/lib/generators/rails_template18f/terraform/templates/gitlab_bootstrap/bot_secrets.tftpl +0 -5
|
@@ -1,42 +1,94 @@
|
|
|
1
1
|
# Note that environment variables can be set in several places
|
|
2
2
|
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
|
3
|
+
spec:
|
|
4
|
+
inputs:
|
|
5
|
+
enable-staging-deploy:
|
|
6
|
+
type: boolean
|
|
7
|
+
default: true
|
|
8
|
+
description: "Set to false for scheduled pipelines"
|
|
9
|
+
disable-tflint:
|
|
10
|
+
type: boolean
|
|
11
|
+
default: false
|
|
12
|
+
description: "Set to true for scheduled pipelines"
|
|
13
|
+
enable-tf-fmt:
|
|
14
|
+
type: boolean
|
|
15
|
+
default: true
|
|
16
|
+
description: "Set to false for scheduled pipelines"
|
|
17
|
+
---
|
|
3
18
|
|
|
4
19
|
workflow:
|
|
5
20
|
rules:
|
|
6
21
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
|
22
|
+
- if: $CI_PIPELINE_SOURCE == 'web'
|
|
7
23
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
8
|
-
- if: $
|
|
24
|
+
- if: $CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+$/
|
|
9
25
|
|
|
10
26
|
stages:
|
|
11
27
|
- build
|
|
12
28
|
- test
|
|
13
|
-
-
|
|
14
|
-
-
|
|
29
|
+
- publish
|
|
30
|
+
- infra
|
|
31
|
+
- dast
|
|
32
|
+
- infra-prod
|
|
15
33
|
|
|
16
34
|
variables:
|
|
17
35
|
POSTGRES_DB: <%= app_name %>_test
|
|
18
36
|
POSTGRES_PASSWORD: not-actually-secret
|
|
19
37
|
POSTGRES_VERSION: <%= postgres_version %>
|
|
20
38
|
RUBY_VERSION: <%= RUBY_VERSION %>
|
|
39
|
+
NODE_MAJOR_VERSION: <%= node_major %>
|
|
40
|
+
CF_API_URL: https://api.fr.cloud.gov
|
|
41
|
+
TF_VAR_cf_user: $CF_USER
|
|
42
|
+
TF_VAR_rails_master_key: $RAILS_MASTER_KEY
|
|
21
43
|
|
|
22
44
|
include:
|
|
23
45
|
- local: ".gitlab/ruby.yml"
|
|
24
46
|
- local: ".gitlab/node.yml"
|
|
25
47
|
- local: ".gitlab/rails.yml"
|
|
26
|
-
-
|
|
48
|
+
- template: Jobs/SAST.gitlab-ci.yml
|
|
49
|
+
- template: Jobs/SAST-IaC.gitlab-ci.yml
|
|
50
|
+
- template: Security/DAST.gitlab-ci.yml
|
|
51
|
+
- template: Jobs/Dependency-Scanning.latest.gitlab-ci.yml
|
|
52
|
+
- template: Jobs/Secret-Detection.gitlab-ci.yml
|
|
53
|
+
- component: $CI_SERVER_FQDN/components/terraform/gitlab-ci-terraform@8
|
|
54
|
+
inputs:
|
|
55
|
+
project-dir: terraform
|
|
56
|
+
fmt-enabled: $[[ inputs.enable-tf-fmt ]]
|
|
57
|
+
tflint-disabled: $[[ inputs.disable-tflint ]]
|
|
58
|
+
validate-enabled: true
|
|
59
|
+
review-enabled: true
|
|
60
|
+
review-autostop-duration: "1 week"
|
|
61
|
+
staging-enabled: $[[ inputs.enable-staging-deploy ]]
|
|
62
|
+
prod-enabled: false # Switch to true when your project is ready for prod deploys
|
|
63
|
+
prod-plan-enabled: true
|
|
64
|
+
|
|
65
|
+
check-tag-on-main:
|
|
66
|
+
stage: .pre
|
|
67
|
+
variables:
|
|
68
|
+
GIT_STRATEGY: clone
|
|
69
|
+
GIT_DEPTH: 0
|
|
70
|
+
script:
|
|
71
|
+
- git branch -r --contains "$CI_COMMIT_TAG" | grep "^\s*origin/${CI_DEFAULT_BRANCH}\$"
|
|
72
|
+
rules:
|
|
73
|
+
- if: $CI_COMMIT_TAG
|
|
74
|
+
|
|
75
|
+
tf-review:
|
|
76
|
+
environment:
|
|
77
|
+
url: "https://<%= app_name.tr("_", "-") %>-${CI_ENVIRONMENT_SLUG}.app.cloud.gov"
|
|
78
|
+
on_stop: tf-destroy-review
|
|
27
79
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
80
|
+
tf-staging:
|
|
81
|
+
environment:
|
|
82
|
+
url: "https://<%= app_name.tr("_", "-") %>-${CI_ENVIRONMENT_SLUG}.app.cloud.gov"
|
|
83
|
+
on_stop: tf-destroy-staging
|
|
84
|
+
|
|
85
|
+
tf-production:
|
|
86
|
+
environment:
|
|
87
|
+
url: "https://<%= app_name.tr("_", "-") %>-${CI_ENVIRONMENT_SLUG}.app.cloud.gov"
|
|
34
88
|
|
|
35
89
|
build-project:
|
|
36
90
|
stage: build
|
|
37
91
|
extends: [.cache-dependencies, .setup-languages]
|
|
38
|
-
cache:
|
|
39
|
-
policy: pull-push
|
|
40
92
|
script:
|
|
41
93
|
- !reference [.bundle-install]
|
|
42
94
|
- !reference [.yarn-install]
|
|
@@ -49,31 +101,9 @@ build-project:
|
|
|
49
101
|
rules:
|
|
50
102
|
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
51
103
|
|
|
52
|
-
brakeman-scan:
|
|
53
|
-
stage: test
|
|
54
|
-
script:
|
|
55
|
-
- bin/brakeman --no-pager --ensure-ignore-notes -f sarif -o output.sarif.json
|
|
56
|
-
artifacts:
|
|
57
|
-
when: always
|
|
58
|
-
expose_as: "Brakeman results"
|
|
59
|
-
paths:
|
|
60
|
-
- output.sarif.json
|
|
61
|
-
|
|
62
|
-
dependency_scanning:
|
|
63
|
-
stage: test
|
|
64
|
-
extends: .setup-languages
|
|
65
|
-
script:
|
|
66
|
-
- bin/rake bundler:audit
|
|
67
|
-
- bin/rake yarn:audit
|
|
68
|
-
- gem install cyclonedx-ruby
|
|
69
|
-
- cyclonedx-ruby -p . -o ruby_bom.xml
|
|
70
|
-
artifacts:
|
|
71
|
-
expose_as: "Ruby SBOM"
|
|
72
|
-
paths:
|
|
73
|
-
- ruby_bom.xml
|
|
74
|
-
|
|
75
104
|
rspec:
|
|
76
105
|
stage: test
|
|
106
|
+
needs: ["build-project"]
|
|
77
107
|
extends: .setup-project
|
|
78
108
|
script:
|
|
79
109
|
- bundle exec rspec
|
|
@@ -81,7 +111,8 @@ rspec:
|
|
|
81
111
|
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
82
112
|
|
|
83
113
|
pa11y_scan:
|
|
84
|
-
stage:
|
|
114
|
+
stage: test
|
|
115
|
+
needs: ["build-project"]
|
|
85
116
|
extends: .run-server
|
|
86
117
|
script:
|
|
87
118
|
- !reference [.install-puppet-deps]
|
|
@@ -89,125 +120,21 @@ pa11y_scan:
|
|
|
89
120
|
rules:
|
|
90
121
|
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
91
122
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
rules:
|
|
97
|
-
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
98
|
-
|
|
99
|
-
owasp_daily_scan:
|
|
100
|
-
extends: .owasp:setup
|
|
101
|
-
script:
|
|
102
|
-
- /zap/zap-full-scan.py -t http://localhost:3000 -c zap.conf -I -r zap_report.html
|
|
103
|
-
rules:
|
|
104
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
105
|
-
|
|
106
|
-
terraform:fmt:
|
|
107
|
-
stage: test
|
|
108
|
-
extends: .terraform:setup
|
|
109
|
-
script:
|
|
110
|
-
- terraform fmt -check -recursive .
|
|
111
|
-
|
|
112
|
-
terraform:validate:
|
|
113
|
-
stage: test
|
|
114
|
-
extends: .terraform:setup
|
|
115
|
-
script:
|
|
116
|
-
- terraform validate
|
|
117
|
-
|
|
118
|
-
terraform:assets:staging:
|
|
119
|
-
extends: .assets:builder
|
|
120
|
-
cache:
|
|
121
|
-
- !reference [.cache-dependencies, cache]
|
|
122
|
-
- key: staging-assets
|
|
123
|
-
unprotect: true
|
|
124
|
-
paths:
|
|
125
|
-
- public/assets
|
|
126
|
-
- app/assets/builds
|
|
127
|
-
policy: $CACHE_POLICY
|
|
128
|
-
variables:
|
|
129
|
-
RAILS_ENV: staging
|
|
130
|
-
rules:
|
|
131
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
132
|
-
when: never
|
|
133
|
-
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
134
|
-
variables:
|
|
135
|
-
CACHE_POLICY: pull-push
|
|
136
|
-
- variables:
|
|
137
|
-
CACHE_POLICY: pull
|
|
138
|
-
<% if terraform_manage_spaces? %>
|
|
139
|
-
terraform:assets:production:
|
|
140
|
-
extends: .assets:builder
|
|
141
|
-
cache:
|
|
142
|
-
- !reference [.cache-dependencies, cache]
|
|
143
|
-
- key: production-assets
|
|
144
|
-
paths:
|
|
145
|
-
- public/assets
|
|
146
|
-
- app/assets/builds
|
|
147
|
-
policy: $CACHE_POLICY
|
|
123
|
+
dast:
|
|
124
|
+
environment:
|
|
125
|
+
name: $DAST_ENVIRONMENT_NAME
|
|
126
|
+
action: access
|
|
148
127
|
variables:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
CACHE_POLICY: pull-push
|
|
154
|
-
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
155
|
-
variables:
|
|
156
|
-
CACHE_POLICY: pull
|
|
157
|
-
<% end %>
|
|
158
|
-
terraform:plan:staging:
|
|
159
|
-
extends:
|
|
160
|
-
- .terraform:setup
|
|
161
|
-
- .terraform:variables:staging
|
|
162
|
-
needs: ["terraform:assets:staging"]
|
|
128
|
+
DAST_TARGET_URL: "https://<%= app_name.tr("_", "-") %>-${CI_ENVIRONMENT_SLUG}.app.cloud.gov"
|
|
129
|
+
DAST_IMAGE_SUFFIX: "-fips"
|
|
130
|
+
tags:
|
|
131
|
+
- unsafe_egress
|
|
163
132
|
script:
|
|
164
|
-
-
|
|
165
|
-
- terraform plan -out=staging_plan.out -var-file=staging.tfvars -var rails_master_key=$RAILS_MASTER_KEY -var cf_user=$CF_USERNAME
|
|
166
|
-
artifacts:
|
|
167
|
-
paths:
|
|
168
|
-
- terraform/staging_plan.out
|
|
169
|
-
- terraform/dist
|
|
170
|
-
|
|
171
|
-
terraform:apply:staging:
|
|
172
|
-
extends:
|
|
173
|
-
- .terraform:setup
|
|
174
|
-
- .terraform:variables:staging
|
|
175
|
-
needs:
|
|
176
|
-
- terraform:plan:staging
|
|
177
|
-
- terraform:assets:staging
|
|
178
|
-
script:
|
|
179
|
-
- apk add zip
|
|
180
|
-
- terraform apply -var-file=staging.tfvars -var rails_master_key=$RAILS_MASTER_KEY -var cf_user=$CF_USERNAME staging_plan.out
|
|
133
|
+
- /browserker/entrypoint.sh /analyze
|
|
181
134
|
rules:
|
|
182
|
-
- if: $CI_PIPELINE_SOURCE == "
|
|
183
|
-
|
|
135
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
136
|
+
variables:
|
|
137
|
+
DAST_ENVIRONMENT_NAME: "review/$CI_COMMIT_REF_NAME"
|
|
184
138
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
extends:
|
|
188
|
-
- .terraform:setup
|
|
189
|
-
- .terraform:variables:production
|
|
190
|
-
needs: ["terraform:assets:production"]
|
|
191
|
-
script:
|
|
192
|
-
- apk add zip
|
|
193
|
-
- terraform plan -out=production_plan.out -var-file=production.tfvars -var rails_master_key=$PRODUCTION_RAILS_MASTER_KEY -var cf_user=$CF_USERNAME
|
|
194
|
-
artifacts:
|
|
195
|
-
paths:
|
|
196
|
-
- terraform/production_plan.out
|
|
197
|
-
- terraform/dist
|
|
198
|
-
|
|
199
|
-
terraform:apply:production:
|
|
200
|
-
extends:
|
|
201
|
-
- .terraform:setup
|
|
202
|
-
- .terraform:variables:production
|
|
203
|
-
needs:
|
|
204
|
-
- terraform:plan:production
|
|
205
|
-
- terraform:assets:production
|
|
206
|
-
script:
|
|
207
|
-
- apk add zip
|
|
208
|
-
- terraform apply -var-file=production.tfvars -var rails_master_key=$PRODUCTION_RAILS_MASTER_KEY -var cf_user=$CF_USERNAME production_plan.out
|
|
209
|
-
rules:
|
|
210
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
211
|
-
when: never
|
|
212
|
-
- if: $CI_COMMIT_BRANCH == "production"
|
|
213
|
-
when: manual<% end %>
|
|
139
|
+
variables:
|
|
140
|
+
DAST_ENVIRONMENT_NAME: "staging"
|
|
@@ -88,7 +88,7 @@ EOB
|
|
|
88
88
|
### Public Egress Proxy
|
|
89
89
|
|
|
90
90
|
Traffic to be delivered to the public internet must be proxied through the [cg-egress-proxy](https://github.com/GSA-TTS/cg-egress-proxy) app. Hostnames that the app should be able to
|
|
91
|
-
reach should be added to the `egress_allowlist` terraform variable in `terraform/production.tfvars` and `terraform/staging.tfvars`
|
|
91
|
+
reach should be added to the `egress_allowlist` terraform variable in `terraform/production.env.tfvars` and `terraform/staging.env.tfvars`
|
|
92
92
|
|
|
93
93
|
See the [ruby troubleshooting doc](https://github.com/GSA-TTS/cg-egress-proxy/blob/main/docs/ruby.md) first if you have any problems making outbound connections through the proxy.
|
|
94
94
|
|
|
@@ -6,8 +6,8 @@ then
|
|
|
6
6
|
exit 1
|
|
7
7
|
fi
|
|
8
8
|
|
|
9
|
-
if [ -z "$GITLAB_PROJECT_ID" ] || [ -z "$
|
|
10
|
-
echo "GITLAB_PROJECT_ID or
|
|
9
|
+
if [ -z "$GITLAB_PROJECT_ID" ] || [ -z "$GITLAB_BASE_URL" ]; then
|
|
10
|
+
echo "GITLAB_PROJECT_ID or GITLAB_BASE_URL has not been set. Run ./setup_shadowenv.sh first"
|
|
11
11
|
exit 1
|
|
12
12
|
fi
|
|
13
13
|
|
|
@@ -16,10 +16,10 @@ set -e
|
|
|
16
16
|
# ensure we're logged in via cli
|
|
17
17
|
cf spaces &> /dev/null || cf login -a api.fr.cloud.gov --sso
|
|
18
18
|
|
|
19
|
-
tf_state_address="
|
|
19
|
+
tf_state_address="$GITLAB_BASE_URL/projects/$GITLAB_PROJECT_ID/terraform/state/bootstrap"
|
|
20
20
|
terraform init \
|
|
21
21
|
-backend-config="address=$tf_state_address" \
|
|
22
22
|
-backend-config="lock_address=$tf_state_address/lock" \
|
|
23
23
|
-backend-config="unlock_address=$tf_state_address/lock"
|
|
24
24
|
|
|
25
|
-
terraform apply "$@"
|
|
25
|
+
terraform apply -var project_id="$GITLAB_PROJECT_ID" "$@"
|
|
@@ -3,7 +3,11 @@ terraform {
|
|
|
3
3
|
required_providers {
|
|
4
4
|
cloudfoundry = {
|
|
5
5
|
source = "cloudfoundry/cloudfoundry"
|
|
6
|
-
version = "~> 1.
|
|
6
|
+
version = "~> 1.10"
|
|
7
|
+
}
|
|
8
|
+
gitlab = {
|
|
9
|
+
source = "gitlabhq/gitlab"
|
|
10
|
+
version = "~> 18.5"
|
|
7
11
|
}
|
|
8
12
|
}
|
|
9
13
|
backend "http" {
|
|
@@ -14,6 +18,7 @@ terraform {
|
|
|
14
18
|
}
|
|
15
19
|
# empty config will let terraform borrow cf-cli's auth
|
|
16
20
|
provider "cloudfoundry" {}
|
|
21
|
+
provider "gitlab" {}
|
|
17
22
|
|
|
18
23
|
locals {
|
|
19
24
|
org_name = "<%= cloud_gov_organization %>"
|
|
@@ -23,10 +28,16 @@ locals {
|
|
|
23
28
|
data "cloudfoundry_org" "org" {
|
|
24
29
|
name = local.org_name
|
|
25
30
|
}
|
|
31
|
+
|
|
32
|
+
variable "project_id" {
|
|
33
|
+
type = number
|
|
34
|
+
description = "The GitLab project ID for this project"
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
<% if terraform_manage_spaces? %>
|
|
27
38
|
variable "terraform_users" {
|
|
28
39
|
type = set(string)
|
|
29
|
-
description = "The list of developer emails and service account usernames who should be
|
|
40
|
+
description = "The list of developer emails and service account usernames who should be able to update the service bot user"
|
|
30
41
|
|
|
31
42
|
validation {
|
|
32
43
|
condition = length(var.terraform_users) > 0
|
|
@@ -51,48 +62,53 @@ data "cloudfoundry_service_plans" "cg_service_account" {
|
|
|
51
62
|
name = "<%= terraform_manage_spaces? ? "space-auditor" : "space-deployer" %>"
|
|
52
63
|
service_offering_name = "cloud-gov-service-account"
|
|
53
64
|
}
|
|
54
|
-
locals {
|
|
55
|
-
sa_service_name = "<%= app_name %>-cicd-deployer"
|
|
56
|
-
sa_key_name = "cicd-deployer-access-key"
|
|
57
|
-
sa_bot_credentials = jsondecode(data.cloudfoundry_service_credential_binding.runner_sa_key.credential_bindings.0.credential_binding).credentials
|
|
58
|
-
sa_cf_username = nonsensitive(local.sa_bot_credentials.username)
|
|
59
|
-
sa_cf_password = local.sa_bot_credentials.password
|
|
60
|
-
}
|
|
61
65
|
resource "cloudfoundry_service_instance" "runner_service_account" {
|
|
62
|
-
name =
|
|
66
|
+
name = "<%= app_name %>-cicd-deployer"
|
|
63
67
|
type = "managed"
|
|
64
|
-
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans
|
|
68
|
+
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans[0].id<% if terraform_manage_spaces? %>
|
|
65
69
|
space = module.mgmt_space.space_id
|
|
66
70
|
depends_on = [module.mgmt_space]<% else %>
|
|
67
71
|
space = data.cloudfoundry_space.space.id<% end %>
|
|
68
72
|
}
|
|
69
73
|
resource "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
70
|
-
name =
|
|
74
|
+
name = "cicd-deployer-access-key"
|
|
71
75
|
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
|
72
76
|
type = "key"
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
locals {
|
|
79
|
+
sa_bot_credentials = jsondecode(cloudfoundry_service_credential_binding.runner_sa_key.credential_binding).credentials
|
|
80
|
+
sa_cf_username = nonsensitive(local.sa_bot_credentials.username)
|
|
81
|
+
sa_cf_password = local.sa_bot_credentials.password
|
|
78
82
|
}<% if terraform_manage_spaces? %>
|
|
79
83
|
data "cloudfoundry_user" "sa_user" {
|
|
80
84
|
name = local.sa_cf_username
|
|
81
85
|
}
|
|
82
86
|
resource "cloudfoundry_org_role" "sa_org_manager" {
|
|
83
|
-
user = data.cloudfoundry_user.sa_user.users
|
|
87
|
+
user = data.cloudfoundry_user.sa_user.users[0].id
|
|
84
88
|
type = "organization_manager"
|
|
85
89
|
org = data.cloudfoundry_org.org.id
|
|
86
90
|
}<% end %>
|
|
87
91
|
|
|
88
|
-
resource "
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
resource "gitlab_project_variable" "cf_user" {
|
|
93
|
+
project = var.project_id
|
|
94
|
+
key = "CF_USER"
|
|
95
|
+
value = local.sa_cf_username
|
|
96
|
+
protected = false
|
|
97
|
+
masked = false
|
|
98
|
+
hidden = false
|
|
99
|
+
raw = true
|
|
100
|
+
variable_type = "env_var"
|
|
101
|
+
description = "Set by terraform bootstrap module"
|
|
102
|
+
}
|
|
91
103
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
resource "gitlab_project_variable" "cf_password" {
|
|
105
|
+
project = var.project_id
|
|
106
|
+
key = "CF_PASSWORD"
|
|
107
|
+
value = local.sa_cf_password
|
|
108
|
+
protected = false
|
|
109
|
+
masked = true
|
|
110
|
+
hidden = true
|
|
111
|
+
raw = true
|
|
112
|
+
variable_type = "env_var"
|
|
113
|
+
description = "Set by terraform bootstrap module"
|
|
98
114
|
}
|
data/lib/generators/rails_template18f/terraform/templates/gitlab_bootstrap/setup_shadowenv.sh
CHANGED
|
@@ -19,7 +19,7 @@ prompt_ans() {
|
|
|
19
19
|
read -r -p "$prompt: " ans
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
prompt_ans "GitLab hostname" "${GITLAB_HOSTNAME:=
|
|
22
|
+
prompt_ans "GitLab hostname" "${GITLAB_HOSTNAME:=workshop.cloud.gov}"
|
|
23
23
|
if [ -n "$ans" ]; then
|
|
24
24
|
GITLAB_HOSTNAME="$ans"
|
|
25
25
|
fi
|
|
@@ -35,8 +35,9 @@ fi
|
|
|
35
35
|
|
|
36
36
|
cat <<EOF > ../.shadowenv.d/100_gitlab_project.lisp
|
|
37
37
|
(provide "gitlab-backend-config")
|
|
38
|
-
(env/set "GITLAB_HOSTNAME" "$GITLAB_HOSTNAME")
|
|
39
38
|
(env/set "GITLAB_PROJECT_ID" "$GITLAB_PROJECT_ID")
|
|
39
|
+
(env/set "GITLAB_HOSTNAME" "$GITLAB_HOSTNAME")
|
|
40
|
+
(env/set "GITLAB_BASE_URL" "https://${GITLAB_HOSTNAME}/api/v4")
|
|
40
41
|
EOF
|
|
41
42
|
|
|
42
43
|
prompt_ans "GitLab username" "$TF_HTTP_USERNAME"
|
|
@@ -56,4 +57,5 @@ cat <<EOF > ../.shadowenv.d/500_tf_backend_secrets.lisp
|
|
|
56
57
|
(provide "tf-backend-secrets")
|
|
57
58
|
(env/set "TF_HTTP_USERNAME" "$TF_HTTP_USERNAME")
|
|
58
59
|
(env/set "TF_HTTP_PASSWORD" "$TF_HTTP_PASSWORD")
|
|
60
|
+
(env/set "GITLAB_TOKEN" "$TF_HTTP_PASSWORD")
|
|
59
61
|
EOF
|
|
@@ -3,7 +3,7 @@ terraform {
|
|
|
3
3
|
required_providers {
|
|
4
4
|
cloudfoundry = {
|
|
5
5
|
source = "cloudfoundry/cloudfoundry"
|
|
6
|
-
version = "~> 1.
|
|
6
|
+
version = "~> 1.10"
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -59,7 +59,7 @@ data "cloudfoundry_service_plans" "cg_service_account" {
|
|
|
59
59
|
locals {
|
|
60
60
|
sa_service_name = "<%= app_name %>-cicd-deployer"
|
|
61
61
|
sa_key_name = "cicd-deployer-access-key"
|
|
62
|
-
sa_bot_credentials = jsondecode(
|
|
62
|
+
sa_bot_credentials = jsondecode(cloudfoundry_service_credential_binding.runner_sa_key.credential_binding).credentials
|
|
63
63
|
sa_cf_username = nonsensitive(local.sa_bot_credentials.username)
|
|
64
64
|
sa_cf_password = local.sa_bot_credentials.password
|
|
65
65
|
}
|
|
@@ -67,7 +67,7 @@ resource "cloudfoundry_service_instance" "runner_service_account" {
|
|
|
67
67
|
name = local.sa_service_name
|
|
68
68
|
type = "managed"
|
|
69
69
|
space = module.mgmt_space.space_id
|
|
70
|
-
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans
|
|
70
|
+
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans[0].id
|
|
71
71
|
depends_on = [module.mgmt_space]
|
|
72
72
|
}
|
|
73
73
|
resource "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
@@ -75,11 +75,6 @@ resource "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
|
75
75
|
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
|
76
76
|
type = "key"
|
|
77
77
|
}
|
|
78
|
-
data "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
79
|
-
name = local.sa_key_name
|
|
80
|
-
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
|
81
|
-
depends_on = [cloudfoundry_service_credential_binding.runner_sa_key]
|
|
82
|
-
}
|
|
83
78
|
data "cloudfoundry_org" "org" {
|
|
84
79
|
name = local.org_name
|
|
85
80
|
}
|
|
@@ -87,24 +82,16 @@ data "cloudfoundry_user" "sa_user" {
|
|
|
87
82
|
name = local.sa_cf_username
|
|
88
83
|
}
|
|
89
84
|
resource "cloudfoundry_org_role" "sa_org_manager" {
|
|
90
|
-
user = data.cloudfoundry_user.sa_user.users
|
|
85
|
+
user = data.cloudfoundry_user.sa_user.users[0].id
|
|
91
86
|
type = "organization_manager"
|
|
92
87
|
org = data.cloudfoundry_org.org.id
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
locals {
|
|
96
|
-
bucket_creds_key_name = "backend-state-bucket-creds"
|
|
97
|
-
}
|
|
98
90
|
resource "cloudfoundry_service_credential_binding" "bucket_creds" {
|
|
99
|
-
name =
|
|
91
|
+
name = "backend-state-bucket-creds"
|
|
100
92
|
service_instance = module.s3.bucket_id
|
|
101
93
|
type = "key"
|
|
102
94
|
}
|
|
103
|
-
data "cloudfoundry_service_credential_binding" "bucket_creds" {
|
|
104
|
-
name = local.bucket_creds_key_name
|
|
105
|
-
service_instance = module.s3.bucket_id
|
|
106
|
-
depends_on = [cloudfoundry_service_credential_binding.bucket_creds]
|
|
107
|
-
}
|
|
108
95
|
|
|
109
96
|
locals {
|
|
110
97
|
import_map = {
|
|
@@ -129,7 +116,7 @@ resource "local_file" "recreate_script" {
|
|
|
129
116
|
}
|
|
130
117
|
|
|
131
118
|
locals {
|
|
132
|
-
bucket_creds = jsondecode(
|
|
119
|
+
bucket_creds = jsondecode(cloudfoundry_service_credential_binding.bucket_creds.credential_binding).credentials
|
|
133
120
|
backend_config = templatefile("${path.module}/templates/backend_config.tftpl", { creds = local.bucket_creds })
|
|
134
121
|
}
|
|
135
122
|
resource "local_sensitive_file" "bucket_creds" {
|
|
@@ -3,7 +3,7 @@ terraform {
|
|
|
3
3
|
required_providers {
|
|
4
4
|
cloudfoundry = {
|
|
5
5
|
source = "cloudfoundry/cloudfoundry"
|
|
6
|
-
version = "~> 1.
|
|
6
|
+
version = "~> 1.10"
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -44,38 +44,25 @@ data "cloudfoundry_service_plans" "cg_service_account" {
|
|
|
44
44
|
locals {
|
|
45
45
|
sa_service_name = "<%= app_name %>-cicd-deployer"
|
|
46
46
|
sa_key_name = "cicd-deployer-access-key"
|
|
47
|
-
sa_bot_credentials = jsondecode(
|
|
47
|
+
sa_bot_credentials = jsondecode(cloudfoundry_service_credential_binding.runner_sa_key.credential_binding).credentials
|
|
48
48
|
}
|
|
49
49
|
resource "cloudfoundry_service_instance" "runner_service_account" {
|
|
50
50
|
name = local.sa_service_name
|
|
51
51
|
type = "managed"
|
|
52
52
|
space = data.cloudfoundry_space.space.id
|
|
53
|
-
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans
|
|
53
|
+
service_plan = data.cloudfoundry_service_plans.cg_service_account.service_plans[0].id
|
|
54
54
|
}
|
|
55
55
|
resource "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
56
56
|
name = local.sa_key_name
|
|
57
57
|
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
|
58
58
|
type = "key"
|
|
59
59
|
}
|
|
60
|
-
data "cloudfoundry_service_credential_binding" "runner_sa_key" {
|
|
61
|
-
name = local.sa_key_name
|
|
62
|
-
service_instance = cloudfoundry_service_instance.runner_service_account.id
|
|
63
|
-
depends_on = [cloudfoundry_service_credential_binding.runner_sa_key]
|
|
64
|
-
}
|
|
65
60
|
|
|
66
|
-
locals {
|
|
67
|
-
bucket_creds_key_name = "backend-state-bucket-creds"
|
|
68
|
-
}
|
|
69
61
|
resource "cloudfoundry_service_credential_binding" "bucket_creds" {
|
|
70
|
-
name =
|
|
62
|
+
name = "backend-state-bucket-creds"
|
|
71
63
|
service_instance = module.s3.bucket_id
|
|
72
64
|
type = "key"
|
|
73
65
|
}
|
|
74
|
-
data "cloudfoundry_service_credential_binding" "bucket_creds" {
|
|
75
|
-
name = local.bucket_creds_key_name
|
|
76
|
-
service_instance = module.s3.bucket_id
|
|
77
|
-
depends_on = [cloudfoundry_service_credential_binding.bucket_creds]
|
|
78
|
-
}
|
|
79
66
|
|
|
80
67
|
locals {
|
|
81
68
|
import_map = {
|
|
@@ -94,7 +81,7 @@ resource "local_file" "recreate_script" {
|
|
|
94
81
|
}
|
|
95
82
|
|
|
96
83
|
locals {
|
|
97
|
-
bucket_creds = jsondecode(
|
|
84
|
+
bucket_creds = jsondecode(cloudfoundry_service_credential_binding.bucket_creds.credential_binding).credentials
|
|
98
85
|
backend_config = templatefile("${path.module}/templates/backend_config.tftpl", { creds = local.bucket_creds })
|
|
99
86
|
}
|
|
100
87
|
resource "local_sensitive_file" "bucket_creds" {
|
|
@@ -59,8 +59,8 @@ These steps only need to be run once per project.
|
|
|
59
59
|
### Steps:
|
|
60
60
|
<% if use_gitlab_backend? %>
|
|
61
61
|
1. Run `./bootstrap/setup_shadowenv.sh`<% end %>
|
|
62
|
-
<% if terraform_manage_spaces? %>1. Create a new `sandbox-<NAME>.tfvars` file to hold variable values for your environment. A good starting point is copying `staging.tfvars` and editing it with your values
|
|
63
|
-
1. Add a `cf_user = "your.email@gsa.gov"` line to the `sandbox-<NAME>.tfvars` file<% end %>
|
|
62
|
+
<% if terraform_manage_spaces? %>1. Create a new `sandbox-<NAME>.env.tfvars` file to hold variable values for your environment. A good starting point is copying `staging.env.tfvars` and editing it with your values
|
|
63
|
+
1. Add a `cf_user = "your.email@gsa.gov"` line to the `sandbox-<NAME>.env.tfvars` file<% end %>
|
|
64
64
|
|
|
65
65
|
1. Run terraform plan with:
|
|
66
66
|
```bash
|
|
@@ -100,11 +100,11 @@ These steps only need to be run once per project.
|
|
|
100
100
|
|- providers.tf
|
|
101
101
|
|- terraform.sh
|
|
102
102
|
|- variables.tf
|
|
103
|
-
|- <env>.tfvars
|
|
103
|
+
|- <env>.env.tfvars
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
In the root module:
|
|
107
|
-
- `<env>.tfvars` is where to set variable values for the given environment name
|
|
107
|
+
- `<env>.env.tfvars` is where to set variable values for the given environment name
|
|
108
108
|
- `terraform.sh` Helper script to setup terraform to point to the correct state file, create a service account to run the root module, and apply the root module.
|
|
109
109
|
- `app.tf` defines the application resource and configuration
|
|
110
110
|
- `main.tf` defines the persistent infrastructure
|
|
@@ -15,8 +15,8 @@ data "archive_file" "src" {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
resource "cloudfoundry_app" "app" {
|
|
18
|
-
name = "${local.app_name}-${var.
|
|
19
|
-
space_name = var.cf_space_name
|
|
18
|
+
name = "${local.app_name}-${var.environment_slug}"
|
|
19
|
+
space_name = <% if terraform_manage_spaces? %>module.app_space.space_name<% else %>var.cf_space_name<% end %>
|
|
20
20
|
org_name = local.cf_org_name
|
|
21
21
|
|
|
22
22
|
path = data.archive_file.src.output_path
|
|
@@ -26,7 +26,7 @@ resource "cloudfoundry_app" "app" {
|
|
|
26
26
|
enable_ssh = var.allow_ssh
|
|
27
27
|
|
|
28
28
|
environment = {
|
|
29
|
-
RAILS_ENV = var.
|
|
29
|
+
RAILS_ENV = var.environment_type
|
|
30
30
|
RAILS_MASTER_KEY = var.rails_master_key
|
|
31
31
|
RAILS_LOG_TO_STDOUT = "true"
|
|
32
32
|
RAILS_SERVE_STATIC_FILES = "true"
|
|
@@ -44,9 +44,9 @@ resource "cloudfoundry_app" "app" {
|
|
|
44
44
|
]
|
|
45
45
|
|
|
46
46
|
service_bindings = [
|
|
47
|
-
<% if has_active_job? %> { service_instance = "${local.app_name}-redis-${var.
|
|
48
|
-
<% if has_active_storage? %> { service_instance = "${local.app_name}-s3-${var.
|
|
49
|
-
{ service_instance = "${local.app_name}-rds-${var.
|
|
47
|
+
<% if has_active_job? %> { service_instance = "${local.app_name}-redis-${var.environment_slug}" },<% end %>
|
|
48
|
+
<% if has_active_storage? %> { service_instance = "${local.app_name}-s3-${var.environment_slug}" },<% end %>
|
|
49
|
+
{ service_instance = "${local.app_name}-rds-${var.environment_slug}" }
|
|
50
50
|
]
|
|
51
51
|
|
|
52
52
|
depends_on = [
|