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

Cognitive Deployment Module #241

Merged
merged 14 commits into from
Jun 19, 2023
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers/features/terraform:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.codespaces"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
branches:
- main
paths:
- '.github/workflows/cognitive-services.yml'
- 'terraform/cognitive-services/**'
- '.github/workflows/cognitive-services-account.yml'
- 'terraform/cognitive-services/cognitive-account**'
# - '.github/actions/**'

env:
terraform_workingdir: "terraform/cognitive-services"
terraform_workingdir: "terraform/cognitive-services/cognitive-account"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
terraform-lint:
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/cognitive-services-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Module:cognitive-services
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- '.github/workflows/cognitive-services-deployment.yml'
- 'terraform/cognitive-services/cognitive-deployment**'
# - '.github/actions/**'

env:
terraform_workingdir: "terraform/cognitive-services/cognitive-deployment"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
terraform-lint:
name: Run Terraform lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: "${{ env.terraform_workingdir }}"

steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2

- name: Terraform fmt
id: fmt
run: terraform fmt -check
continue-on-error: false

terraform-sec:
name: Run Terraform tfsec
needs:
- terraform-lint
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@main

- name: Run tfsec with reviewdog output on the PR
uses: ./.github/actions/run-terraform-sec

terratest:
name: Run Terratest
needs:
- terraform-sec
runs-on: [self-hosted, 1ES.Pool=azure-data-labs-modules]
environment:
name: acctests

defaults:
run:
working-directory: "${{ env.terraform_workingdir }}/test"

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18.2

- name: Setup Dependencies
run: |
az login --identity > /dev/null
export ARM_USE_MSI=true
export ARM_SUBSCRIPTION_ID=$(az login --identity | jq -r '.[0] | .id')
export ARM_TENANT_ID=$(az login --identity | jq -r '.[0] | .tenantId')
go mod init test && go mod tidy
env:
GOPATH: "/home/cloudtest/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}"

- name: Unit-test
run: |
az login --identity > /dev/null
export ARM_USE_MSI=true
export ARM_SUBSCRIPTION_ID=$(az login --identity | jq -r '.[0] | .id')
export ARM_TENANT_ID=$(az login --identity | jq -r '.[0] | .tenantId')
go test -v -timeout 45m
env:
GOPATH: "/home/cloudtest/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}"

terraform-docs:
name: Run Terraform Docs
needs:
- terratest
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Render terraform docs and push changes back to PR
uses: ./.github/actions/run-terraform-docs
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Looking for **built-in templates**? Check out [Azure Data Labs templates](https:
| [Batch Services / Account](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/batch-services/batch-services-account) | [![Module:batch-services-account](https://github.com/Azure/azure-data-labs-modules/actions/workflows/batch-services-account.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/batch-services-account.yml) |
| [Bastion Host](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/bastion-host) | [![Module:bastion-host](https://github.com/Azure/azure-data-labs-modules/actions/workflows/bastion-host.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/bastion-host.yml) |
| [Cognitive Search](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cognitive-search) | [![Module:cognitive-search](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-search.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-search.yml) |
| [Cognitive Services](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cognitive-services) |[![Module:cognitive-services](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services.yml) |
| [Cognitive Services / Account](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cognitive-services/cognitive-account) |[![Module:cognitive-account](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services-account.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services-account.yml) |
| [Cognitive Services / Deployment](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cognitive-services/cognitive-deployment) |[![Module:cognitive-deployment](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services-deployment.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cognitive-services-deployment.yml) |
| [Container Registry](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/container-registry) | [![Module:container-registry](https://github.com/Azure/azure-data-labs-modules/actions/workflows/container-registry.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/container-registry.yml) |
| [Cosmos DB / Account](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cosmosdb/cosmosdb-account) | [![Module:cosmosdb-account](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cosmosdb-account.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cosmosdb-account.yml)
| [Cosmos DB / Cassandra Keyspace](https://github.com/Azure/azure-data-labs-modules/tree/main/terraform/cosmosdb/cosmosdb-cassandra-keyspace) | [![Module:cosmosdb-cassandra-keyspace](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cosmosdb-cassandra-keyspace.yml/badge.svg)](https://github.com/Azure/azure-data-labs-modules/actions/workflows/cosmosdb-cassandra-keyspace.yml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

| Name | Type |
|------|------|
| [azurerm_cognitive_account.adl_cog](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cognitive_account) | resource |
| [azurerm_cognitive_account.adl_cog_acc](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cognitive_account) | resource |
| [http_http.ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |

## Inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data "http" "ip" {
url = "https://ifconfig.me"
}

resource "azurerm_cognitive_account" "adl_cog" {
resource "azurerm_cognitive_account" "adl_cog_acc" {
name = "cog-${var.basename}"
location = var.location
resource_group_name = var.resource_group_name
Expand All @@ -26,12 +26,12 @@ resource "azurerm_cognitive_account" "adl_cog" {
}

module "cog_pe" {
source = "../private-endpoint"
basename = "${azurerm_cognitive_account.adl_cog[0].name}-cog"
source = "../../private-endpoint"
basename = "${azurerm_cognitive_account.adl_cog_acc[0].name}-cog"
resource_group_name = var.resource_group_name
location = var.location
subnet_id = var.subnet_id
private_connection_resource_id = azurerm_cognitive_account.adl_cog[0].id
private_connection_resource_id = azurerm_cognitive_account.adl_cog_acc[0].id
subresource_names = ["account"]
is_manual_connection = false
private_dns_zone_ids = var.private_dns_zone_ids
Expand Down
23 changes: 23 additions & 0 deletions terraform/cognitive-services/cognitive-account/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output "id" {
value = (
length(azurerm_cognitive_account.adl_cog_acc) > 0 ?
azurerm_cognitive_account.adl_cog_acc[0].id : ""
)
description = "Resource identifier of the instance of Cognitive Services."
}

output "name" {
value = (
length(azurerm_cognitive_account.adl_cog_acc) > 0 ?
azurerm_cognitive_account.adl_cog_acc[0].name : ""
)
description = "The name of the Cognitive Services."
}

output "resource_group_name" {
value = (
length(azurerm_cognitive_account.adl_cog_acc) > 0 ?
azurerm_cognitive_account.adl_cog_acc[0].resource_group_name : ""
)
description = "Resource Group where the Cognitive Services exists."
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module "cognitive_services" {
module "cognitive_account" {
source = "../"
basename = random_string.postfix.result
resource_group_name = module.local_rg.name
Expand All @@ -12,30 +12,30 @@ module "cognitive_services" {
# Module dependencies

module "local_rg" {
source = "../../resource-group"
source = "../../../resource-group"
basename = random_string.postfix.result
location = var.location
tags = local.tags
}

module "local_vnet" {
source = "../../virtual-network"
source = "../../../virtual-network"
resource_group_name = module.local_rg.name
basename = random_string.postfix.result
location = var.location
address_space = ["10.0.0.0/16"]
}

module "local_snet_default" {
source = "../../subnet"
source = "../../../subnet"
resource_group_name = module.local_rg.name
name = "vnet-${random_string.postfix.result}-kv-default"
vnet_name = module.local_vnet.name
address_prefixes = ["10.0.6.0/24"]
}

module "local_pdnsz_cog" {
source = "../../private-dns-zone"
source = "../../../private-dns-zone"
resource_group_name = module.local_rg.name
dns_zones = [local.dns_cog]
vnet_id = module.local_vnet.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
tags = {
Project = "Azure/azure-data-labs-modules"
Module = "cognitive-services"
Module = "cognitive-account"
Toolkit = "Terraform"
}

Expand Down
11 changes: 11 additions & 0 deletions terraform/cognitive-services/cognitive-account/test/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "id" {
value = module.cognitive_account.id
}

output "name" {
value = module.cognitive_account.name
}

output "resource_group_name" {
value = module.cognitive_account.resource_group_name
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
resource_group_name = "rg-adl-terraform-state"
storage_account_name = "stadlterraformstate"
container_name = "default"
key = "cognitiveservices.terraform.tfstate"
key = "cognitiveaccount.terraform.tfstate"
}

required_providers {
Expand Down
28 changes: 28 additions & 0 deletions terraform/cognitive-services/cognitive-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- BEGIN_TF_DOCS -->
## Resources

| Name | Type |
|------|------|
| [azurerm_cognitive_deployment.adl_cog_dpl](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cognitive_deployment) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_basename"></a> [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes |
| <a name="input_cognitive_account_id"></a> [cognitive\_account\_id](#input\_cognitive\_account\_id) | The ID of the Cognitive Services Account. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_model_format"></a> [model\_format](#input\_model\_format) | The format of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. Possible value is OpenAI. | `string` | `"OpenAI"` | no |
| <a name="input_model_name"></a> [model\_name](#input\_model\_name) | The name of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_model_version"></a> [model\_version](#input\_model\_version) | The version of Cognitive Services Account Deployment model. | `string` | n/a | yes |
| <a name="input_scale_type"></a> [scale\_type](#input\_scale\_type) | TDeployment scale type. Possible value is Standard. Changing this forces a new resource to be created. | `string` | `"Standard"` | no |
| <a name="input_rai_policy_name"></a> [rai\_policy\_name](#input\_rai\_policy\_name) | The name of RAI policy. Changing this forces a new resource to be created. | `string` | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags which should be assigned to the deployed resource. | `map(string)` | `{}` | no |
| <a name="input_module_enabled"></a> [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | Resource identifier of the instance of Cognitive Deployment. |
| <a name="output_name"></a> [name](#output\_name) | The name of the Cognitive Deployment. |
<!-- END_TF_DOCS -->
17 changes: 17 additions & 0 deletions terraform/cognitive-services/cognitive-deployment/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cognitive_deployment

resource "azurerm_cognitive_deployment" "adl_cog_dpl" {
name = "cog-dpl-${var.basename}"
cognitive_account_id = var.cognitive_account_id
model {
format = var.model_format
name = var.model_name
version = var.model_version
}
scale {
type = var.scale_type
}
rai_policy_name = var.rai_policy_name

count = var.module_enabled ? 1 : 0
}
15 changes: 15 additions & 0 deletions terraform/cognitive-services/cognitive-deployment/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "id" {
value = (
length(azurerm_cognitive_deployment.adl_cog_dpl) > 0 ?
azurerm_cognitive_deployment.adl_cog_dpl[0].id : ""
)
description = "Resource identifier of the instance of Cognitive Deployment."
}

output "name" {
value = (
length(azurerm_cognitive_deployment.adl_cog_dpl) > 0 ?
azurerm_cognitive_deployment.adl_cog_dpl[0].name : ""
)
description = "The name of the Cognitive Deployment."
}
Loading