Skip to content

Commit bf19998

Browse files
update ai translation app policies
1 parent bc95b83 commit bf19998

File tree

10 files changed

+105
-34
lines changed

10 files changed

+105
-34
lines changed

ai-hub/ai-translation/policies/terraform/api_gateway.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ resource "oci_apigateway_deployment" "ai_application_apigateway_deployment" {
4040
type = "OAUTH2"
4141
use_cookies_for_intermediate_steps = "true"
4242
use_cookies_for_session = "true"
43+
max_expiry_duration_in_hours = 1
4344
}
4445
validation_policy {
4546
additional_validation_policy {

ai-hub/ai-translation/policies/terraform/container_instances.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "oci_container_instances_container_instance" "ai_container_instance" {
44
compartment_id = var.vcn_compartment_id
55
containers {
66
#Required
7-
image_url = local.image
7+
image_url = local.container_image
88

99
#Optional
1010
environment_variables = {
@@ -16,7 +16,7 @@ resource "oci_container_instances_container_instance" "ai_container_instance" {
1616
NUM_WORKERS = var.num_workers
1717
TASK_STORE = "TMPDIR"
1818
LOG_DIR = var.translation_log_dir
19-
PROJECT_COMPARTMENT_OCID = var.compartment_ocid
19+
PROJECT_COMPARTMENT_OCID = var.data_science_project_compartment_id
2020
PROCESSING_JOB_OCID = oci_datascience_job.ai_job.id
2121
OCI_CACHE_ENDPOINT = var.oci_cache_endpoint
2222
BACKEND_MD_URL = oci_datascience_model_deployment.ai_deployment.model_deployment_url

ai-hub/ai-translation/policies/terraform/datascience_job.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "oci_datascience_job" "ai_job" {
33
# Required
44
display_name = var.job_display_name
55
description = local.job_desc
6-
compartment_id = var.compartment_ocid
6+
compartment_id = var.data_science_project_compartment_id
77
project_id = var.project_ocid
88

99
job_configuration_details {
@@ -31,8 +31,8 @@ resource "oci_datascience_job" "ai_job" {
3131
job_environment_type = "OCIR_CONTAINER"
3232
image = local.image
3333
# image_digest = local.digest
34-
entrypoint = local.job_entrypoint
35-
cmd = local.job_cmd
34+
entrypoint = local.job_entrypoint
35+
cmd = local.job_cmd
3636
}
3737

3838
# Logging

ai-hub/ai-translation/policies/terraform/identity_app.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resource "oci_identity_domains_app" "ai_application_confidential_app" {
1414
bypass_consent = true
1515
allowed_grants = ["authorization_code", "client_credentials", "urn:ietf:params:oauth:grant-type:jwt-bearer", "implicit"]
1616
all_url_schemes_allowed = true
17-
redirect_uris = ["https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/","https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/playground", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/docs", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/"]
17+
redirect_uris = ["https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/playground", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/docs", "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/ui/"]
1818
post_logout_redirect_uris = ["https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/"]
1919
audience = oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname
2020
}

ai-hub/ai-translation/policies/terraform/model.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ data "archive_file" "model_zip" {
2727

2828
# dummy Model catalog entry with artifact
2929
resource "oci_datascience_model" "ai_model" {
30-
compartment_id = var.compartment_ocid
30+
compartment_id = var.data_science_project_compartment_id
3131
project_id = var.project_ocid
32-
display_name = var.model_display_name
32+
display_name = var.model_display_name
3333
description = local.model_desc
3434

3535
# Upload artifact inline (ZIP created above)

ai-hub/ai-translation/policies/terraform/model_deployment.tf

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "oci_datascience_model_deployment" "ai_deployment" {
33
# Required
44
display_name = var.deployment_display_name
55
description = local.md_desc
6-
compartment_id = var.compartment_ocid
6+
compartment_id = var.data_science_project_compartment_id
77
project_id = var.project_ocid
88

99
model_deployment_configuration_details {
@@ -29,7 +29,7 @@ resource "oci_datascience_model_deployment" "ai_deployment" {
2929
}
3030

3131
environment_configuration_details {
32-
image = local.image
32+
image = local.image
3333
# image_digest = local.digest
3434
environment_configuration_type = "OCIR_CONTAINER"
3535
# Environment variables are customized based on the AI app.
@@ -42,24 +42,38 @@ resource "oci_datascience_model_deployment" "ai_deployment" {
4242
NUM_WORKERS = var.num_workers
4343
TASK_STORE = "TMPDIR",
4444
LOG_DIR = var.translation_log_dir
45-
PROJECT_COMPARTMENT_OCID = var.compartment_ocid
45+
PROJECT_COMPARTMENT_OCID = var.data_science_project_compartment_id
4646
PROCESSING_JOB_OCID = oci_datascience_job.ai_job.id
4747
OCI_CACHE_ENDPOINT = var.oci_cache_endpoint
48-
MODEL_DEPLOY_CUSTOM_ENDPOINTS = "[{\"endpointURI\": \"/api/languages\", \"httpMethods\": [\"GET\"]}, {\"endpointURI\": \"/api/batch\", \"httpMethods\": [\"POST\"]}, {\"endpointURI\": \"/api/task\", \"httpMethods\": [\"GET\"]}, {\"endpointURI\": \"/api/translate\", \"httpMethods\": [\"GET\", \"POST\"]}, {\"endpointURI\": \"/api/translate\", \"httpMethods\": [\"POST\"], \"streaming\": true}]"
48+
MODEL_DEPLOY_CUSTOM_ENDPOINTS = "[{\"endpointURI\": \"/api/languages\", \"httpMethods\": [\"GET\"]}, {\"endpointURI\": \"/api/batch\", \"httpMethods\": [\"POST\"]}, {\"endpointURI\": \"/api/task\", \"httpMethods\": [\"GET\"]}, {\"endpointURI\": \"/api/translate\", \"httpMethods\": [\"GET\", \"POST\"]}, {\"endpointURI\": \"/api/translate\", \"httpMethods\": [\"POST\"], \"streaming\": true}, {\"endpointURI\": \"/mcp/\", \"httpMethods\": [\"POST\"], \"streaming\": true}]"
4949
}
5050
}
5151
}
5252

5353
# Logging, use the same log group and log ocid to reduce the variables.
54-
category_log_details {
55-
access {
56-
log_group_id = var.log_group_ocid
57-
log_id = var.log_ocid
58-
}
59-
predict {
60-
log_group_id = var.log_group_ocid
61-
log_id = var.log_ocid
54+
dynamic "category_log_details" {
55+
for_each = (
56+
var.log_group_ocid != null && var.log_ocid != "" &&
57+
var.log_group_ocid != null && var.log_ocid != ""
58+
) ? [1] : []
59+
60+
content {
61+
access {
62+
log_group_id = var.log_group_ocid
63+
log_id = var.log_ocid
64+
}
65+
predict {
66+
log_group_id = var.log_group_ocid
67+
log_id = var.log_ocid
68+
}
6269
}
6370
}
6471

72+
freeform_tags = {
73+
"ai-hub-solution-name" = "LLM based translation"
74+
"ai_solution_playground_url" = "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/"
75+
"ai_solution_mcp_endpoint" = "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/mcp"
76+
"ai_solution_api_endpoint_list_apis" = "https://${oci_apigateway_gateway.ai_application_oci_apigateway_gateway.hostname}/api/translate"
77+
}
78+
6579
}

ai-hub/ai-translation/policies/terraform/output.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ output "base_url" {
55

66
output "mcp_endpoint" {
77
description = "MCP Endpoint"
8-
value = "${oci_apigateway_deployment.ai_application_apigateway_deployment.endpoint}mcp"
8+
value = "${oci_datascience_model_deployment.ai_deployment.model_deployment_url}/predictWithResponseStream/mcp/"
99
}
1010

1111
output "playground_ui" {
@@ -25,15 +25,15 @@ output "api_schema" {
2525

2626
output "api_endpoint_default" {
2727
description = "API Endpoint - Translate"
28-
value = "${oci_apigateway_deployment.ai_application_apigateway_deployment.endpoint}api/translate"
28+
value = "${oci_datascience_model_deployment.ai_deployment.model_deployment_url}/predictWithResponseStream/api/translate"
2929
}
3030

3131
output "api_endpoint_batch" {
3232
description = "API Endpoint - Batch Translation Job"
33-
value = "${oci_apigateway_deployment.ai_application_apigateway_deployment.endpoint}api/batch"
33+
value = "${oci_datascience_model_deployment.ai_deployment.model_deployment_url}/predict/api/batch"
3434
}
3535

3636
output "api_endpoint_list_languages" {
3737
description = "API Endpoint - Supported Languages"
38-
value = "${oci_apigateway_deployment.ai_application_apigateway_deployment.endpoint}api/languages"
38+
value = "${oci_datascience_model_deployment.ai_deployment.model_deployment_url}/predict/api/languages"
3939
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "oci_identity_dynamic_group" "ai_solution_group" {
2+
compartment_id = var.tenancy_ocid
3+
description = "Dynamic Group for AI Solution"
4+
name = "ai_solution_group-${random_string.randomstring.result}"
5+
matching_rule = "any { all {resource.type='datasciencemodeldeployment',resource.compartment.id='${var.data_science_project_compartment_id}'}, all {resource.type='apigateway',resource.compartment.id='${var.compartment_ocid}'},all {resource.type='computecontainerinstance',resource.compartment.id='${var.vcn_compartment_id}'},all {resource.type='datasciencejobrun', resource.compartment.id='${var.data_science_project_compartment_id}'}}"
6+
}
7+
8+
locals {
9+
policies = [
10+
"allow service datascience to use virtual-network-family in compartment id ${var.vcn_compartment_id}",
11+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to manage secret-family in compartment id ${var.vault_compartment_id}",
12+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to use virtual-network-family in compartment id ${var.vcn_compartment_id}",
13+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to use logging-family in compartment id ${var.log_compartment_id}",
14+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to manage data-science-family in compartment id ${var.data_science_project_compartment_id}",
15+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to manage generative-ai-family in tenancy",
16+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to manage generative-ai-family in compartment id ${var.data_science_project_compartment_id}",
17+
"allow dynamic-group ${oci_identity_dynamic_group.ai_solution_group.name} to read repos in tenancy"
18+
]
19+
}
20+
21+
resource "oci_identity_policy" "ai_solution_policies" {
22+
compartment_id = "${var.tenancy_ocid}"
23+
description = "Dynamic group policies for AI Solution"
24+
name = "ai_solution_policies-${random_string.randomstring.result}"
25+
statements = local.policies
26+
depends_on = [oci_identity_dynamic_group.ai_solution_group]
27+
}

ai-hub/ai-translation/policies/terraform/schema.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ variableGroups:
1616
- vcn_display_name
1717
- deployment_type
1818
- model_display_name
19+
- shape
1920

2021
- title: "General Configuration"
2122
variables:
2223
- compartment_ocid
2324
- availability_domain
24-
- shape
25+
- data_science_project_compartment_id
2526
- project_ocid
27+
- log_compartment_id
2628
- log_group_ocid
2729
- log_ocid
2830
- title: "Application Configurations"
@@ -97,18 +99,30 @@ variables:
9799
title: Data Science Project
98100
description: The Data Science Project for creating model deployments and jobs.
99101
dependsOn:
100-
compartmentId: ${compartment_ocid}
102+
compartmentId: ${data_science_project_compartment_id}
103+
log_compartment_id:
104+
type: oci:identity:compartment:id
105+
required: false
106+
title: Logs Compartment Id
107+
description: Compartment in which Log Group and Logs are present.
108+
default: compartment_ocid
101109
log_group_ocid:
102110
type: string
103-
required: true
111+
required: false
104112
title: Log Group OCID
105113
description: Log Group OCID.
106114
log_ocid:
107115
type: string
108-
required: true
116+
required: false
109117
title: Log OCID
110118
description: Log OCID.
111119
# Application
120+
data_science_project_compartment_id:
121+
type: oci:identity:compartment:id
122+
required: true
123+
title: Data Science Project Compartment Id
124+
description: Compartment in which Data Science Project is present.
125+
default: compartment_ocid
112126
model_backend:
113127
type: enum
114128
required: true

ai-hub/ai-translation/policies/terraform/variables.tf

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,30 @@ variable "key_id" {
7777
default = "none"
7878
}
7979

80+
variable "data_science_project_compartment_id" {
81+
description = "Compartment in which Data Science Project is present"
82+
type = string
83+
}
84+
8085
variable "project_ocid" {
81-
type = string
86+
type = string
8287
description = "Data Science project in which resources needs to be created"
8388
}
8489

90+
variable "log_compartment_id" {
91+
description = "Compartment in which Logs are present"
92+
type = string
93+
}
94+
8595
variable "log_group_ocid" {
86-
default = "ocid1.loggroup.oc1.iad.amaaaaaav66vvniaidjweu7sgg5qgx7yzri5yb4xw3qnqsg6szl2xdh7scka"
96+
type = string
97+
description = "Log Group Ocid where logs will be stored"
98+
default = ""
8799
}
88100
variable "log_ocid" {
89-
default = "ocid1.log.oc1.iad.amaaaaaav66vvnia3h4o6otedz4lz23zex6z2pei6yjqszb7zdfswaa5srca"
101+
type = string
102+
description = "Log ocid where where logs needs to be stored"
103+
default = ""
90104
}
91105

92106
variable "shape" {
@@ -167,13 +181,14 @@ locals {
167181
app_subnet_id = (var.create_new_vcn ? oci_core_subnet.app_oci_core_subnet[0].id : var.existing_app_subnet_id)
168182
api_gw_subnet_id = (var.create_new_vcn ? oci_core_subnet.api_gw_oci_core_subnet[0].id : var.existing_api_gw_subnet_id)
169183

170-
image = "dsmc://ai-translation:0.1.0-dev.16"
171-
digest = "sha256:124f2834142305c3f53f63d0c3f8aa071b9180d50f1c8c17fbf66937f183804c"
184+
container_image = "iad.ocir.io/id1ytzpctjnn/dsmc/aisolution/ai_translation:0.1.0"
185+
image = "dsmc://ai_translation:0.1.0"
186+
digest = "sha256:381d884387b7015eb02c7eb7c4d4e9d125249befd2a425f0811cf282d47065ae"
172187
job_desc = "Job for batch translation"
173188
job_entrypoint = ["python"]
174189
job_cmd = ["/opt/app/batch.py"]
175190
md_desc = "Deployment for AI translation Application"
176-
model_desc = "Data Science Model for AI Translation Deployment"
191+
model_desc = "Data Science Model for AI Translation Deployment"
177192
}
178193

179194

0 commit comments

Comments
 (0)