Skip to content

Commit 2cbb9d1

Browse files
Qiumin ZhangManiteja-Kurapati
authored andcommitted
Added - Support for OCI Data Science - Model Explorer
1 parent 2fa663e commit 2cbb9d1

6 files changed

+191
-14
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package integrationtest
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"testing"
7+
8+
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
9+
10+
"github.com/oracle/terraform-provider-oci/internal/acctest"
11+
"github.com/oracle/terraform-provider-oci/internal/utils"
12+
13+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/terraform"
15+
16+
"github.com/oracle/terraform-provider-oci/httpreplay"
17+
)
18+
19+
var (
20+
// MD config consists of creating dependencies and generate MD config
21+
DatascienceModelDeploymentModelExplorerResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_datascience_model_deployment", "test_model_deployment", acctest.Optional, acctest.Create, DatascienceModelDeploymentModelExplorerRepresentation)
22+
DatascienceModelDeploymentModelExplorerRepresentation = map[string]interface{}{
23+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
24+
"model_deployment_configuration_details": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatascienceModelDeploymentModelExplorerModelDeploymentConfigurationDetailsRepresentation},
25+
"project_id": acctest.Representation{RepType: acctest.Required, Create: `${var.model_explorer_project_id}`},
26+
"description": acctest.Representation{RepType: acctest.Optional, Create: `description1`, Update: `description1`},
27+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName1`, Update: `displayName2`},
28+
}
29+
30+
// model deployment configuration details related.
31+
DatascienceModelDeploymentModelExplorerModelDeploymentConfigurationDetailsRepresentation = map[string]interface{}{
32+
"deployment_type": acctest.Representation{RepType: acctest.Required, Create: `SINGLE_MODEL`},
33+
"model_configuration_details": acctest.RepresentationGroup{RepType: acctest.Required, Group: ModelConfigurationDetailsRepresentation},
34+
}
35+
ModelConfigurationDetailsRepresentation = map[string]interface{}{
36+
"instance_configuration": acctest.RepresentationGroup{RepType: acctest.Required, Group: InstanceConfigurationRepresentation},
37+
"model_id": acctest.Representation{RepType: acctest.Required, Create: `${var.model_explorer_model_id}`},
38+
"bandwidth_mbps": acctest.Representation{RepType: acctest.Optional, Create: `10`},
39+
"maximum_bandwidth_mbps": acctest.Representation{RepType: acctest.Optional, Create: `10`},
40+
"scaling_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: DatascienceModelDeploymentModelDeploymentConfigurationDetailsModelConfigurationDetailsScalingPolicyRepresentation},
41+
}
42+
InstanceConfigurationRepresentation = map[string]interface{}{
43+
"subnet_id": acctest.Representation{RepType: acctest.Optional, Create: nil},
44+
"instance_shape_name": acctest.Representation{RepType: acctest.Required, Create: `VM.GPU.A10.1`},
45+
}
46+
)
47+
48+
func TestDatascienceModelDeploymentModelExplorerResource_basic(t *testing.T) {
49+
httpreplay.SetScenario("TestDatascienceModelDeploymentModelExplorerResource_basic")
50+
defer httpreplay.SaveScenario()
51+
52+
config := acctest.ProviderTestConfig()
53+
54+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
55+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
56+
57+
resourceName := "oci_datascience_model_deployment.test_model_deployment"
58+
singularDatasourceName := "data.oci_datascience_model_deployment.test_model_deployment"
59+
var resId string
60+
61+
acctest.ResourceTest(t, testAccCheckDatascienceModelDeploymentDestroy, []resource.TestStep{
62+
// verify create with optionals
63+
{
64+
Config: config + compartmentIdVariableStr +
65+
acctest.GenerateResourceFromRepresentationMap("oci_datascience_model_deployment", "test_model_deployment", acctest.Optional, acctest.Create, DatascienceModelDeploymentModelExplorerRepresentation),
66+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
67+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
68+
resource.TestCheckResourceAttrSet(resourceName, "created_by"),
69+
resource.TestCheckResourceAttr(resourceName, "description", "description1"),
70+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName1"),
71+
resource.TestCheckResourceAttrSet(resourceName, "id"),
72+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.#", "1"),
73+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.environment_configuration_details.#", "1"),
74+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.#", "1"),
75+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.bandwidth_mbps", "10"),
76+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.instance_configuration.#", "1"),
77+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.instance_configuration.0.instance_shape_name"),
78+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.model_id"),
79+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.#", "1"),
80+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.0.instance_count", "1"),
81+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.0.policy_type", "FIXED_SIZE"),
82+
resource.TestCheckResourceAttr(resourceName, "model_deployment_system_data.#", "1"),
83+
resource.TestCheckResourceAttr(resourceName, "model_deployment_system_data.0.model_type", "MANAGED_MODEL"),
84+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_url"),
85+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
86+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
87+
88+
func(s *terraform.State) (err error) {
89+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
90+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
91+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
92+
return errExport
93+
}
94+
}
95+
return err
96+
},
97+
),
98+
},
99+
100+
// verify singular datasource - get model deployment
101+
{
102+
Config: config +
103+
acctest.GenerateDataSourceFromRepresentationMap("oci_datascience_model_deployment", "test_model_deployment", acctest.Required, acctest.Create, DatascienceDatascienceModelDeploymentSingularDataSourceRepresentation) +
104+
compartmentIdVariableStr + DatascienceModelDeploymentModelExplorerResourceConfig,
105+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
106+
resource.TestCheckResourceAttrSet(singularDatasourceName, "model_deployment_id"),
107+
108+
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
109+
resource.TestCheckResourceAttrSet(singularDatasourceName, "created_by"),
110+
resource.TestCheckResourceAttr(singularDatasourceName, "description", "description1"),
111+
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "displayName1"),
112+
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
113+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.#", "1"),
114+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.environment_configuration_details.#", "1"),
115+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.#", "1"),
116+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.bandwidth_mbps", "10"),
117+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.instance_configuration.#", "1"),
118+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.instance_configuration.0.instance_shape_name"),
119+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.model_id"),
120+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.#", "1"),
121+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.0.instance_count", "1"),
122+
resource.TestCheckResourceAttr(resourceName, "model_deployment_configuration_details.0.model_configuration_details.0.scaling_policy.0.policy_type", "FIXED_SIZE"),
123+
resource.TestCheckResourceAttr(resourceName, "model_deployment_system_data.#", "1"),
124+
resource.TestCheckResourceAttr(resourceName, "model_deployment_system_data.0.model_type", "MANAGED_MODEL"),
125+
resource.TestCheckResourceAttrSet(resourceName, "model_deployment_url"),
126+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
127+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
128+
),
129+
},
130+
})
131+
}

internal/service/datascience/datascience_model_deployment_resource.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func DatascienceModelDeploymentResource() *schema.Resource {
2727
State: schema.ImportStatePassthrough,
2828
},
2929
Timeouts: &schema.ResourceTimeout{
30-
Create: &tfresource.TwentyMinutes,
31-
Update: &tfresource.ThirtyMinutes,
32-
Delete: &tfresource.TwentyMinutes,
30+
Create: tfresource.GetTimeoutDuration("245m"),
31+
Update: tfresource.GetTimeoutDuration("245m"),
32+
Delete: tfresource.GetTimeoutDuration("35m"),
3333
},
3434
Create: createDatascienceModelDeployment,
3535
Read: readDatascienceModelDeployment,
@@ -88,6 +88,13 @@ func DatascienceModelDeploymentResource() *schema.Resource {
8888
Type: schema.TypeString,
8989
},
9090
},
91+
"default_environment_variables": {
92+
Type: schema.TypeMap,
93+
Optional: true,
94+
Computed: true,
95+
ForceNew: true,
96+
Elem: schema.TypeString,
97+
},
9198
"entrypoint": {
9299
Type: schema.TypeList,
93100
Optional: true,
@@ -834,6 +841,10 @@ func DatascienceModelDeploymentResource() *schema.Resource {
834841
Type: schema.TypeInt,
835842
Computed: true,
836843
},
844+
"model_type": {
845+
Type: schema.TypeString,
846+
Computed: true,
847+
},
837848
"system_infra_type": {
838849
Type: schema.TypeString,
839850
Computed: true,
@@ -2474,6 +2485,8 @@ func ModelDeploymentSystemDataToMap(obj *oci_datascience.ModelDeploymentSystemDa
24742485
if v.CurrentInstanceCount != nil {
24752486
result["current_instance_count"] = int(*v.CurrentInstanceCount)
24762487
}
2488+
2489+
result["model_type"] = string(v.ModelType)
24772490
default:
24782491
log.Printf("[WARN] Received 'system_infra_type' of unknown type %v", *obj)
24792492
return nil

internal/service/datascience/datascience_model_deployments_data_source.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ func (s *DatascienceModelDeploymentsDataSourceCrud) SetData() error {
175175
modelDeployment["model_deployment_configuration_details"] = nil
176176
}
177177

178+
if r.ModelDeploymentSystemData != nil {
179+
modelDeploymentSystemDataArray := []interface{}{}
180+
if modelDeploymentSystemDataMap := ModelDeploymentSystemDataToMap(&r.ModelDeploymentSystemData); modelDeploymentSystemDataMap != nil {
181+
modelDeploymentSystemDataArray = append(modelDeploymentSystemDataArray, modelDeploymentSystemDataMap)
182+
}
183+
modelDeployment["model_deployment_system_data"] = modelDeploymentSystemDataArray
184+
} else {
185+
modelDeployment["model_deployment_system_data"] = nil
186+
}
187+
178188
if r.ModelDeploymentUrl != nil {
179189
modelDeployment["model_deployment_url"] = *r.ModelDeploymentUrl
180190
}

website/docs/d/datascience_model_deployment.html.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ The following attributes are exported:
5151
* `deployment_type` - The type of the model deployment.
5252
* `environment_configuration_details` - The configuration to carry the environment details thats used in Model Deployment creation
5353
* `cmd` - The container image run [CMD](https://docs.docker.com/engine/reference/builder/#cmd) as a list of strings. Use `CMD` as arguments to the `ENTRYPOINT` or the only command to run in the absence of an `ENTRYPOINT`. The combined size of `CMD` and `ENTRYPOINT` must be less than 2048 bytes.
54+
* `default_environment_variables` - Service injected Environment variables set for the web server container and can not be set or modified by user.
5455
* `entrypoint` - The container image run [ENTRYPOINT](https://docs.docker.com/engine/reference/builder/#entrypoint) as a list of strings. Accept the `CMD` as extra arguments. The combined size of `CMD` and `ENTRYPOINT` must be less than 2048 bytes. More information on how `CMD` and `ENTRYPOINT` interact are [here](https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact).
5556
* `environment_configuration_type` - The environment configuration type
5657
* `environment_variables` - Environment variables to set for the web server container. The size of envVars must be less than 2048 bytes. Key should be under 32 characters. Key should contain only letters, digits and underscore (_) Key should start with a letter. Key should have at least 2 characters. Key should not end with underscore eg. `TEST_` Key if added cannot be empty. Value can be empty. No specific size limits on individual Values. But overall environment variables is limited to 2048 bytes. Key can't be reserved Model Deployment environment variables.
5758
* `health_check_port` - The port on which the container [HEALTHCHECK](https://docs.docker.com/engine/reference/builder/#healthcheck) would listen. The port can be anything between `1024` and `65535`. The following ports cannot be used `24224`, `8446`, `8447`.
58-
* `image` - The full path to the Oracle Container Repository (OCIR) registry, image, and tag in a canonical format. Acceptable format: `<region>.ocir.io/<registry>/<image>:<tag>` `<region>.ocir.io/<registry>/<image>:<tag>@digest`
59+
* `image` - The full path to the Oracle Container Repository (OCIR) registry, image, and tag in a canonical format. The container image is optional while using service managed open source foundation model. Acceptable format: `<region>.ocir.io/<registry>/<image>:<tag>` `<region>.ocir.io/<registry>/<image>:<tag>@digest`
5960
* `image_digest` - The digest of the container image. For example, `sha256:881303a6b2738834d795a32b4a98eb0e5e3d1cad590a712d1e04f9b2fa90a030`
6061
* `server_port` - The port on which the web server serving the inference is running. The port can be anything between `1024` and `65535`. The following ports cannot be used `24224`, `8446`, `8447`.
6162
* `infrastructure_configuration_details` - The infrastructure configuration details.
6263
* `bandwidth_mbps` - The minimum network bandwidth for the model deployment.
6364
* `infrastructure_type` - The type of the model deployment infrastructure.
6465
* `instance_configuration` - The model deployment instance configuration.
65-
* `instance_shape_name` - The shape used to launch the model deployment instances.
66+
* `instance_shape_name` - The shape used to launch the model deployment instances. When using service managed open source foundation model, the supported shapes can be retrieved using get model api /models/{modelId}/definedMetadata/deploymentConfiguration/artifact/content.
6667
* `model_deployment_instance_shape_config_details` - Details for the model-deployment instance shape configuration.
6768
* `cpu_baseline` - The baseline OCPU utilization for a subcore burstable VM instance. If this attribute is left blank, it will default to `BASELINE_1_1`. The following values are supported: BASELINE_1_8 - baseline usage is 1/8 of an OCPU. BASELINE_1_2 - baseline usage is 1/2 of an OCPU. BASELINE_1_1 - baseline usage is an entire OCPU. This represents a non-burstable instance.
6869
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 to 512 GB and VM.Optimized3.Flex memory range is between 6 to 256 GB.
@@ -122,7 +123,7 @@ The following attributes are exported:
122123
* `model_configuration_details` - The model configuration details.
123124
* `bandwidth_mbps` - The minimum network bandwidth for the model deployment.
124125
* `instance_configuration` - The model deployment instance configuration.
125-
* `instance_shape_name` - The shape used to launch the model deployment instances.
126+
* `instance_shape_name` - The shape used to launch the model deployment instances. When using service managed open source foundation model, the supported shapes can be retrieved using get model api /models/{modelId}/definedMetadata/deploymentConfiguration/artifact/content.
126127
* `model_deployment_instance_shape_config_details` - Details for the model-deployment instance shape configuration.
127128
* `cpu_baseline` - The baseline OCPU utilization for a subcore burstable VM instance. If this attribute is left blank, it will default to `BASELINE_1_1`. The following values are supported: BASELINE_1_8 - baseline usage is 1/8 of an OCPU. BASELINE_1_2 - baseline usage is 1/2 of an OCPU. BASELINE_1_1 - baseline usage is an entire OCPU. This represents a non-burstable instance.
128129
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 to 512 GB and VM.Optimized3.Flex memory range is between 6 to 256 GB.
@@ -184,6 +185,7 @@ The following attributes are exported:
184185
* `model_group_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the model group you want to deploy.
185186
* `model_deployment_system_data` - Model deployment system data.
186187
* `current_instance_count` - This value is the current count of the model deployment instances.
188+
* `model_type` - The type of the deployed model.
187189
* `system_infra_type` - The infrastructure type of the model deployment.
188190
* `model_deployment_url` - The URL to interact with the model deployment.
189191
* `project_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the project associated with the model deployment.

0 commit comments

Comments
 (0)