Skip to content

Commit 4d0c721

Browse files
committed
init further azure devops services
1 parent 6386b5a commit 4d0c721

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4197
-45
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Azure DevOps Pipeline Backplane
2+
3+
This module provisions the infrastructure required to support the Azure DevOps Pipeline building block.
4+
5+
## What It Provisions
6+
7+
- **Azure AD Service Principal**: For pipeline management automation
8+
- **Azure Key Vault**: Stores Azure DevOps Personal Access Token (PAT)
9+
- **Custom Role Definition**: Minimal permissions for reading Key Vault secrets
10+
- **Role Assignment**: Grants the service principal access to Key Vault
11+
12+
## Prerequisites
13+
14+
- Azure subscription with permissions to create:
15+
- Azure AD applications and service principals
16+
- Key Vault instances
17+
- Custom role definitions and assignments
18+
- Azure DevOps organization with Administrator access
19+
- Azure DevOps PAT with `Build (Read & Execute)` scope
20+
21+
## Usage
22+
23+
```hcl
24+
module "azuredevops_pipeline_backplane" {
25+
source = "./backplane"
26+
27+
azure_devops_organization_url = "https://dev.azure.com/myorg"
28+
service_principal_name = "azuredevops-pipeline-terraform"
29+
key_vault_name = "kv-azdo-pipeline-prod"
30+
resource_group_name = "rg-azdo-pipeline-prod"
31+
location = "West Europe"
32+
scope = "/subscriptions/00000000-0000-0000-0000-000000000000"
33+
}
34+
```
35+
36+
## Post-Deployment Steps
37+
38+
1. Create an Azure DevOps PAT with `Build (Read & Execute)` scope
39+
2. Store the PAT in the provisioned Key Vault:
40+
```bash
41+
az keyvault secret set --vault-name <key_vault_name> --name azdo-pat --value <your_pat>
42+
```
43+
44+
## Outputs
45+
46+
- `service_principal_client_id` - For authentication
47+
- `key_vault_name` - Where to store the PAT
48+
- `key_vault_uri` - For programmatic access
49+
- `azure_devops_organization_url` - Organization URL passed through
50+
51+
## Security Considerations
52+
53+
- Service principal has read-only access to Key Vault secrets
54+
- PAT should be rotated regularly (recommended: every 90 days)
55+
- Use separate backplane instances for different environments
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
data "azurerm_client_config" "current" {}
2+
3+
data "azurerm_subscription" "current" {}
4+
5+
resource "azuread_application" "azure_devops" {
6+
display_name = var.service_principal_name
7+
description = "Service principal for managing Azure DevOps pipelines"
8+
}
9+
10+
resource "azuread_service_principal" "azure_devops" {
11+
client_id = azuread_application.azure_devops.client_id
12+
}
13+
14+
resource "azurerm_resource_group" "devops" {
15+
name = var.resource_group_name
16+
location = var.location
17+
}
18+
19+
resource "azurerm_key_vault" "devops" {
20+
name = var.key_vault_name
21+
location = azurerm_resource_group.devops.location
22+
resource_group_name = azurerm_resource_group.devops.name
23+
tenant_id = data.azurerm_client_config.current.tenant_id
24+
sku_name = "standard"
25+
26+
access_policy {
27+
tenant_id = data.azurerm_client_config.current.tenant_id
28+
object_id = data.azurerm_client_config.current.object_id
29+
30+
secret_permissions = [
31+
"Get",
32+
"List",
33+
"Set",
34+
"Delete",
35+
"Recover",
36+
"Backup",
37+
"Restore"
38+
]
39+
}
40+
41+
access_policy {
42+
tenant_id = data.azurerm_client_config.current.tenant_id
43+
object_id = azuread_service_principal.azure_devops.object_id
44+
45+
secret_permissions = [
46+
"Get",
47+
"List"
48+
]
49+
}
50+
}
51+
52+
resource "azurerm_role_definition" "azure_devops_manager" {
53+
name = "${var.service_principal_name}-manager"
54+
description = "Allows management of Azure DevOps pipelines"
55+
scope = var.scope
56+
57+
permissions {
58+
actions = [
59+
"Microsoft.KeyVault/vaults/secrets/read",
60+
"Microsoft.Resources/subscriptions/resourceGroups/read"
61+
]
62+
}
63+
}
64+
65+
resource "azurerm_role_assignment" "azure_devops_manager" {
66+
scope = var.scope
67+
role_definition_id = azurerm_role_definition.azure_devops_manager.role_definition_resource_id
68+
principal_id = azuread_service_principal.azure_devops.object_id
69+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
output "service_principal_client_id" {
2+
description = "Client ID of the Azure DevOps service principal"
3+
value = azuread_service_principal.azure_devops.client_id
4+
}
5+
6+
output "service_principal_object_id" {
7+
description = "Object ID of the Azure DevOps service principal"
8+
value = azuread_service_principal.azure_devops.object_id
9+
}
10+
11+
output "key_vault_id" {
12+
description = "ID of the Key Vault for storing Azure DevOps PAT"
13+
value = azurerm_key_vault.devops.id
14+
}
15+
16+
output "key_vault_name" {
17+
description = "Name of the Key Vault for storing Azure DevOps PAT"
18+
value = azurerm_key_vault.devops.name
19+
}
20+
21+
output "key_vault_uri" {
22+
description = "URI of the Key Vault for storing Azure DevOps PAT"
23+
value = azurerm_key_vault.devops.vault_uri
24+
}
25+
26+
output "resource_group_name" {
27+
description = "Name of the resource group containing the Key Vault"
28+
value = azurerm_resource_group.devops.name
29+
}
30+
31+
output "azure_devops_organization_url" {
32+
description = "Azure DevOps organization URL"
33+
value = var.azure_devops_organization_url
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "azure_devops_organization_url" {
2+
description = "Azure DevOps organization URL (e.g., https://dev.azure.com/myorg)"
3+
type = string
4+
}
5+
6+
variable "service_principal_name" {
7+
description = "Name for the Azure DevOps service principal"
8+
type = string
9+
default = "azure-devops-terraform"
10+
}
11+
12+
variable "key_vault_name" {
13+
description = "Name of the Key Vault to store the Azure DevOps PAT"
14+
type = string
15+
}
16+
17+
variable "resource_group_name" {
18+
description = "Resource group name for the Key Vault"
19+
type = string
20+
}
21+
22+
variable "location" {
23+
description = "Azure region for resources"
24+
type = string
25+
default = "West Europe"
26+
}
27+
28+
variable "scope" {
29+
description = "Azure scope for role definitions (subscription or management group)"
30+
type = string
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = "~> 3.116.0"
8+
}
9+
azuread = {
10+
source = "hashicorp/azuread"
11+
version = "~> 2.53.1"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)