Skip to content

Commit 727d51a

Browse files
Merge pull request #27 from johanneswuerbach/cleanup
feat: create humanitec deploy user
2 parents 3ba0cfb + 91cb768 commit 727d51a

File tree

7 files changed

+62
-45
lines changed

7 files changed

+62
-45
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,28 @@ Once you are finished with the reference architecture, you can remove all provis
224224
| kubernetes | ~> 2.25 |
225225
| random | ~> 3.5 |
226226

227+
### Providers
228+
229+
| Name | Version |
230+
|------|---------|
231+
| humanitec | ~> 1.0 |
232+
227233
### Modules
228234

229235
| Name | Source | Version |
230236
|------|--------|---------|
231237
| base | ./modules/base | n/a |
232238
| github | ./modules/github | n/a |
233-
| github\_app | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-06//modules/github-app |
239+
| github\_app | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-12//modules/github-app |
234240
| portal\_backstage | ./modules/portal-backstage | n/a |
235241

242+
### Resources
243+
244+
| Name | Type |
245+
|------|------|
246+
| [humanitec_service_user_token.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/service_user_token) | resource |
247+
| [humanitec_user.deployer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/user) | resource |
248+
236249
### Inputs
237250

238251
| Name | Description | Type | Default | Required |
@@ -241,7 +254,6 @@ Once you are finished with the reference architecture, you can remove all provis
241254
| aws\_region | AWS region | `string` | n/a | yes |
242255
| disk\_size | Disk size in GB to use for EKS nodes | `number` | `20` | no |
243256
| github\_org\_id | GitHub org id (required for Backstage) | `string` | `null` | no |
244-
| humanitec\_ci\_service\_user\_token | Humanitec CI Service User Token (required for Backstage) | `string` | `null` | no |
245257
| humanitec\_org\_id | Humanitec Organization ID (required for Backstage) | `string` | `null` | no |
246258
| instance\_types | List of EC2 instances types to use for EKS nodes | `list(string)` | <pre>[<br> "t3.large"<br>]</pre> | no |
247259
| with\_backstage | Deploy Backstage | `bool` | `false` | no |

main.tf

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@ module "base" {
88
disk_size = var.disk_size
99
}
1010

11+
# User used for scaffolding and deploying apps
12+
13+
resource "humanitec_user" "deployer" {
14+
count = var.with_backstage ? 1 : 0
15+
16+
name = "deployer"
17+
role = "administrator"
18+
type = "service"
19+
}
20+
21+
resource "humanitec_service_user_token" "deployer" {
22+
count = var.with_backstage ? 1 : 0
23+
24+
id = "deployer"
25+
user_id = humanitec_user.deployer[0].id
26+
description = "Used by scaffolding and deploying"
27+
}
28+
1129
module "github" {
1230
count = var.with_backstage ? 1 : 0
1331

1432
source = "./modules/github"
1533

1634
humanitec_org_id = var.humanitec_org_id
17-
humanitec_ci_service_user_token = var.humanitec_ci_service_user_token
35+
humanitec_ci_service_user_token = humanitec_service_user_token.deployer[0].token
1836
aws_region = var.aws_region
1937
github_org_id = var.github_org_id
2038

@@ -30,9 +48,7 @@ locals {
3048
module "github_app" {
3149
count = var.with_backstage ? 1 : 0
3250

33-
# Not pinned as we don't have a release yet
34-
# tflint-ignore: terraform_module_pinned_source
35-
source = "github.com/humanitec-architecture/shared-terraform-modules?ref=v2024-06-06//modules/github-app"
51+
source = "github.com/humanitec-architecture/shared-terraform-modules?ref=v2024-06-12//modules/github-app"
3652

3753
credentials_file = "${path.module}/${local.github_app_credentials_file}"
3854
}
@@ -45,7 +61,7 @@ module "portal_backstage" {
4561
source = "./modules/portal-backstage"
4662

4763
humanitec_org_id = var.humanitec_org_id
48-
humanitec_ci_service_user_token = var.humanitec_ci_service_user_token
64+
humanitec_ci_service_user_token = humanitec_service_user_token.deployer[0].token
4965

5066
github_org_id = var.github_org_id
5167
github_app_client_id = module.github_app[0].client_id

modules/portal-backstage/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ This module deploys the [Humanitec Reference Architecture Backstage](https://git
1010
| Name | Version |
1111
|------|---------|
1212
| terraform | >= 1.3.0 |
13-
| aws | ~> 5.17 |
14-
| github | ~> 5.38 |
1513
| humanitec | ~> 1.0 |
16-
| random | ~> 3.5 |
1714

1815
### Providers
1916

@@ -26,7 +23,7 @@ This module deploys the [Humanitec Reference Architecture Backstage](https://git
2623
| Name | Source | Version |
2724
|------|--------|---------|
2825
| backstage\_postgres | github.com/humanitec-architecture/resource-packs-in-cluster | v2024-06-05//humanitec-resource-defs/postgres/basic |
29-
| portal\_backstage | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-06//modules/portal-backstage |
26+
| portal\_backstage | github.com/humanitec-architecture/shared-terraform-modules | v2024-06-12//modules/portal-backstage |
3027

3128
### Resources
3229

modules/portal-backstage/main.tf

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,37 @@ resource "humanitec_application" "backstage" {
33
name = "backstage"
44
}
55

6+
locals {
7+
secrets = {
8+
humanitec-token = var.humanitec_ci_service_user_token
9+
github-app-client-id = var.github_app_client_id
10+
github-app-client-secret = var.github_app_client_secret
11+
github-app-private-key = indent(2, var.github_app_private_key)
12+
github-webhook-secret = var.github_webhook_secret
13+
}
14+
15+
secret_refs = {
16+
for key, value in local.secrets : key => {
17+
value = value
18+
}
19+
}
20+
}
21+
622
module "portal_backstage" {
7-
# Not pinned as we don't have a release yet
8-
# tflint-ignore: terraform_module_pinned_source
9-
source = "github.com/humanitec-architecture/shared-terraform-modules?ref=v2024-06-06//modules/portal-backstage"
23+
source = "github.com/humanitec-architecture/shared-terraform-modules?ref=v2024-06-12//modules/portal-backstage"
1024

1125
cloud_provider = "aws"
1226

13-
humanitec_org_id = var.humanitec_org_id
14-
humanitec_app_id = humanitec_application.backstage.id
15-
humanitec_ci_service_user_token = var.humanitec_ci_service_user_token
27+
humanitec_org_id = var.humanitec_org_id
28+
humanitec_app_id = humanitec_application.backstage.id
29+
humanitec_ci_service_user_token_ref = local.secret_refs["humanitec-token"]
1630

17-
github_org_id = var.github_org_id
18-
github_app_client_id = var.github_app_client_id
19-
github_app_client_secret = var.github_app_client_secret
20-
github_app_id = var.github_app_id
21-
github_app_private_key = var.github_app_private_key
22-
github_webhook_secret = var.github_webhook_secret
31+
github_org_id = var.github_org_id
32+
github_app_client_id_ref = local.secret_refs["github-app-client-id"]
33+
github_app_client_secret_ref = local.secret_refs["github-app-client-secret"]
34+
github_app_id = var.github_app_id
35+
github_app_private_key_ref = local.secret_refs["github-app-private-key"]
36+
github_webhook_secret_ref = local.secret_refs["github-webhook-secret"]
2337
}
2438

2539
# Configure required resources for backstage

modules/portal-backstage/providers.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
terraform {
22
required_providers {
3-
aws = {
4-
source = "hashicorp/aws"
5-
version = "~> 5.17"
6-
}
73
humanitec = {
84
source = "humanitec/humanitec"
95
version = "~> 1.0"
106
}
11-
github = {
12-
source = "integrations/github"
13-
version = "~> 5.38"
14-
}
15-
random = {
16-
source = "hashicorp/random"
17-
version = "~> 3.5"
18-
}
197
}
208
required_version = ">= 1.3.0"
219
}

terraform.tfvars.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ disk_size = 20
1111
# GitHub org id (required for Backstage)
1212
github_org_id = ""
1313

14-
# Humanitec CI Service User Token (required for Backstage)
15-
humanitec_ci_service_user_token = ""
16-
1714
# Humanitec Organization ID (required for Backstage)
1815
humanitec_org_id = ""
1916

variables.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,3 @@ variable "humanitec_org_id" {
3939
type = string
4040
default = null
4141
}
42-
43-
variable "humanitec_ci_service_user_token" {
44-
description = "Humanitec CI Service User Token (required for Backstage)"
45-
type = string
46-
sensitive = true
47-
default = null
48-
}

0 commit comments

Comments
 (0)