Skip to content

Commit 9b696c3

Browse files
Zhijin Wusagarp337
authored andcommitted
Added - Support for data science service to list fast launch job configs
1 parent 2c55e2e commit 9b696c3

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package integrationtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/terraform-providers/terraform-provider-oci/internal/acctest"
11+
"github.com/terraform-providers/terraform-provider-oci/internal/utils"
12+
13+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
14+
15+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
16+
)
17+
18+
var (
19+
fastLaunchJobConfigDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
}
22+
23+
FastLaunchJobConfigResourceConfig = ""
24+
)
25+
26+
// issue-routing-tag: datascience/default
27+
func TestDatascienceFastLaunchJobConfigResource_basic(t *testing.T) {
28+
httpreplay.SetScenario("TestDatascienceFastLaunchJobConfigResource_basic")
29+
defer httpreplay.SaveScenario()
30+
31+
config := acctest.ProviderTestConfig()
32+
33+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
34+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
35+
36+
datasourceName := "data.oci_datascience_fast_launch_job_configs.test_fast_launch_job_configs"
37+
38+
acctest.SaveConfigContent("", "", "", t)
39+
40+
acctest.ResourceTest(t, nil, []resource.TestStep{
41+
// verify datasource
42+
{
43+
Config: config +
44+
acctest.GenerateDataSourceFromRepresentationMap("oci_datascience_fast_launch_job_configs", "test_fast_launch_job_configs", acctest.Required, acctest.Create, fastLaunchJobConfigDataSourceRepresentation) +
45+
compartmentIdVariableStr + FastLaunchJobConfigResourceConfig,
46+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
47+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
48+
49+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.#"),
50+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.core_count"),
51+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.managed_egress_support"),
52+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.memory_in_gbs"),
53+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.name"),
54+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.shape_name"),
55+
resource.TestCheckResourceAttrSet(datasourceName, "fast_launch_job_configs.0.shape_series"),
56+
),
57+
},
58+
})
59+
}

internal/provider/register_datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ func init() {
553553
RegisterDatasource("oci_datascience_notebook_sessions", tf_datascience.DatascienceNotebookSessionsDataSource())
554554
RegisterDatasource("oci_datascience_project", tf_datascience.DatascienceProjectDataSource())
555555
RegisterDatasource("oci_datascience_projects", tf_datascience.DatascienceProjectsDataSource())
556+
RegisterDatasource("oci_datascience_fast_launch_job_configs", tf_datascience.DatascienceFastLaunchJobConfigsDataSource())
556557
// devops service
557558
RegisterDatasource("oci_devops_build_pipeline", tf_devops.DevopsBuildPipelineDataSource())
558559
RegisterDatasource("oci_devops_build_pipeline_stage", tf_devops.DevopsBuildPipelineStageDataSource())
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package datascience
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
10+
oci_datascience "github.com/oracle/oci-go-sdk/v56/datascience"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/internal/client"
13+
"github.com/terraform-providers/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func DatascienceFastLaunchJobConfigsDataSource() *schema.Resource {
17+
return &schema.Resource{
18+
Read: readDatascienceFastLaunchJobConfigs,
19+
Schema: map[string]*schema.Schema{
20+
"filter": tfresource.DataSourceFiltersSchema(),
21+
"compartment_id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
},
25+
"fast_launch_job_configs": {
26+
Type: schema.TypeList,
27+
Computed: true,
28+
Elem: &schema.Resource{
29+
Schema: map[string]*schema.Schema{
30+
// Required
31+
32+
// Optional
33+
34+
// Computed
35+
"core_count": {
36+
Type: schema.TypeInt,
37+
Computed: true,
38+
},
39+
"managed_egress_support": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
43+
"memory_in_gbs": {
44+
Type: schema.TypeInt,
45+
Computed: true,
46+
},
47+
"name": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
},
51+
"shape_name": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
},
55+
"shape_series": {
56+
Type: schema.TypeString,
57+
Computed: true,
58+
},
59+
},
60+
},
61+
},
62+
},
63+
}
64+
}
65+
66+
func readDatascienceFastLaunchJobConfigs(d *schema.ResourceData, m interface{}) error {
67+
sync := &DatascienceFastLaunchJobConfigsDataSourceCrud{}
68+
sync.D = d
69+
sync.Client = m.(*client.OracleClients).DataScienceClient()
70+
71+
return tfresource.ReadResource(sync)
72+
}
73+
74+
type DatascienceFastLaunchJobConfigsDataSourceCrud struct {
75+
D *schema.ResourceData
76+
Client *oci_datascience.DataScienceClient
77+
Res *oci_datascience.ListFastLaunchJobConfigsResponse
78+
}
79+
80+
func (s *DatascienceFastLaunchJobConfigsDataSourceCrud) VoidState() {
81+
s.D.SetId("")
82+
}
83+
84+
func (s *DatascienceFastLaunchJobConfigsDataSourceCrud) Get() error {
85+
request := oci_datascience.ListFastLaunchJobConfigsRequest{}
86+
87+
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
88+
tmp := compartmentId.(string)
89+
request.CompartmentId = &tmp
90+
}
91+
92+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "datascience")
93+
94+
response, err := s.Client.ListFastLaunchJobConfigs(context.Background(), request)
95+
if err != nil {
96+
return err
97+
}
98+
99+
s.Res = &response
100+
request.Page = s.Res.OpcNextPage
101+
102+
for request.Page != nil {
103+
listResponse, err := s.Client.ListFastLaunchJobConfigs(context.Background(), request)
104+
if err != nil {
105+
return err
106+
}
107+
108+
s.Res.Items = append(s.Res.Items, listResponse.Items...)
109+
request.Page = listResponse.OpcNextPage
110+
}
111+
112+
return nil
113+
}
114+
115+
func (s *DatascienceFastLaunchJobConfigsDataSourceCrud) SetData() error {
116+
if s.Res == nil {
117+
return nil
118+
}
119+
120+
s.D.SetId(tfresource.GenerateDataSourceHashID("DatascienceFastLaunchJobConfigsDataSource-", DatascienceFastLaunchJobConfigsDataSource(), s.D))
121+
resources := []map[string]interface{}{}
122+
123+
for _, r := range s.Res.Items {
124+
fastLaunchJobConfig := map[string]interface{}{}
125+
126+
if r.CoreCount != nil {
127+
fastLaunchJobConfig["core_count"] = *r.CoreCount
128+
}
129+
130+
fastLaunchJobConfig["managed_egress_support"] = r.ManagedEgressSupport
131+
132+
if r.MemoryInGBs != nil {
133+
fastLaunchJobConfig["memory_in_gbs"] = *r.MemoryInGBs
134+
}
135+
136+
if r.Name != nil {
137+
fastLaunchJobConfig["name"] = *r.Name
138+
}
139+
140+
if r.ShapeName != nil {
141+
fastLaunchJobConfig["shape_name"] = *r.ShapeName
142+
}
143+
144+
fastLaunchJobConfig["shape_series"] = r.ShapeSeries
145+
146+
resources = append(resources, fastLaunchJobConfig)
147+
}
148+
149+
if f, fOk := s.D.GetOkExists("filter"); fOk {
150+
resources = tfresource.ApplyFilters(f.(*schema.Set), resources, DatascienceFastLaunchJobConfigsDataSource().Schema["fast_launch_job_configs"].Elem.(*schema.Resource).Schema)
151+
}
152+
153+
if err := s.D.Set("fast_launch_job_configs", resources); err != nil {
154+
return err
155+
}
156+
157+
return nil
158+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
subcategory: "Data Science"
3+
layout: "oci"
4+
page_title: "Oracle Cloud Infrastructure: oci_datascience_fast_launch_job_configs"
5+
sidebar_current: "docs-oci-datasource-datascience-fast_launch_job_configs"
6+
description: |-
7+
Provides the list of Fast Launch Job Configs in Oracle Cloud Infrastructure Data Science service
8+
---
9+
10+
# Data Source: oci_datascience_fast_launch_job_configs
11+
This data source provides the list of Fast Launch Job Configs in Oracle Cloud Infrastructure Data Science service.
12+
13+
List fast launch capable job configs in the specified compartment.
14+
15+
## Example Usage
16+
17+
```hcl
18+
data "oci_datascience_fast_launch_job_configs" "test_fast_launch_job_configs" {
19+
#Required
20+
compartment_id = var.compartment_id
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `compartment_id` - (Required) <b>Filter</b> results by the [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment.
29+
30+
31+
## Attributes Reference
32+
33+
The following attributes are exported:
34+
35+
* `fast_launch_job_configs` - The list of fast_launch_job_configs.
36+
37+
### FastLaunchJobConfig Reference
38+
39+
The following attributes are exported:
40+
41+
* `core_count` - The number of cores associated with this fast launch job shape.
42+
* `managed_egress_support` - The managed egress support
43+
* `memory_in_gbs` - The number of cores associated with this fast launch job shape.
44+
* `name` - The name of the fast launch job config
45+
* `shape_name` - The name of the fast launch job shape.
46+
* `shape_series` - The family that the compute shape belongs to.
47+

0 commit comments

Comments
 (0)