Skip to content

Commit 66e6327

Browse files
committed
feat: restructure module GitHub Actions Terraform Setup
1 parent 84cb228 commit 66e6327

File tree

5 files changed

+73
-33
lines changed

5 files changed

+73
-33
lines changed
Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,25 @@
1-
output "config_tf" {
1+
output "provider_config" {
22
description = "Generates a config.tf that can be dropped into meshStack's BuildingBlockDefinition as an encrypted file input to configure this building block."
33
sensitive = true
44
value = <<EOF
5-
provider "github" {
6-
owner = "${var.github_org}"
75
8-
app_auth {
9-
id = "${var.github_app_id}"
10-
installation_id = "${var.github_app_installation_id}"
6+
use following Environment variables to configure your Terraform AZURERM Provider:
117
12-
# TODO: ensure the pem file exists on disk in the BB execution environment (with meshStack: secret file input)
13-
pem_file = file("./github-app.private-key.pem")
14-
}
8+
ARM_TENANT_ID = "${data.azurerm_subscription.current.tenant_id}"
9+
ARM_SUBSCRIPTION_ID = "USE THE PLATFORM TENANT ID"
10+
ARM_CLIENT_ID = "${azuread_service_principal.starterkit.client_id}"
11+
ARM_CLIENT_SECRET = "${azuread_service_principal_password.starterkit.value}"
1512
}
1613
17-
provider "azurerm" {
18-
features {
19-
resource_group {
20-
prevent_deletion_if_contains_resources = false # This allows the deletion of the building block without having to separately delete the app resources
21-
}
22-
}
14+
use following Environment variables to configure your Terraform AZUREAD Provider:
2315
24-
resource_provider_registrations = "core"
25-
26-
storage_use_azuread = true
27-
28-
tenant_id = "${data.azurerm_subscription.current.tenant_id}"
29-
subscription_id = var.subscription_id
30-
client_id = "${azuread_service_principal.starterkit.client_id}"
31-
client_secret = "${azuread_service_principal_password.starterkit.value}"
16+
ARM_TENANT_ID = "${data.azurerm_subscription.current.tenant_id}"
17+
ARM_CLIENT_ID = "${azuread_service_principal.starterkit.client_id}"
18+
ARM_CLIENT_SECRET = "${azuread_service_principal_password.starterkit.value}"
3219
}
33-
34-
locals {
35-
deploy_role_definition_id = "${azurerm_role_definition.starterkit_deploy.role_definition_id}"
20+
EOF
3621
}
3722

38-
provider "azuread" {
39-
tenant_id = "${data.azurerm_subscription.current.tenant_id}"
40-
client_id = "${azuread_service_principal.starterkit.client_id}"
41-
client_secret = "${azuread_service_principal_password.starterkit.value}"
42-
}
43-
EOF
23+
output "deploy_role_definition_id" {
24+
value = azurerm_role_definition.starterkit_deploy.role_definition_id
4425
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Azure GitHub Actions Terraform Setup
3+
supportedPlatforms:
4+
- azure
5+
description: |
6+
Deploy directly to Azure using GitHub Actions and Terraform brought to you by meshStack
7+
---
8+
9+
# Azure Key Vault
10+
11+
This Terraform module provisions an Azure Key Vault along with necessary role assignments.
12+
13+
14+
## Requirements
15+
- Terraform `>= 1.0`
16+
- AzureRM Provider `>= 4.18.0`
17+
18+
## Providers
19+
20+
```hcl
21+
terraform {
22+
required_providers {
23+
azurerm = {
24+
source = "hashicorp/azurerm"
25+
version = "4.18.0"
26+
}
27+
}
28+
}
29+
30+
provider "azurerm" {
31+
features {}
32+
}
33+
```
34+
35+
<!-- BEGIN_TF_DOCS -->
36+
37+
<!-- END_TF_DOCS -->

modules/azure/github-actions-terraform-setup/buildingblock/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ data "azuread_client_config" "current" {}
66
resource "azurerm_role_assignment" "starterkit_deploy" {
77
# since the role is defined on MG level, we need to prefix the subscription id here to make terraform happy and not plan replacements
88
# see https://github.com/hashicorp/terraform-provider-azurerm/issues/19847#issuecomment-1407262429
9-
role_definition_id = "${data.azurerm_subscription.current.id}/providers/Microsoft.Authorization/roleDefinitions/${local.deploy_role_definition_id}"
9+
role_definition_id = "${data.azurerm_subscription.current.id}/providers/Microsoft.Authorization/roleDefinitions/${var.deploy_role_definition_id}"
1010

1111
description = "Grant permissions to deploy a starterkit building block."
1212
principal_id = data.azuread_client_config.current.object_id
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
provider "github" {
2+
app_auth {}
3+
# using `GITHUB_APP_XXX` environment variables
4+
}
5+
6+
provider "azurerm" {
7+
features {
8+
resource_group {
9+
prevent_deletion_if_contains_resources = false # This allows the deletion of the building block without having to separately delete the app resources
10+
}
11+
}
12+
13+
resource_provider_registrations = "core"
14+
15+
storage_use_azuread = true
16+
}
17+
18+
provider "azuread" {}

modules/azure/github-actions-terraform-setup/buildingblock/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ variable "location" {
2323
default = "westeurope"
2424
}
2525

26+
variable "deploy_role_definition_id" {
27+
type = string
28+
description = "Role definition ID to assign to the GitHub Actions App Service Managed Identity. This is used to deploy resources via Terraform."
29+
}

0 commit comments

Comments
 (0)