Skip to content

Commit 047fd36

Browse files
feat: toggleable backstage
1 parent 6fe3f75 commit 047fd36

40 files changed

+929
-736
lines changed

.github/workflows/ci.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install terraform-docs
2121
run: |
2222
WORK_DIR=$(mktemp -d)
23-
curl -Lo ${WORK_DIR}/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-$(uname)-amd64.tar.gz
23+
curl -Lo ${WORK_DIR}/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.18.0/terraform-docs-v0.18.0-$(uname)-amd64.tar.gz
2424
cd ${WORK_DIR}
2525
tar -xzf terraform-docs.tar.gz
2626
chmod +x terraform-docs
@@ -31,11 +31,11 @@ jobs:
3131
- name: Check git diff is clean (all files generated should be committed)
3232
run: git diff --exit-code
3333

34-
- name: Terraform Format Check
35-
run: make fmt-check
36-
37-
- name: Stub Github App credentials (required for validation)
38-
run: cd ./examples/with-backstage && STUB_FILE=1 node create-gh-app/index.js
34+
- uses: terraform-linters/setup-tflint@v4
35+
with:
36+
tflint_version: v0.51.1
37+
- name: Terraform Lint
38+
run: make lint
3939

4040
- name: Terraform Validate
4141
run: make validate

.tflint.hcl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugin "terraform" {
2+
enabled = true
3+
preset = "recommended"
4+
}
5+
6+
plugin "google" {
7+
enabled = true
8+
version = "0.29.0"
9+
source = "github.com/terraform-linters/tflint-ruleset-google"
10+
}

Makefile

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
TF_DIRS = $(patsubst %/main.tf, %, $(shell find . -type d -name .terraform -prune -o -name 'main.tf' -print))
22
VALIDATE_TF_DIRS = $(addprefix validate-,$(TF_DIRS))
3+
LINT_TF_DIRS = $(addprefix lint-,$(TF_DIRS))
4+
DOCS_TF_DIRS = $(addprefix docs-,$(TF_DIRS))
5+
6+
# Generate docs for a terraform directories
7+
$(DOCS_TF_DIRS): docs-%:
8+
@echo "Docs $*"
9+
terraform-docs --config docs/.terraform-docs.yaml $*
10+
terraform-docs --config docs/.terraform-docs-example.yaml $*
311

412
# Generate docs
513
.PHONY: docs
6-
docs:
7-
# terraform-docs --lockfile=false ./modules/base
8-
terraform-docs --config docs/.terraform-docs.yaml .
9-
terraform-docs --config docs/.terraform-docs-example.yaml .
10-
terraform-docs --config docs/.terraform-docs.yaml ./examples/with-backstage
11-
terraform-docs --config docs/.terraform-docs-example.yaml ./examples/with-backstage
14+
docs: $(DOCS_TF_DIRS)
15+
@echo "All docs generated"
1216

1317
# Format all terraform files
1418
fmt:
@@ -27,3 +31,16 @@ $(VALIDATE_TF_DIRS): validate-%:
2731
# Validate all terraform directories
2832
validate: $(VALIDATE_TF_DIRS)
2933
@echo "All validated"
34+
35+
# Lint a terraform directories
36+
$(LINT_TF_DIRS): lint-%:
37+
@echo "Lint $*"
38+
tflint --config "$(PWD)/.tflint.hcl" --chdir="$*"
39+
40+
# Initialize tflint
41+
lint-init:
42+
tflint --init
43+
44+
# Lint all terraform directories
45+
lint: lint-init $(LINT_TF_DIRS) fmt-check
46+
@echo "All linted"

README.md

+120-47
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Humanitec Google Cloud Reference Architecture Implementation
2+
>
23
> TL;DR
34
>
45
>Skip the theory? Go [here](#how-to-spin-up-your-humanitec-google-cloud-reference-architecture-implementation) to spin up your Humanitec Google Cloud Reference Architecture Implementation.
@@ -19,33 +20,34 @@ When McKinsey originally [published the reference architecture](https://youtu.be
1920

2021
![Google Cloud reference architecture Humanitec](docs/images/Reference-Architecture-Google-Cloud-Humanitec.png)
2122

22-
### Developer Control Plane
23+
### Developer Control Plane
2324

2425
This plane is the primary configuration layer and interaction point for the platform users. It harbors the following components:
2526

2627
* A **Version Control System**. GitHub is a prominent example, but this can be any system that contains two types of repositories:
27-
* Application Source Code
28-
* Platform Source Code, e.g. using Terraform
28+
* Application Source Code
29+
* Platform Source Code, e.g. using Terraform
2930
* **Workload specifications**. The reference architecture uses [Score](https://developer.humanitec.com/score/overview/).
3031
* A **portal** for developers to interact with. It can be the Humanitec Portal, but you might also use [Backstage](https://backstage.io/) or any other portal on the market.
3132

32-
### Integration and Delivery Plane
33+
### Integration and Delivery Plane
3334

3435
This plane is about building and storing the image, creating app and infra configs from the abstractions provided by the developers, and deploying the final state. It’s where the domains of developers and platform engineers meet.
3536

3637
This plane usually contains four different tools:
38+
3739
* A **CI pipeline**. It can be Github Actions or any CI tooling on the market.
3840
* The **image registry** holding your container images. Again, this can be any registry on the market.
3941
* An **orchestrator** which in our example, is the Humanitec Platform Orchestrator.
4042
* The **CD system**, which can be the Platform Orchestrator’s deployment pipeline capabilities — an external system triggered by the Orchestrator using a webhook, or a setup in tandem with GitOps operators like ArgoCD.
4143

42-
### Monitoring and Logging Plane
44+
### Monitoring and Logging Plane
4345

4446
The integration of monitoring and logging systems varies greatly depending on the system. This plane however is not a focus of the reference architecture.
4547

46-
### Security Plane
48+
### Security Plane
4749

48-
The security plane of the reference architecture is focused on the secrets management system. The secrets manager stores configuration information such as database passwords, API keys, or TLS certificates needed by an Application at runtime. It allows the Platform Orchestrator to reference the secrets and inject them into the Workloads dynamically. You can learn more about secrets management and integration with other secrets management [here](https://developer.humanitec.com/platform-orchestrator/security/overview).
50+
The security plane of the reference architecture is focused on the secrets management system. The secrets manager stores configuration information such as database passwords, API keys, or TLS certificates needed by an Application at runtime. It allows the Platform Orchestrator to reference the secrets and inject them into the Workloads dynamically. You can learn more about secrets management and integration with other secrets management [here](https://developer.humanitec.com/platform-orchestrator/security/overview).
4951

5052
The reference architecture sample implementations use the secrets store attached to the Humanitec SaaS system.
5153

@@ -54,22 +56,19 @@ The reference architecture sample implementations use the secrets store attached
5456
This plane is where the actual infrastructure exists including clusters, databases, storage, or DNS services. The configuration of the Resources is managed by the Platform Orchestrator which dynamically creates app and infrastructure configurations with every deployment and creates, updates, or deletes dependent Resources as required.
5557

5658
## How to spin up your Humanitec Google Cloud Reference Architecture Implementation
57-
This repo contains an implementation of part of the Humanitec Reference Architecture for an Internal Developer Platform.
58-
59-
To install an implementation containing add-ons, follow the separate README. We currently feature these add-ons:
6059

61-
* [Base layer plus Backstage](examples/with-backstage/)
60+
This repo contains an implementation of part of the Humanitec Reference Architecture for an Internal Developer Platform, including Backstage as optional Portal solution.
6261

6362
This repo covers the base layer of the implementation for Google Cloud (GCP).
6463

6564
By default, the following will be provisioned:
6665

67-
- VPC
68-
- GKE Autopilot Cluster
69-
- Google Service Account to access the cluster
70-
- Ingress NGINX in the cluster
71-
- Resource Definitions in Humanitec for:
72-
- Kubernetes Cluster
66+
* VPC
67+
* GKE Autopilot Cluster
68+
* Google Service Account to access the cluster
69+
* Ingress NGINX in the cluster
70+
* Resource Definitions in Humanitec for:
71+
* Kubernetes Cluster
7372

7473
### Prerequisites
7574

@@ -99,13 +98,13 @@ This reference architecture implementation uses Terraform. You will need to do t
9998

10099
For example:
101100

102-
```
101+
```shell
103102
export HUMANITEC_TOKEN="my-humanitec-api-token"
104103
```
105104

106105
5. Run terraform:
107106

108-
```
107+
```shell
109108
terraform init
110109
terraform plan
111110
terraform apply
@@ -130,46 +129,90 @@ There are many other optional inputs that can be set. The full list is described
130129
Check for the existence of key elements of the reference architecture. This is a subset of all elements only. For a complete list of what was installed, review the Terraform code.
131130

132131
1. Set the `HUMANITEC_ORG` environment variable to the ID of your Humanitec Organization (must be all lowercase):
133-
```bash
134-
export HUMANITEC_ORG="my-humanitec-org"
135-
```
132+
133+
```bash
134+
export HUMANITEC_ORG="my-humanitec-org"
135+
```
136136

137137
2. Verify the existence of the Resource Definition for the GKE cluster in your Humanitec Organization:
138-
```bash
139-
curl -s https://api.humanitec.io/orgs/${HUMANITEC_ORG}/resources/defs/htc-ref-arch-cluster \
140-
--header "Authorization: Bearer ${HUMANITEC_TOKEN}" \
141-
| jq .id,.type
142-
```
143-
This should output:
144-
```bash
145-
"htc-ref-arch-cluster"
146-
"k8s-cluster"
147-
```
138+
139+
```bash
140+
curl -s https://api.humanitec.io/orgs/${HUMANITEC_ORG}/resources/defs/htc-ref-arch-cluster \
141+
--header "Authorization: Bearer ${HUMANITEC_TOKEN}" \
142+
| jq .id,.type
143+
```
144+
145+
This should output:
146+
147+
```bash
148+
"htc-ref-arch-cluster"
149+
"k8s-cluster"
150+
```
148151

149152
3. Verify the existence of the newly created GKE cluster:
150153

151-
```bash
152-
gcloud container clusters list --filter "name=htc-ref-arch-cluster"
153-
```
154-
This should output cluster data like this:
155-
```bash
156-
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
157-
htc-ref-arch-cluster <your-region> xx.xx.xx-gke.xx xx.xx.xx.xx n2d-standard-4 xx.xx.xx-gke.xx 3 RUNNING
158-
```
154+
```bash
155+
gcloud container clusters list --filter "name=htc-ref-arch-cluster"
156+
```
157+
158+
This should output cluster data like this:
159+
160+
```bash
161+
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
162+
htc-ref-arch-cluster <your-region> xx.xx.xx-gke.xx xx.xx.xx.xx n2d-standard-4 xx.xx.xx-gke.xx 3 RUNNING
163+
```
164+
165+
### Enable a portal (optional)
166+
167+
#### Portal Prerequisites
168+
169+
Backstage requires a GitHub connection, which in turn needs:
170+
171+
* A GitHub organization and permission to create new repositories in it. Go to <https://github.com/account/organizations/new> to create a new org (the "Free" option is fine). Note: is has to be an organization, a free account is not sufficient.
172+
* Create a classic github personal access token with `repo`, `workflow`, `delete_repo` and `admin:org` scope [here](https://github.com/settings/tokens).
173+
* Set the `GITHUB_TOKEN` environment variable to your token.
174+
175+
```shell
176+
export GITHUB_TOKEN="my-github-token"
177+
```
178+
179+
* Set the `GITHUB_ORG_ID` environment variable to your GitHub organization ID.
180+
181+
```shell
182+
export GITHUB_ORG_ID="my-github-org-id"
183+
```
184+
185+
* Install the GitHub App for Backstage into your GitHub organization
186+
* Run `docker run --rm -it -e GITHUB_ORG_ID -v $(pwd):/pwd -p 127.0.0.1:3000:3000 ghcr.io/humanitec-architecture/create-gh-app` ([image source](https://github.com/humanitec-architecture/create-gh-app/)) and follow the instructions:
187+
* “All repositories” ~> Install
188+
* “Okay, [] was installed on the [] account.” ~> You can close the window and server.
189+
190+
#### Portal Usage
191+
192+
* Enable `with_backstage` inside your `terraform.tfvars` and configure the additional variables that a required for Backstage.
193+
* Perform another `terraform apply`
194+
195+
#### Verify portal setup
196+
197+
* [Fetch the DNS entry](https://developer.humanitec.com/score/getting-started/get-dns/) of the Humanitec Application `backstage`, Environment `development`.
198+
* Open the host in your browser.
199+
* Click the "Create" button and scaffold your first application.
159200

160201
### Cleaning up
161202

162203
Once you are finished with the reference architecture, you can remove all provisioned infrastructure and the resource definitions created in Humanitec with the following:
163204

164-
1. Ensure you are (still) logged in with `gcloud`.
205+
1. Delete all Humanitec Applications scaffolded using the Portal, if you used one, but not the `backstage` app itself.
206+
207+
2. Ensure you are (still) logged in with `gcloud`.
165208

166-
2. Ensure you still have the `HUMANITEC_TOKEN` environment variable set to an appropriate Humanitec API token with the `Administrator` role on the Humanitec Organization.
209+
3. Ensure you still have the `HUMANITEC_TOKEN` environment variable set to an appropriate Humanitec API token with the `Administrator` role on the Humanitec Organization.
167210

168211
You can verify this in the UI if you log in with an Administrator user and go to Resource Management, and check the "Usage" of each resource definition with the prefix set in `humanitec_prefix` - by default this is `htc-ref-arch-`.
169212

170-
3. Run terraform:
213+
4. Run terraform:
171214

172-
```
215+
```shell
173216
terraform destroy
174217
```
175218

@@ -180,31 +223,63 @@ Once you are finished with the reference architecture, you can remove all provis
180223

181224
| Name | Version |
182225
|------|---------|
226+
| terraform | >= 1.0.0 |
183227
| terraform | >= 1.3.0 |
228+
| github | ~> 5.38 |
229+
| google | ~> 5.1 |
230+
| helm | ~> 2.12 |
231+
| humanitec | ~> 1.0 |
232+
| kubernetes | ~> 2.25 |
233+
| random | ~> 3.5 |
234+
235+
### Providers
236+
237+
| Name | Version |
238+
|------|---------|
184239
| google | ~> 5.1 |
185240
| humanitec | ~> 1.0 |
241+
| local | n/a |
242+
| random | ~> 3.5 |
186243

187244
### Modules
188245

189246
| Name | Source | Version |
190247
|------|--------|---------|
191248
| base | ./modules/base | n/a |
249+
| github | ./modules/github | n/a |
250+
| github\_app | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-12//modules/github-app |
251+
| portal\_backstage | ./modules/portal-backstage | n/a |
252+
253+
### Resources
254+
255+
| Name | Type |
256+
|------|------|
257+
| [google_storage_bucket.terraform_state](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket) | resource |
258+
| [humanitec_service_user_token.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/service_user_token) | resource |
259+
| [humanitec_user.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/user) | resource |
260+
| [local_file.terraform_backend_config](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
261+
| [random_id.bucket_prefix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
192262

193263
### Inputs
194264

195265
| Name | Description | Type | Default | Required |
196266
|------|-------------|------|---------|:--------:|
197-
| humanitec\_org\_id | ID of the Humanitec Organization to associate resources with. | `string` | n/a | yes |
267+
| gar\_repository\_location | Location of the Google Artifact Registry repository, | `string` | n/a | yes |
198268
| project\_id | GCP Project ID to provision resources in. | `string` | n/a | yes |
199269
| region | GCP Region to provision resources in. | `string` | n/a | yes |
200270
| environment | The environment to associate the reference architecture with. | `string` | `null` | no |
201271
| environment\_type | The environment type to associate the reference architecture with. | `string` | `"development"` | no |
272+
| gar\_repository\_id | Google Artifact Registry repository ID. | `string` | `"htc-ref-arch"` | no |
273+
| github\_org\_id | GitHub org id (required for Backstage) | `string` | `null` | no |
274+
| humanitec\_org\_id | Humanitec Organization ID (required for Backstage) | `string` | `null` | no |
202275
| humanitec\_prefix | A prefix that will be attached to all IDs created in Humanitec. | `string` | `"htc-ref-arch-"` | no |
276+
| with\_backstage | Deploy Backstage | `bool` | `false` | no |
203277
<!-- END_TF_DOCS -->
204278

205279
## Learn more
206280

207281
Expand your knowledge by heading over to our learning path, and discover how to:
282+
208283
* Deploy the Humanitec reference architecture using a cloud provider of your choice
209284
* Deploy and manage Applications using the Humanitec Platform Orchestrator and Score
210285
* Provision additional Resources and connect to them
@@ -227,5 +302,3 @@ Expand your knowledge by heading over to our learning path, and discover how to:
227302
* [Resource management theory](https://developer.humanitec.com/training/master-your-internal-developer-platform/resource-management-theory/)
228303
* [Tutorial: Provision a Redis cluster on AWS using Terraform](https://developer.humanitec.com/training/master-your-internal-developer-platform/provision-redis-aws/)
229304
* [Tutorial: Update Resource Definitions for related Applications](https://developer.humanitec.com/training/master-your-internal-developer-platform/update-resource-definitions-for-related-applications/)
230-
231-

0 commit comments

Comments
 (0)