Skip to content

Commit e383304

Browse files
Merge pull request #15 from htc-demo-00-azure/toggleable-backstage
feat: toggleable backstage
2 parents 98e0596 + 6c7d29a commit e383304

30 files changed

+631
-744
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,22 @@ 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
2727
mv terraform-docs /usr/local/bin/terraform-docs
28-
2928
- name: Generate docs
3029
run: make docs
3130

3231
- name: Check git diff is clean (all files generated should be committed)
3332
run: git diff --exit-code
3433

35-
- name: Terraform Format Check
36-
run: make fmt-check
37-
38-
- name: Stub GitHub App credentials (required for validation)
39-
run: cd ./examples/with-backstage && STUB_FILE=1 node create-gh-app/index.js
40-
41-
- name: Terraform Validate
42-
run: make validate
43-
4434
- uses: terraform-linters/setup-tflint@v4
4535
with:
46-
tflint_version: v0.49.0
47-
48-
- name: Lint
36+
tflint_version: v0.51.1
37+
- name: Terraform Lint
4938
run: make lint
39+
40+
- name: Terraform Validate
41+
run: make validate

.tflint.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ plugin "terraform" {
55

66
plugin "azurerm" {
77
enabled = true
8-
version = "0.25.1"
8+
version = "0.26.0"
99
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
1010
}

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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))
33
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 $*
411

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

1417
# Format all terraform files
1518
fmt:
@@ -39,5 +42,5 @@ lint-init:
3942
tflint --init
4043

4144
# Lint all terraform directories
42-
lint: lint-init $(LINT_TF_DIRS)
45+
lint: lint-init $(LINT_TF_DIRS) fmt-check
4346
@echo "All linted"

README.md

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This plane is where the actual infrastructure exists including clusters, databas
5858

5959
## How to spin up your Humanitec Azure Reference Architecture
6060

61-
This repo contains an implementation of part of the Humanitec Reference Architecture for an Internal Developer Platform.
61+
This repo contains an implementation of part of the Humanitec Reference Architecture for an Internal Developer Platform, including Backstage as optional Portal solution.
6262

6363
This repo covers the base layer of the implementation for Azure.
6464

@@ -98,21 +98,21 @@ This reference architecture implementation uses Terraform. You will need to do t
9898

9999
For example:
100100

101-
```
101+
```shell
102102
export HUMANITEC_TOKEN="my-humanitec-api-token"
103103
```
104104

105105
5. Run terraform:
106106

107-
```
107+
```shell
108108
terraform init
109109
terraform plan
110110
terraform apply
111111
```
112112

113113
`terraform plan` and `apply` might output this message:
114114

115-
```
115+
```shell
116116
│ Warning: Argument is deprecated
117117
118118
│ with module.base.module.azure_aks.azurerm_kubernetes_cluster.main,
@@ -136,34 +136,34 @@ Check for the existence of key elements of the reference architecture. This is a
136136

137137
1. Set the `HUMANITEC_ORG` environment variable to the ID of your Humanitec Organization (must be all lowercase):
138138

139-
```
139+
```shell
140140
export HUMANITEC_ORG="my-humanitec-org"
141141
```
142142

143143
2. Verify the existence of the Resource Definition for the AKS cluster in your Humanitec Organization:
144144

145-
```
145+
```shell
146146
curl -s https://api.humanitec.io/orgs/${HUMANITEC_ORG}/resources/defs/ref-arch \
147147
--header "Authorization: Bearer ${HUMANITEC_TOKEN}" \
148148
| jq .id,.type
149149
```
150150

151151
This should output:
152152

153-
```
153+
```shell
154154
"ref-arch"
155155
"k8s-cluster"
156156
```
157157

158158
3. Verify the existence of the newly created AKS cluster:
159159

160-
```
160+
```shell
161161
az aks list --subscription <your-subscription>
162162
```
163163

164164
This should output:
165165

166-
```
166+
```shell
167167
[
168168
{
169169
... various properties ...
@@ -173,17 +173,56 @@ Check for the existence of key elements of the reference architecture. This is a
173173
]
174174
```
175175

176+
### Enable a portal (optional)
177+
178+
#### Portal Prerequisites
179+
180+
Backstage requires a GitHub connection, which in turn needs:
181+
182+
* 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.
183+
* Create a classic github personal access token with `repo`, `workflow`, `delete_repo` and `admin:org` scope [here](https://github.com/settings/tokens).
184+
* Set the `GITHUB_TOKEN` environment variable to your token.
185+
186+
```shell
187+
export GITHUB_TOKEN="my-github-token"
188+
```
189+
190+
* Set the `GITHUB_ORG_ID` environment variable to your GitHub organization ID.
191+
192+
```shell
193+
export GITHUB_ORG_ID="my-github-org-id"
194+
```
195+
196+
* Install the GitHub App for Backstage into your GitHub organization
197+
* 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:
198+
* “All repositories” ~> Install
199+
* “Okay, [] was installed on the [] account.” ~> You can close the window and server.
200+
201+
#### Portal Usage
202+
203+
* Enable `with_backstage` inside your `terraform.tfvars` and configure the additional variables that a required for Backstage.
204+
* Perform another `terraform apply`
205+
206+
#### Verify portal setup
207+
208+
* [Fetch the DNS entry](https://developer.humanitec.com/score/getting-started/get-dns/) of the Humanitec Application `backstage`, Environment `development`.
209+
* Open the host in your browser.
210+
* Click the "Create" button and scaffold your first application.
211+
176212
### Cleaning up
177213

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

180-
1. Ensure you are (still) logged in with `az`.
216+
Once you are finished with the reference architecture, you can remove all provisioned infrastructure and the resource definitions created in Humanitec with the following:
217+
218+
1. Delete all Humanitec Applications scaffolded using the Portal, if you used one, but not the `backstage` app itself.
219+
2. Ensure you are (still) logged in with `az`.
181220

182-
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.
221+
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.
183222

184-
3. Run terraform:
223+
4. Run terraform:
185224

186-
```
225+
```shell
187226
terraform destroy
188227
```
189228

@@ -198,24 +237,44 @@ Once you are finished with the reference architecture, you can remove all provis
198237
| azapi | ~> 1.11 |
199238
| azuread | ~> 2.47 |
200239
| azurerm | ~> 3.87 |
240+
| github | ~> 5.38 |
201241
| helm | ~> 2.12 |
202242
| humanitec | ~> 1.0 |
203243
| kubernetes | ~> 2.25 |
244+
| random | ~> 3.5 |
245+
246+
### Providers
247+
248+
| Name | Version |
249+
|------|---------|
250+
| humanitec | ~> 1.0 |
204251

205252
### Modules
206253

207254
| Name | Source | Version |
208255
|------|--------|---------|
209256
| base | ./modules/base | n/a |
257+
| github | ./modules/github | n/a |
258+
| github\_app | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-12//modules/github-app |
259+
| portal\_backstage | ./modules/portal-backstage | n/a |
260+
261+
### Resources
262+
263+
| Name | Type |
264+
|------|------|
265+
| [humanitec_service_user_token.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/service_user_token) | resource |
266+
| [humanitec_user.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/user) | resource |
210267

211268
### Inputs
212269

213270
| Name | Description | Type | Default | Required |
214271
|------|-------------|------|---------|:--------:|
215-
| humanitec\_org\_id | Humanitec Organization ID | `string` | n/a | yes |
216272
| location | Azure region to deploy into | `string` | n/a | yes |
217273
| subscription\_id | Azure Subscription (ID) to use | `string` | n/a | yes |
274+
| github\_org\_id | GitHub org id (required for Backstage) | `string` | `null` | no |
275+
| humanitec\_org\_id | Humanitec Organization ID (required for Backstage) | `string` | `null` | no |
218276
| vm\_size | The Azure VM instances type to use as "Agents" (aka Kubernetes Nodes) in AKS | `string` | `"Standard_D2_v2"` | no |
277+
| with\_backstage | Deploy Backstage | `bool` | `false` | no |
219278

220279
### Outputs
221280

0 commit comments

Comments
 (0)