Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add secure_storage_connector module #58

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resources that lack official modules.
| <a name="module_cert_manager"></a> [cert\_manager](#module\_cert\_manager) | ./modules/cert_manager | n/a |
| <a name="module_database"></a> [database](#module\_database) | ./modules/database | n/a |
| <a name="module_identity"></a> [identity](#module\_identity) | ./modules/identity | n/a |
| <a name="module_multi_tenant_service_principal"></a> [multi\_tenant\_service\_principal](#module\_multi\_tenant\_service\_principal) | ./modules/multi_tenant_service_principal | n/a |
| <a name="module_networking"></a> [networking](#module\_networking) | ./modules/networking | n/a |
| <a name="module_redis"></a> [redis](#module\_redis) | ./modules/redis | n/a |
| <a name="module_storage"></a> [storage](#module\_storage) | ./modules/storage | n/a |
Expand Down
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ module "app_aks" {
tags = var.tags
}

module "multi_tenant_service_principal" {
source = "./modules/multi_tenant_service_principal"

namespace = var.namespace
# resource_group_name = azurerm_resource_group.default.name
}

locals {
container_name = try(module.storage[0].container.name, "")
account_name = try(module.storage[0].account.name, "")
Expand Down
13 changes: 13 additions & 0 deletions modules/multi_tenant_service_principal/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data "azuread_client_config" "current" {}

resource "azuread_application" "example" {
display_name = "${var.namespace} Application"
owners = [data.azuread_client_config.current.object_id]
sign_in_audience = "AzureADMultipleOrgs"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to create a multi-tenant service principal

https://stackoverflow.com/questions/65696539/how-to-create-a-multi-tenant-service-principal-in-azure-using-terraform/65696750#65696750

And available_to_other_tenants has been deprecated and replaced with sign_in_audience in the AzureAD v2.0 and Microsoft Graph docs

}

resource "azuread_service_principal" "example" {
client_id = azuread_application.example.client_id
app_role_assignment_required = false
owners = [data.azuread_client_config.current.object_id]
}
Empty file.
9 changes: 9 additions & 0 deletions modules/multi_tenant_service_principal/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "namespace" {
type = string
description = "Friendly name prefix used for tagging and naming Azure resources."
}

#variable "resource_group_name" {
# description = "Resource Group name"
# type = string
#}
45 changes: 45 additions & 0 deletions modules/secure_storage_connector/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "group" {
name = "${var.namespace}-resources"
location = var.location
}

resource "azurerm_storage_account" "account" {
name = "${var.namespace}storageaccount"
resource_group_name = azurerm_resource_group.group.name
location = azurerm_resource_group.group.location
account_tier = "Standard"
account_replication_type = "LRS"
is_hns_enabled = "true"

blob_properties {
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD", "PUT"]
allowed_origins = ["*"]
exposed_headers = ["*"]
max_age_in_seconds = 3600
}
}
}

resource "azurerm_storage_container" "container" {
name = "${var.namespace}-container"
storage_account_name = azurerm_storage_account.account.name
container_access_type = "private"
}

resource "azurerm_role_assignment" "principal" {
scope = azurerm_storage_account.account.id
role_definition_name = "Storage Blob Data Owner"
principal_id = var.azure_principal_id
}

resource "azurerm_role_assignment" "principal2" {
scope = azurerm_storage_account.account.id
role_definition_name = "Storage Account Contributor"
principal_id = var.azure_principal_id
}
7 changes: 7 additions & 0 deletions modules/secure_storage_connector/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "storage_account_name" {
value = azurerm_storage_account.account.name
}

output "container_name" {
value = azurerm_storage_container.container.name
}
14 changes: 14 additions & 0 deletions modules/secure_storage_connector/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "namespace" {
type = string
description = "Prefix to use when creating resources"
}

variable "location" {
type = string
description = "The Azure Region where resources will be created"
}

variable "azure_principal_id" {
description = "Azure principal ID that can access the blob storage"
type = string
}
1 change: 1 addition & 0 deletions modules/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "azurerm_storage_container" "default" {
name = "wandb"
storage_account_name = azurerm_storage_account.default.name
container_access_type = "private"
# TODO give RBAC to the newly created service principal
}

resource "azurerm_management_lock" "default" {
Expand Down