Skip to content

Commit

Permalink
Merge pull request #508 from microsoft/ryonsteele/terraform-conversion
Browse files Browse the repository at this point in the history
Conversion from BICEP to Terraform - Part 1
  • Loading branch information
dayland committed Feb 27, 2024
2 parents 7d280dc + f7daac0 commit e4c80ab
Show file tree
Hide file tree
Showing 87 changed files with 4,436 additions and 3,637 deletions.
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ RUN /tmp/docker-client.sh $USERNAME
RUN git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1 \
&& echo "if [ -f \"$HOME/.bash-git-prompt/gitprompt.sh\" ]; then GIT_PROMPT_ONLY_IN_REPO=1 && source $HOME/.bash-git-prompt/gitprompt.sh; fi" >> "/home/$USERNAME/.bashrc"

# terraform + tflint
ARG TERRAFORM_VERSION=1.3.7
ARG TFLINT_VERSION=0.44.1
RUN mkdir -p /tmp/docker-downloads \
&& curl -sSL -o /tmp/docker-downloads/terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& unzip /tmp/docker-downloads/terraform.zip \
&& mv terraform /usr/local/bin \
&& rm /tmp/docker-downloads/terraform.zip \
&& echo "alias tf=terraform" >> "/home/$USERNAME/.bashrc"

RUN curl -sSL -o /tmp/docker-downloads/tflint.zip https://github.com/wata727/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip \
&& unzip /tmp/docker-downloads/tflint.zip \
&& mv tflint /usr/local/bin \
&& rm /tmp/docker-downloads/tflint.zip

# azure-cli
COPY ./scripts/azure-cli.sh /tmp/
RUN /tmp/azure-cli.sh
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"ms-azuretools.vscode-azureresourcegroups",
"ms-azuretools.vscode-azurefunctions",
"ms-python.python",
"ms-python.pylint"
"ms-python.pylint",
"HashiCorp.terraform"
],

"remoteUser": "vscode"
Expand Down
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ main.parameters.json
infrastructure.env
infrastructure.debug.env
infra_output.json
inf_output.json
random.txt
.state

Expand All @@ -385,4 +386,12 @@ app/backend/shared_code
packages-microsoft*

# docker container build artifacts
app/enrichment/shared_code
app/enrichment/shared_code

#terraform
.terraform
infra/.terraform*
terraform.tfstate
terraform.tfstate.d
.tfplan.txt
infra/infoasst*
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ infrastructure: check-subscription ## Deploy infrastructure
@./scripts/inf-create.sh

extract-env: extract-env-debug-webapp extract-env-debug-functions ## Extract infrastructure.env file from BICEP output
@./scripts/json-to-env.sh < infra_output.json > ./scripts/environments/infrastructure.env
@./scripts/json-to-env.sh < inf_output.json > ./scripts/environments/infrastructure.env

deploy-webapp: extract-env ## Deploys the web app code to Azure App Service
@./scripts/deploy-webapp.sh
Expand All @@ -40,10 +40,10 @@ deploy-search-indexes: extract-env ## Deploy search indexes
@./scripts/deploy-search-indexes.sh

extract-env-debug-webapp: ## Extract infrastructure.debug.env file from BICEP output
@./scripts/json-to-env.webapp.debug.sh < infra_output.json > ./scripts/environments/infrastructure.debug.env
@./scripts/json-to-env.webapp.debug.sh < inf_output.json > ./scripts/environments/infrastructure.debug.env

extract-env-debug-functions: ## Extract local.settings.json to debug functions from BICEP output
@./scripts/json-to-env.function.debug.sh < infra_output.json > ./functions/local.settings.json
@./scripts/json-to-env.function.debug.sh < inf_output.json > ./functions/local.settings.json

# Utils (used by other Makefile rules)
check-subscription:
Expand All @@ -57,4 +57,4 @@ destroy-inf: check-subscription
@./scripts/inf-destroy.sh

functional-tests: extract-env ## Run functional tests to check the processing pipeline is working
@./scripts/functional-tests.sh
@./scripts/functional-tests.sh
7 changes: 4 additions & 3 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"AZURE_SEARCH_INDEX": "gptkbindex",
"AZURE_OPENAI_SERVICE": "myopenai",
"AZURE_OPENAI_RESOURCE_GROUP": "",
"AZURE_OPENAI_ENDPOINT": "",
"AZURE_OPENAI_CHATGPT_DEPLOYMENT": "gpt-35-turbo-16k",
"AZURE_OPENAI_CHATGPT_MODEL_NAME": "",
"AZURE_OPENAI_CHATGPT_MODEL_VERSION": "",
Expand Down Expand Up @@ -95,8 +96,8 @@

# Used by the OpenAI SDK
openai.api_type = "azure"
openai.api_base = "https://" + ENV["AZURE_OPENAI_SERVICE"] + ".openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_base = ENV["AZURE_OPENAI_ENDPOINT"]
openai.api_version = "2023-12-01-preview"

# Setup StatusLog to allow access to CosmosDB for logging
statusLog = StatusLog(
Expand Down Expand Up @@ -166,7 +167,7 @@
chat_approaches = {
Approaches.ReadRetrieveRead: ChatReadRetrieveReadApproach(
search_client,
ENV["AZURE_OPENAI_SERVICE"],
ENV["AZURE_OPENAI_ENDPOINT"],
ENV["AZURE_OPENAI_SERVICE_KEY"],
ENV["AZURE_OPENAI_CHATGPT_DEPLOYMENT"],
ENV["KB_FIELDS_SOURCEFILE"],
Expand Down
5 changes: 3 additions & 2 deletions app/backend/approaches/chatreadretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ChatReadRetrieveReadApproach(Approach):
def __init__(
self,
search_client: SearchClient,
oai_service_name: str,
oai_endpoint: str,
oai_service_key: str,
chatgpt_deployment: str,
source_file_field: str,
Expand Down Expand Up @@ -118,13 +118,14 @@ def __init__(
self.target_translation_language=target_translation_language
self.enrichment_endpoint=enrichment_endpoint
self.enrichment_key=enrichment_key
self.oai_endpoint=oai_endpoint

if is_gov_cloud_deployment:
self.embedding_service_url = f'https://{enrichment_appservice_name}.azurewebsites.us'
else:
self.embedding_service_url = f'https://{enrichment_appservice_name}.azurewebsites.net'

openai.api_base = 'https://' + oai_service_name + '.openai.azure.com/'
openai.api_base = oai_endpoint
openai.api_type = 'azure'
openai.api_key = oai_service_key

Expand Down
2 changes: 1 addition & 1 deletion app/enrichment/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
openai.api_base = "https://" + ENV["AZURE_OPENAI_SERVICE"] + ".openai.azure.com/"
openai.api_type = "azure"
openai.api_key = ENV["AZURE_OPENAI_SERVICE_KEY"]
openai.api_version = "2023-06-01-preview"
openai.api_version = "2023-12-01-preview"

class AzOAIEmbedding(object):
"""A wrapper for a Azure OpenAI Embedding model"""
Expand Down
5 changes: 2 additions & 3 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ If you have chosen to enable authentication and authorization for your deploymen
Once deployed, you can find the URL of your installation by:

1) Browse to your new Resource Group at https://portal.azure.com and locate the "App Service"
![Location of App Service in Portal](../docs/images/deployment_app_service_location.jpg)
![Location of App Service in Portal](./docs/images/deployment_app_service_location.jpg)

2) After clicking on the App Service, you will see the "Default domain" listed. This is the link to your installation.
![Default Domain of App Service in Portal](../docs/images/deployment_default_domain.jpg)
![Default Domain of App Service in Portal](./docs/images/deployment_default_domain.jpg)


## Next steps

At this point deployment is complete. Please go to the [Using the IA Accelerator for the first time](../README.md#using-ia-accelerator-for-the-first-time) section and complete the following steps.

146 changes: 0 additions & 146 deletions infra/abbreviations.json

This file was deleted.

68 changes: 68 additions & 0 deletions infra/arm_templates/video_indexer/avi.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "${arm_template_schema_mgmt_api}/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"metadata" : {
"description" : "The name of the AVAM resource"
},
"defaultValue": "avam-account"
},
"managedIdentityId": {
"type": "string",
"metadata" : {
"description" : "The managed identity used to grant access to the Azure Storage account"
},
"defaultValue": ""
},
"storageServicesResourceId": {
"type": "string",
"metadata" : {
"description" : "The Storage Account Id for storing uploaded videos. The Account needs to be created prior to the creation of this template"
},
"defaultValue" : ""
},
"tags": {
"type": "object",
"metadata" : {
"description" : "Arm Template Tags"
},
"defaultValue": {}
},
"apiVersion": {
"type": "string",
"metadata": {
"description": "Video indexer api version"
}
}
},
"resources": [
{
"type": "Microsoft.VideoIndexer/accounts",
"apiVersion": "[parameters('apiVersion')]",
"name": "[parameters('name')]",

"location": "[resourceGroup().location]",
"tags": "[parameters('tags')]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('managedIdentityId')]": {}
}
},
"properties": {
"storageServices": {
"resourceId": "[parameters('storageServicesResourceId')]",
"userAssignedIdentity": "[parameters('managedIdentityId')]"
}
}
}
],
"outputs": {
"avam_id": {
"value": "[reference(resourceId('Microsoft.VideoIndexer/accounts',parameters('name'))).accountId]",
"type": "string"
}
}
}
Loading

0 comments on commit e4c80ab

Please sign in to comment.