Skip to content

Commit

Permalink
Solution's IaC
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Oct 11, 2023
1 parent def422d commit 83a459d
Show file tree
Hide file tree
Showing 51 changed files with 1,227 additions and 1 deletion.
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,39 @@ public/
resources/
node_modules/
package-lock.json
.hugo_build.lock
.hugo_build.lock

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
6 changes: 6 additions & 0 deletions docs/content/en/docs/Deploy the Architecture/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ weight: 3
description: This guide provides details and instructions to help you deploy the Activate GenAI with Azure Accelerator for your customer.
---

{{% pageinfo %}}
Work in progress. There are still some manual steps to be automated. Check [here](https://github.com/Azure/activate-genai/blob/main/infra/README.md) for the latest updates.
{{% /pageinfo %}}


Run the following command to deploy the **Activate GenAI with Azure** Accelerator:

```bash
cd infra
terraform init
terraform apply
```
60 changes: 60 additions & 0 deletions infra/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Deploying the Solution

## Deploying the infrastructure

Run the following commands to deploy the infrastructure:

```bash
cd infra
terraform init
terraform apply
```

## Manual steps

> This is temporal
Clone the GitHub repository [cmendible/azure-search-openai-demo](https://github.com/cmendible/azure-search-openai-demo) and run the following commands to deploy the Azure Search Index and upload the sample documents:

```bash
git clone https://github.com/cmendible/azure-search-openai-demo.git
cd azure-search-openai-demo
git checkout k8s

export AZURE_PRINCIPAL_ID="<principal id>"
export AZURE_RESOURCE_GROUP="<resource group>"
export AZURE_SUBSCRIPTION_ID="<subscription id>"
export AZURE_TENANT_ID="<azure tenant id>"
export AZURE_STORAGE_ACCOUNT="<storage account name>"
export AZURE_STORAGE_CONTAINER="content"
export AZURE_SEARCH_SERVICE="<search service name>"
export OPENAI_HOST="azure"
export AZURE_OPENAI_SERVICE="<openai service name>"
export OPENAI_API_KEY=""
export OPENAI_ORGANIZATION=""
export AZURE_OPENAI_EMB_DEPLOYMENT="text-embedding-ada-002"
export AZURE_OPENAI_EMB_MODEL_NAME="text-embedding-ada-002"
export AZURE_SEARCH_INDEX="gptkbindex"
```

Login to Azure:

```bash
azd auth login --client-id <client-id> --client-secret <client-password> --tenant-id <tenant-id>
```

Deploy the Azure Search Index and upload the sample documents:

```bash
./scripts/prepdocs.sh
```
157 changes: 157 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
data "azurerm_subscription" "current" {}

resource "random_id" "random" {
byte_length = 8
}

resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
}

locals {
name_sufix = substr(lower(random_id.random.hex), 1, 4)
storage_account_name = "${var.storage_account_name}${local.name_sufix}"
}

module "vnet" {
source = "./modules/vnet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = var.virtual_network_name
}

module "apim" {
source = "./modules/apim"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
apim_name = var.apim_name
apim_subnet_id = module.vnet.apim_subnet_id
publisher_name = var.publisher_name
publisher_email = var.publisher_email
}

module "mi" {
source = "./modules/mi"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
managed_identity_name = var.managed_identity_name
}

resource "azurerm_role_assignment" "id_reader" {
scope = azurerm_resource_group.rg.id
role_definition_name = "Reader"
principal_id = module.mi.principal_id
}

module "search" {
source = "./modules/search"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
search_name = var.search_name
principal_id = module.mi.principal_id
}

module "form_recognizer" {
source = "./modules/form"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
form_recognizer_name = var.form_recognizer_name
}

module "log" {
source = "./modules/log"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
log_name = var.log_name
}

module "appi" {
source = "./modules/appi"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
appi_name = var.apim_name
log_id = module.log.log_id
}

module "st" {
source = "./modules/st"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
storage_account_name = local.storage_account_name
principal_id = module.mi.principal_id
}

module "openai" {
source = "./modules/openai"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
secondary_location = var.secondary_location
azopenai_name = var.azopenai_name
principal_id = module.mi.principal_id
}

module "cae" {
source = "./modules/cae"
location = azurerm_resource_group.rg.location
resource_group_id = azurerm_resource_group.rg.id
cae_name = var.cae_name
cae_subnet_id = module.vnet.cae_subnet_id
log_workspace_id = module.log.log_workspace_id
log_key = module.log.log_key
appi_key = module.appi.appi_key
}

module "ca_back" {
source = "./modules/ca-back"
location = azurerm_resource_group.rg.location
resource_group_id = azurerm_resource_group.rg.id
ca_name = var.ca_back_name
cae_id = module.cae.cae_id
managed_identity_id = module.mi.mi_id
chat_gpt_deployment = module.openai.gpt_deployment_name
chat_gpt_model = module.openai.gpt_deployment_name
embeddings_deployment = module.openai.embedding_deployment_name
embeddings_model = module.openai.embedding_deployment_name
storage_account_name = module.st.storage_account_name
storage_container_name = module.st.storage_container_name
search_service_name = module.search.search_service_name
search_index_name = module.search.search_index_name
openai_service_name = module.openai.openai_service_name
tenant_id = data.azurerm_subscription.current.tenant_id
managed_identity_client_id = module.mi.client_id
}

# module "ca_webapi" {
# source = "./modules/ca-webapi"
# location = azurerm_resource_group.rg.location
# resource_group_id = azurerm_resource_group.rg.id
# ca_name = var.ca_webapi_name
# cae_id = module.cae.cae_id
# cae_default_domain = module.cae.defaultDomain
# ca_webapp_name = var.ca_webapp_name
# managed_identity_id = module.mi.mi_id
# chat_gpt_deployment = module.openai.gpt_deployment_name
# chat_gpt_model = module.openai.gpt_deployment_name
# embeddings_deployment = module.openai.embedding_deployment_name
# embeddings_model = module.openai.embedding_deployment_name
# storage_account_name = module.st.storage_account_name
# storage_container_name = module.st.storage_container_name
# search_service_name = module.search.search_service_name
# search_index_name = module.search.search_index_name
# openai_service_name = module.openai.openai_service_name
# tenant_id = data.azurerm_subscription.current.tenant_id
# managed_identity_client_id = module.mi.client_id
# }

# module "ca_webapp" {
# source = "./modules/ca-webapp"
# location = azurerm_resource_group.rg.location
# resource_group_id = azurerm_resource_group.rg.id
# ca_name = var.ca_webapp_name
# cae_id = module.cae.cae_id
# managed_identity_id = module.mi.mi_id
# tenant_id = data.azurerm_subscription.current.tenant_id
# managed_identity_client_id = module.mi.client_id
# backend_url = module.ca_webapi.fqdn
# }
13 changes: 13 additions & 0 deletions infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "azurerm_api_management" "apim" {
name = var.apim_name
location = var.location
resource_group_name = var.resource_group_name
publisher_name = var.publisher_name
publisher_email = var.publisher_email
sku_name = "Developer_1"
virtual_network_type = "External" # Use "Internal" for a fully private APIM

virtual_network_configuration {
subnet_id = var.apim_subnet_id
}
}
3 changes: 3 additions & 0 deletions infra/modules/apim/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "apim_name" {
value = azurerm_api_management.apim.name
}
6 changes: 6 additions & 0 deletions infra/modules/apim/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
variable "resource_group_name" {}
variable "location" {}
variable "apim_name" {}
variable "publisher_name" {}
variable "publisher_email" {}
variable "apim_subnet_id" {}
7 changes: 7 additions & 0 deletions infra/modules/appi/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "azurerm_application_insights" "appinsights" {
name = var.appi_name
location = var.location
resource_group_name = var.resource_group_name
application_type = "web"
workspace_id = var.log_id
}
7 changes: 7 additions & 0 deletions infra/modules/appi/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "appi_id" {
value = azurerm_application_insights.appinsights.id
}

output "appi_key" {
value = azurerm_application_insights.appinsights.instrumentation_key
}
4 changes: 4 additions & 0 deletions infra/modules/appi/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_group_name" {}
variable "location" {}
variable "appi_name" {}
variable "log_id" {}
Loading

0 comments on commit 83a459d

Please sign in to comment.