Skip to content

Commit fba5732

Browse files
committed
feat: use dynamic credentials
1 parent e383304 commit fba5732

File tree

9 files changed

+26
-14
lines changed

9 files changed

+26
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ Once you are finished with the reference architecture, you can remove all provis
269269

270270
| Name | Description | Type | Default | Required |
271271
|------|-------------|------|---------|:--------:|
272+
| humanitec\_org\_id | Humanitec Organization ID | `string` | n/a | yes |
272273
| location | Azure region to deploy into | `string` | n/a | yes |
273274
| subscription\_id | Azure Subscription (ID) to use | `string` | n/a | yes |
274275
| 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 |
276276
| vm\_size | The Azure VM instances type to use as "Agents" (aka Kubernetes Nodes) in AKS | `string` | `"Standard_D2_v2"` | no |
277277
| with\_backstage | Deploy Backstage | `bool` | `false` | no |
278278

main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
module "base" {
44
source = "./modules/base"
55

6-
subscription_id = var.subscription_id
7-
location = var.location
8-
vm_size = var.vm_size
6+
subscription_id = var.subscription_id
7+
location = var.location
8+
vm_size = var.vm_size
9+
humanitec_org_id = var.humanitec_org_id
910
}
1011

1112
# User used for scaffolding and deploying apps

modules/base/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Module that provides the reference architecture.
3838
| Name | Type |
3939
|------|------|
4040
| [azuread_application.main](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application) | resource |
41+
| [azuread_application_federated_identity_credential.credential](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential) | resource |
4142
| [azuread_group.cluster_admins](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/group) | resource |
4243
| [azuread_group_member.cluster_admins](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/group_member) | resource |
4344
| [azuread_service_principal.humanitec](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal) | resource |
44-
| [azuread_service_principal_password.humanitec](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal_password) | resource |
4545
| [azurerm_container_registry.acr](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry) | resource |
4646
| [azurerm_public_ip.ingress](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | resource |
4747
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
@@ -63,6 +63,7 @@ Module that provides the reference architecture.
6363

6464
| Name | Description | Type | Default | Required |
6565
|------|-------------|------|---------|:--------:|
66+
| humanitec\_org\_id | Humanitec Organization ID | `string` | n/a | yes |
6667
| location | Azure region to deploy into | `string` | n/a | yes |
6768
| subscription\_id | Azure Subscription (ID) to use | `string` | n/a | yes |
6869
| cluster\_name | Name for the AKS cluster | `string` | `"ref-arch"` | no |

modules/base/humanitec.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ resource "humanitec_resource_account" "cluster_account" {
66
type = "azure"
77

88
credentials = jsonencode({
9-
"appId" : azuread_service_principal.humanitec.client_id,
10-
"displayName" : azuread_application.main.display_name,
11-
"password" : azuread_service_principal_password.humanitec.value,
12-
"tenant" : azuread_service_principal.humanitec.application_tenant_id
9+
"azure_identity_tenant_id" : azuread_service_principal.humanitec.application_tenant_id
10+
"azure_identity_client_id" : azuread_service_principal.humanitec.client_id
1311
})
1412
}
1513

modules/base/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ resource "azuread_service_principal" "humanitec" {
7272
owners = [data.azuread_client_config.current.object_id]
7373
}
7474

75-
resource "azuread_service_principal_password" "humanitec" {
76-
service_principal_id = azuread_service_principal.humanitec.id
75+
resource "azuread_application_federated_identity_credential" "credential" {
76+
application_id = azuread_application.main.id
77+
display_name = "AccessFromHumanitec"
78+
description = "Access From Humanitec"
79+
audiences = ["api://AzureADTokenExchange"]
80+
issuer = "https://idtoken.humanitec.io"
81+
subject = "${var.humanitec_org_id}/${humanitec_resource_account.cluster_account.id}"
7782
}
7883

7984
# Required to fetch AKS credentials

modules/base/terraform.tfvars.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ container_registry_name_prefix = "humrefarch"
88
# Name of the environment to be deployed into
99
environment = "development"
1010

11+
# Humanitec Organization ID
12+
humanitec_org_id = ""
13+
1114
# Number of allowed unavaiable replicas for the ingress-nginx controller
1215
ingress_nginx_min_unavailable = 1
1316

modules/base/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ variable "subscription_id" {
4949
description = "Azure Subscription (ID) to use"
5050
type = string
5151
}
52+
53+
variable "humanitec_org_id" {
54+
description = "Humanitec Organization ID"
55+
type = string
56+
}

terraform.tfvars.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# GitHub org id (required for Backstage)
33
github_org_id = ""
44

5-
# Humanitec Organization ID (required for Backstage)
5+
# Humanitec Organization ID
66
humanitec_org_id = ""
77

88
# Azure region to deploy into

variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ variable "github_org_id" {
2727
}
2828

2929
variable "humanitec_org_id" {
30-
description = "Humanitec Organization ID (required for Backstage)"
30+
description = "Humanitec Organization ID"
3131
type = string
32-
default = null
3332
}

0 commit comments

Comments
 (0)