From 007b26e8d35d2cbc8d43a09c9fff646c6a13e5fe Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 17:10:14 +0200 Subject: [PATCH 01/13] cognitive deployment module --- ...ces.yml => cognitive-services-account.yml} | 6 +- .../cognitive-services-deployment.yml | 97 +++++++++++++++++++ README.md | 3 +- .../{ => cognitive-account}/README.md | 0 .../{ => cognitive-account}/main.tf | 0 .../{ => cognitive-account}/outputs.tf | 0 .../test/cognitive_account.tf} | 10 +- .../{ => cognitive-account}/test/locals.tf | 2 +- .../cognitive-account/test/outputs.tf | 11 +++ .../cognitive-account/test/providers.tf | 19 ++++ .../{ => cognitive-account}/test/unit_test.go | 0 .../{ => cognitive-account}/test/variables.tf | 0 .../{ => cognitive-account}/variables.tf | 0 .../cognitive-deployment/main.tf | 19 ++++ .../cognitive-deployment/outputs.tf | 23 +++++ .../test/cognitive_deployment.tf | 53 ++++++++++ .../cognitive-deployment/test/locals.tf | 9 ++ .../test/outputs.tf | 0 .../cognitive-deployment/test/providers.tf | 19 ++++ .../cognitive-deployment/test/unit_test.go | 36 +++++++ .../cognitive-deployment/test/variables.tf | 10 ++ .../cognitive-deployment/variables.tf | 55 +++++++++++ 22 files changed, 362 insertions(+), 10 deletions(-) rename .github/workflows/{cognitive-services.yml => cognitive-services-account.yml} (92%) create mode 100644 .github/workflows/cognitive-services-deployment.yml rename terraform/cognitive-services/{ => cognitive-account}/README.md (100%) rename terraform/cognitive-services/{ => cognitive-account}/main.tf (100%) rename terraform/cognitive-services/{ => cognitive-account}/outputs.tf (100%) rename terraform/cognitive-services/{test/cognitive_services.tf => cognitive-account/test/cognitive_account.tf} (83%) rename terraform/cognitive-services/{ => cognitive-account}/test/locals.tf (81%) create mode 100644 terraform/cognitive-services/cognitive-account/test/outputs.tf create mode 100644 terraform/cognitive-services/cognitive-account/test/providers.tf rename terraform/cognitive-services/{ => cognitive-account}/test/unit_test.go (100%) rename terraform/cognitive-services/{ => cognitive-account}/test/variables.tf (100%) rename terraform/cognitive-services/{ => cognitive-account}/variables.tf (100%) create mode 100644 terraform/cognitive-services/cognitive-deployment/main.tf create mode 100644 terraform/cognitive-services/cognitive-deployment/outputs.tf create mode 100644 terraform/cognitive-services/cognitive-deployment/test/cognitive_deployment.tf create mode 100644 terraform/cognitive-services/cognitive-deployment/test/locals.tf rename terraform/cognitive-services/{ => cognitive-deployment}/test/outputs.tf (100%) create mode 100644 terraform/cognitive-services/cognitive-deployment/test/providers.tf create mode 100644 terraform/cognitive-services/cognitive-deployment/test/unit_test.go create mode 100644 terraform/cognitive-services/cognitive-deployment/test/variables.tf create mode 100644 terraform/cognitive-services/cognitive-deployment/variables.tf diff --git a/.github/workflows/cognitive-services.yml b/.github/workflows/cognitive-services-account.yml similarity index 92% rename from .github/workflows/cognitive-services.yml rename to .github/workflows/cognitive-services-account.yml index f821721a..c03f5dd1 100644 --- a/.github/workflows/cognitive-services.yml +++ b/.github/workflows/cognitive-services-account.yml @@ -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: diff --git a/.github/workflows/cognitive-services-deployment.yml b/.github/workflows/cognitive-services-deployment.yml new file mode 100644 index 00000000..a9cb1d7e --- /dev/null +++ b/.github/workflows/cognitive-services-deployment.yml @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 5d055afe..38c591a2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/terraform/cognitive-services/README.md b/terraform/cognitive-services/cognitive-account/README.md similarity index 100% rename from terraform/cognitive-services/README.md rename to terraform/cognitive-services/cognitive-account/README.md diff --git a/terraform/cognitive-services/main.tf b/terraform/cognitive-services/cognitive-account/main.tf similarity index 100% rename from terraform/cognitive-services/main.tf rename to terraform/cognitive-services/cognitive-account/main.tf diff --git a/terraform/cognitive-services/outputs.tf b/terraform/cognitive-services/cognitive-account/outputs.tf similarity index 100% rename from terraform/cognitive-services/outputs.tf rename to terraform/cognitive-services/cognitive-account/outputs.tf diff --git a/terraform/cognitive-services/test/cognitive_services.tf b/terraform/cognitive-services/cognitive-account/test/cognitive_account.tf similarity index 83% rename from terraform/cognitive-services/test/cognitive_services.tf rename to terraform/cognitive-services/cognitive-account/test/cognitive_account.tf index a19dfe73..971311c8 100644 --- a/terraform/cognitive-services/test/cognitive_services.tf +++ b/terraform/cognitive-services/cognitive-account/test/cognitive_account.tf @@ -1,4 +1,4 @@ -module "cognitive_services" { +module "cognitive_account" { source = "../" basename = random_string.postfix.result resource_group_name = module.local_rg.name @@ -12,14 +12,14 @@ 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 @@ -27,7 +27,7 @@ module "local_vnet" { } 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 @@ -35,7 +35,7 @@ module "local_snet_default" { } 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 diff --git a/terraform/cognitive-services/test/locals.tf b/terraform/cognitive-services/cognitive-account/test/locals.tf similarity index 81% rename from terraform/cognitive-services/test/locals.tf rename to terraform/cognitive-services/cognitive-account/test/locals.tf index 66ffa0ad..bef67fda 100644 --- a/terraform/cognitive-services/test/locals.tf +++ b/terraform/cognitive-services/cognitive-account/test/locals.tf @@ -1,7 +1,7 @@ locals { tags = { Project = "Azure/azure-data-labs-modules" - Module = "cognitive-services" + Module = "cognitive-account" Toolkit = "Terraform" } diff --git a/terraform/cognitive-services/cognitive-account/test/outputs.tf b/terraform/cognitive-services/cognitive-account/test/outputs.tf new file mode 100644 index 00000000..c6fda489 --- /dev/null +++ b/terraform/cognitive-services/cognitive-account/test/outputs.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-account/test/providers.tf b/terraform/cognitive-services/cognitive-account/test/providers.tf new file mode 100644 index 00000000..7e170671 --- /dev/null +++ b/terraform/cognitive-services/cognitive-account/test/providers.tf @@ -0,0 +1,19 @@ +terraform { + backend "azurerm" { + resource_group_name = "rg-adl-terraform-state" + storage_account_name = "stadlterraformstate" + container_name = "default" + key = "cognitiveaccount.terraform.tfstate" + } + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.61.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/terraform/cognitive-services/test/unit_test.go b/terraform/cognitive-services/cognitive-account/test/unit_test.go similarity index 100% rename from terraform/cognitive-services/test/unit_test.go rename to terraform/cognitive-services/cognitive-account/test/unit_test.go diff --git a/terraform/cognitive-services/test/variables.tf b/terraform/cognitive-services/cognitive-account/test/variables.tf similarity index 100% rename from terraform/cognitive-services/test/variables.tf rename to terraform/cognitive-services/cognitive-account/test/variables.tf diff --git a/terraform/cognitive-services/variables.tf b/terraform/cognitive-services/cognitive-account/variables.tf similarity index 100% rename from terraform/cognitive-services/variables.tf rename to terraform/cognitive-services/cognitive-account/variables.tf diff --git a/terraform/cognitive-services/cognitive-deployment/main.tf b/terraform/cognitive-services/cognitive-deployment/main.tf new file mode 100644 index 00000000..c3c8be04 --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/main.tf @@ -0,0 +1,19 @@ +# 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 + + tags = var.tags + + count = var.module_enabled ? 1 : 0 +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/outputs.tf b/terraform/cognitive-services/cognitive-deployment/outputs.tf new file mode 100644 index 00000000..ad3497ad --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/outputs.tf @@ -0,0 +1,23 @@ +output "id" { + value = ( + length(azurerm_cognitive_deployment.adl_cog) > 0 ? + azurerm_cognitive_deployment.adl_cog[0].id : "" + ) + description = "Resource identifier of the instance of Cognitive Deployment." +} + +output "name" { + value = ( + length(azurerm_cognitive_deployment.adl_cog) > 0 ? + azurerm_cognitive_deployment.adl_cog[0].name : "" + ) + description = "The name of the Cognitive Deployment." +} + +output "resource_group_name" { + value = ( + length(azurerm_cognitive_deployment.adl_cog) > 0 ? + azurerm_cognitive_deployment.adl_cog[0].resource_group_name : "" + ) + description = "Resource Group where the Cognitive Deployment exists." +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/test/cognitive_deployment.tf b/terraform/cognitive-services/cognitive-deployment/test/cognitive_deployment.tf new file mode 100644 index 00000000..6c62ec08 --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/test/cognitive_deployment.tf @@ -0,0 +1,53 @@ +module "cognitive_deployment" { + source = "../" + basename = random_string.postfix.result + cognitive_account_id = module.cognitive_account.id + model_format = "OpenAI" + model_name = "text-ada-001" + model_version = "1" + scale_type = "Standard" + tags = {} +} + +# Module dependencies + +module "cognitive_account" { + source = "../../cognitive-account" + basename = random_string.postfix.result + resource_group_name = module.local_rg.name + location = var.location + kind = "OpenAI" + subnet_id = module.local_snet_default.id + private_dns_zone_ids = [module.local_pdnsz_cog.list[local.dns_cog].id] + tags = {} +} + +module "local_rg" { + source = "../../../resource-group" + basename = random_string.postfix.result + location = var.location + tags = local.tags +} + +module "local_vnet" { + 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" + 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" + resource_group_name = module.local_rg.name + dns_zones = [local.dns_cog] + vnet_id = module.local_vnet.id +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/test/locals.tf b/terraform/cognitive-services/cognitive-deployment/test/locals.tf new file mode 100644 index 00000000..38b4f99f --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/test/locals.tf @@ -0,0 +1,9 @@ +locals { + tags = { + Project = "Azure/azure-data-labs-modules" + Module = "cognitive-deployment" + Toolkit = "Terraform" + } + + dns_cog = "privatelink.cognitiveservices.azure.com" +} \ No newline at end of file diff --git a/terraform/cognitive-services/test/outputs.tf b/terraform/cognitive-services/cognitive-deployment/test/outputs.tf similarity index 100% rename from terraform/cognitive-services/test/outputs.tf rename to terraform/cognitive-services/cognitive-deployment/test/outputs.tf diff --git a/terraform/cognitive-services/cognitive-deployment/test/providers.tf b/terraform/cognitive-services/cognitive-deployment/test/providers.tf new file mode 100644 index 00000000..f97f9a77 --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/test/providers.tf @@ -0,0 +1,19 @@ +terraform { + backend "azurerm" { + resource_group_name = "rg-adl-terraform-state" + storage_account_name = "stadlterraformstate" + container_name = "default" + key = "cognitivedeployment.terraform.tfstate" + } + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.61.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/test/unit_test.go b/terraform/cognitive-services/cognitive-deployment/test/unit_test.go new file mode 100644 index 00000000..9e155ee8 --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/test/unit_test.go @@ -0,0 +1,36 @@ +package test + +import ( + "testing" + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestModule(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + TerraformDir: "./", + Lock: true, + LockTimeout: "1800s", + // VarFiles: []string{"terraform_unitest.tfvars"}, + } + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer terraform.Destroy(t, terraformOptions) + + // Is used mainly for debugging, fail early if plan is not possible + terraform.InitAndPlan(t, terraformOptions) + + // This will run `terraform init` and `terraform apply` and fail the test if there are any errors + terraform.InitAndApply(t, terraformOptions) + + // Check if the outputs exist + assert := assert.New(t) + id := terraform.Output(t, terraformOptions, "id") + assert.NotNil(id) + name := terraform.Output(t, terraformOptions, "name") + assert.NotNil(name) + resource_group_name := terraform.Output(t, terraformOptions, "resource_group_name") + assert.NotNil(resource_group_name) +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/test/variables.tf b/terraform/cognitive-services/cognitive-deployment/test/variables.tf new file mode 100644 index 00000000..b025435b --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/test/variables.tf @@ -0,0 +1,10 @@ +resource "random_string" "postfix" { + length = 8 + special = false + upper = false +} + +variable "location" { + type = string + default = "North Europe" +} \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/variables.tf b/terraform/cognitive-services/cognitive-deployment/variables.tf new file mode 100644 index 00000000..d8282ab8 --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/variables.tf @@ -0,0 +1,55 @@ +variable "basename" { + type = string + description = "Basename of the module." + validation { + condition = can(regex("^[-\\w]{1,60}$", var.basename)) && can(regex("[\\w]+$", var.basename)) + error_message = "The name must be between 1 and 60 characters, must only contain alphanumeric characters and hyphens, and cannot end with a hyphen." + } +} + +variable "cognitive_account_id" { + type = string + description = "The ID of the Cognitive Services Account. Changing this forces a new resource to be created." +} + +variable "model_format" { + type = string + description = "The format of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. Possible value is OpenAI." + validation { + condition = contains(["openai"], lower(var.model_format)) + error_message = "Valid values for model_format is \"OpenAI\"." + } + default = "OpenAI" +} + +variable "model_name" { + type = string + description = "The name of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created." +} + +variable "model_version" { + type = string + description = "The version of Cognitive Services Account Deployment model." +} + +variable "scale_type" { + type = string + description = "TDeployment scale type. Possible value is Standard. Changing this forces a new resource to be created." + validation { + condition = contains(["standard"], lower(var.scale_type)) + error_message = "Valid values for scale_type is \"Standard\"." + } + default = "Standard" +} + +variable "tags" { + type = map(string) + default = {} + description = "A mapping of tags which should be assigned to the deployed resource." +} + +variable "module_enabled" { + type = bool + description = "Variable to enable or disable the module." + default = true +} \ No newline at end of file From 7334715877589197e13137a05044e8f8e617dbaa Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 15:39:59 +0000 Subject: [PATCH 02/13] fmt --- terraform/cognitive-services/cognitive-deployment/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/cognitive-services/cognitive-deployment/main.tf b/terraform/cognitive-services/cognitive-deployment/main.tf index c3c8be04..ce514ff4 100644 --- a/terraform/cognitive-services/cognitive-deployment/main.tf +++ b/terraform/cognitive-services/cognitive-deployment/main.tf @@ -1,8 +1,8 @@ # 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 + name = "cog-dpl-${var.basename}" + cognitive_account_id = var.cognitive_account_id model { format = var.model_format name = var.model_name From db685a5f32b24d0b2b5a78fbba09c4a69abe14eb Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 15:40:19 +0000 Subject: [PATCH 03/13] codespaces container --- .devcontainer/devcontainer.json | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..bced4c77 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" +} From 4dda91a8698a336465341a05a7485913def47e8d Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 15:48:36 +0000 Subject: [PATCH 04/13] fix pe reference --- terraform/cognitive-services/cognitive-account/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/cognitive-services/cognitive-account/main.tf b/terraform/cognitive-services/cognitive-account/main.tf index 7d4d014f..c166e76d 100644 --- a/terraform/cognitive-services/cognitive-account/main.tf +++ b/terraform/cognitive-services/cognitive-account/main.tf @@ -26,7 +26,7 @@ resource "azurerm_cognitive_account" "adl_cog" { } module "cog_pe" { - source = "../private-endpoint" + source = "../../private-endpoint" basename = "${azurerm_cognitive_account.adl_cog[0].name}-cog" resource_group_name = var.resource_group_name location = var.location From 4c4b9e58dfeb72f129099c7046889635e345e4ca Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 15:57:07 +0000 Subject: [PATCH 05/13] fix output --- .../cognitive-services/cognitive-deployment/test/outputs.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/terraform/cognitive-services/cognitive-deployment/test/outputs.tf b/terraform/cognitive-services/cognitive-deployment/test/outputs.tf index 9231606e..cffa9d79 100644 --- a/terraform/cognitive-services/cognitive-deployment/test/outputs.tf +++ b/terraform/cognitive-services/cognitive-deployment/test/outputs.tf @@ -1,11 +1,11 @@ output "id" { - value = module.cognitive_services.id + value = module.cognitive_deployment.id } output "name" { - value = module.cognitive_services.name + value = module.cognitive_deployment.name } output "resource_group_name" { - value = module.cognitive_services.resource_group_name + value = module.cognitive_deployment.resource_group_name } \ No newline at end of file From 40d8a529c2ef1bc9bb792b16765e2c7c0fbc791b Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 16:12:12 +0000 Subject: [PATCH 06/13] fix output --- .../cognitive-services/cognitive-account/main.tf | 6 +++--- .../cognitive-services/cognitive-account/outputs.tf | 12 ++++++------ .../cognitive-deployment/outputs.tf | 12 ++++++------ .../cognitive-deployment/variables.tf | 6 ++++++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/terraform/cognitive-services/cognitive-account/main.tf b/terraform/cognitive-services/cognitive-account/main.tf index c166e76d..b9a79bdf 100644 --- a/terraform/cognitive-services/cognitive-account/main.tf +++ b/terraform/cognitive-services/cognitive-account/main.tf @@ -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 @@ -27,11 +27,11 @@ resource "azurerm_cognitive_account" "adl_cog" { module "cog_pe" { source = "../../private-endpoint" - basename = "${azurerm_cognitive_account.adl_cog[0].name}-cog" + 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 diff --git a/terraform/cognitive-services/cognitive-account/outputs.tf b/terraform/cognitive-services/cognitive-account/outputs.tf index 2c96bbc6..ea8b5f96 100644 --- a/terraform/cognitive-services/cognitive-account/outputs.tf +++ b/terraform/cognitive-services/cognitive-account/outputs.tf @@ -1,23 +1,23 @@ output "id" { value = ( - length(azurerm_cognitive_account.adl_cog) > 0 ? - azurerm_cognitive_account.adl_cog[0].id : "" + 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) > 0 ? - azurerm_cognitive_account.adl_cog[0].name : "" + 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) > 0 ? - azurerm_cognitive_account.adl_cog[0].resource_group_name : "" + 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." } \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/outputs.tf b/terraform/cognitive-services/cognitive-deployment/outputs.tf index ad3497ad..768c48d2 100644 --- a/terraform/cognitive-services/cognitive-deployment/outputs.tf +++ b/terraform/cognitive-services/cognitive-deployment/outputs.tf @@ -1,23 +1,23 @@ output "id" { value = ( - length(azurerm_cognitive_deployment.adl_cog) > 0 ? - azurerm_cognitive_deployment.adl_cog[0].id : "" + 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) > 0 ? - azurerm_cognitive_deployment.adl_cog[0].name : "" + length(azurerm_cognitive_deployment.adl_cog_dpl) > 0 ? + azurerm_cognitive_deployment.adl_cog_dpl[0].name : "" ) description = "The name of the Cognitive Deployment." } output "resource_group_name" { value = ( - length(azurerm_cognitive_deployment.adl_cog) > 0 ? - azurerm_cognitive_deployment.adl_cog[0].resource_group_name : "" + length(azurerm_cognitive_deployment.adl_cog_dpl) > 0 ? + azurerm_cognitive_deployment.adl_cog_dpl[0].resource_group_name : "" ) description = "Resource Group where the Cognitive Deployment exists." } \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/variables.tf b/terraform/cognitive-services/cognitive-deployment/variables.tf index d8282ab8..dd53febb 100644 --- a/terraform/cognitive-services/cognitive-deployment/variables.tf +++ b/terraform/cognitive-services/cognitive-deployment/variables.tf @@ -42,6 +42,12 @@ variable "scale_type" { default = "Standard" } +variable "rai_policy_name" { + type = string + description = "The name of RAI policy. Changing this forces a new resource to be created." + default = null +} + variable "tags" { type = map(string) default = {} From aea85b533df94ffc1307846a2021549b46bec825 Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Fri, 16 Jun 2023 16:39:50 +0000 Subject: [PATCH 07/13] remove tags --- terraform/cognitive-services/cognitive-deployment/main.tf | 2 -- 1 file changed, 2 deletions(-) diff --git a/terraform/cognitive-services/cognitive-deployment/main.tf b/terraform/cognitive-services/cognitive-deployment/main.tf index ce514ff4..d14c2aad 100644 --- a/terraform/cognitive-services/cognitive-deployment/main.tf +++ b/terraform/cognitive-services/cognitive-deployment/main.tf @@ -13,7 +13,5 @@ resource "azurerm_cognitive_deployment" "adl_cog_dpl" { } rai_policy_name = var.rai_policy_name - tags = var.tags - count = var.module_enabled ? 1 : 0 } \ No newline at end of file From 3111f1f479850e5607fb7a02140e67e167c4da5e Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Mon, 19 Jun 2023 07:58:54 +0000 Subject: [PATCH 08/13] rm output --- .../cognitive-services/cognitive-deployment/outputs.tf | 8 -------- .../cognitive-deployment/test/outputs.tf | 4 ---- 2 files changed, 12 deletions(-) diff --git a/terraform/cognitive-services/cognitive-deployment/outputs.tf b/terraform/cognitive-services/cognitive-deployment/outputs.tf index 768c48d2..47fda0f6 100644 --- a/terraform/cognitive-services/cognitive-deployment/outputs.tf +++ b/terraform/cognitive-services/cognitive-deployment/outputs.tf @@ -12,12 +12,4 @@ output "name" { azurerm_cognitive_deployment.adl_cog_dpl[0].name : "" ) description = "The name of the Cognitive Deployment." -} - -output "resource_group_name" { - value = ( - length(azurerm_cognitive_deployment.adl_cog_dpl) > 0 ? - azurerm_cognitive_deployment.adl_cog_dpl[0].resource_group_name : "" - ) - description = "Resource Group where the Cognitive Deployment exists." } \ No newline at end of file diff --git a/terraform/cognitive-services/cognitive-deployment/test/outputs.tf b/terraform/cognitive-services/cognitive-deployment/test/outputs.tf index cffa9d79..f0d67aa6 100644 --- a/terraform/cognitive-services/cognitive-deployment/test/outputs.tf +++ b/terraform/cognitive-services/cognitive-deployment/test/outputs.tf @@ -4,8 +4,4 @@ output "id" { output "name" { value = module.cognitive_deployment.name -} - -output "resource_group_name" { - value = module.cognitive_deployment.resource_group_name } \ No newline at end of file From 5e81cda66f4b4cb15409c1efb5ae4cc7af9b71fa Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Mon, 19 Jun 2023 07:59:02 +0000 Subject: [PATCH 09/13] rm test provider --- .../cognitive-services/test/providers.tf | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 terraform/cognitive-services/test/providers.tf diff --git a/terraform/cognitive-services/test/providers.tf b/terraform/cognitive-services/test/providers.tf deleted file mode 100644 index c9651524..00000000 --- a/terraform/cognitive-services/test/providers.tf +++ /dev/null @@ -1,19 +0,0 @@ -terraform { - backend "azurerm" { - resource_group_name = "rg-adl-terraform-state" - storage_account_name = "stadlterraformstate" - container_name = "default" - key = "cognitiveservices.terraform.tfstate" - } - - required_providers { - azurerm = { - source = "hashicorp/azurerm" - version = "= 3.61.0" - } - } -} - -provider "azurerm" { - features {} -} \ No newline at end of file From bba3460cdb502885f180852d0407ac6916827697 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 19 Jun 2023 08:12:51 +0000 Subject: [PATCH 10/13] terraform-docs: automated action --- terraform/cognitive-services/cognitive-account/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/cognitive-services/cognitive-account/README.md b/terraform/cognitive-services/cognitive-account/README.md index ee7761e2..a51ded17 100644 --- a/terraform/cognitive-services/cognitive-account/README.md +++ b/terraform/cognitive-services/cognitive-account/README.md @@ -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 From c05080e401c3bfac7fa65de2b38395ef03d1e817 Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Mon, 19 Jun 2023 08:33:40 +0000 Subject: [PATCH 11/13] change to westeurope for service availabiltiy --- .../cognitive-services/cognitive-deployment/test/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/cognitive-services/cognitive-deployment/test/variables.tf b/terraform/cognitive-services/cognitive-deployment/test/variables.tf index b025435b..da40f6a4 100644 --- a/terraform/cognitive-services/cognitive-deployment/test/variables.tf +++ b/terraform/cognitive-services/cognitive-deployment/test/variables.tf @@ -6,5 +6,5 @@ resource "random_string" "postfix" { variable "location" { type = string - default = "North Europe" + default = "West Europe" } \ No newline at end of file From a840c65be113d2a8ee924b0adddf8a2ef9903e5c Mon Sep 17 00:00:00 2001 From: Jorge Docampo Date: Mon, 19 Jun 2023 10:21:00 +0000 Subject: [PATCH 12/13] rm rg output --- .../cognitive-services/cognitive-deployment/test/unit_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/terraform/cognitive-services/cognitive-deployment/test/unit_test.go b/terraform/cognitive-services/cognitive-deployment/test/unit_test.go index 9e155ee8..745e336a 100644 --- a/terraform/cognitive-services/cognitive-deployment/test/unit_test.go +++ b/terraform/cognitive-services/cognitive-deployment/test/unit_test.go @@ -31,6 +31,4 @@ func TestModule(t *testing.T) { assert.NotNil(id) name := terraform.Output(t, terraformOptions, "name") assert.NotNil(name) - resource_group_name := terraform.Output(t, terraformOptions, "resource_group_name") - assert.NotNil(resource_group_name) } \ No newline at end of file From b30ba7d0fe630d5a61cc1dd31230ad717771739a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 19 Jun 2023 10:32:20 +0000 Subject: [PATCH 13/13] terraform-docs: automated action --- .../cognitive-deployment/README.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 terraform/cognitive-services/cognitive-deployment/README.md diff --git a/terraform/cognitive-services/cognitive-deployment/README.md b/terraform/cognitive-services/cognitive-deployment/README.md new file mode 100644 index 00000000..9c6e62bc --- /dev/null +++ b/terraform/cognitive-services/cognitive-deployment/README.md @@ -0,0 +1,28 @@ + +## 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 | +|------|-------------|------|---------|:--------:| +| [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes | +| [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 | +| [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 | +| [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 | +| [model\_version](#input\_model\_version) | The version of Cognitive Services Account Deployment model. | `string` | n/a | yes | +| [scale\_type](#input\_scale\_type) | TDeployment scale type. Possible value is Standard. Changing this forces a new resource to be created. | `string` | `"Standard"` | no | +| [rai\_policy\_name](#input\_rai\_policy\_name) | The name of RAI policy. Changing this forces a new resource to be created. | `string` | `null` | no | +| [tags](#input\_tags) | A mapping of tags which should be assigned to the deployed resource. | `map(string)` | `{}` | no | +| [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | Resource identifier of the instance of Cognitive Deployment. | +| [name](#output\_name) | The name of the Cognitive Deployment. | + \ No newline at end of file