Skip to content

Commit a1bbaf0

Browse files
Shrey Kapoorvsin12
authored andcommitted
Added - Support for BDS - On Demand Bootstrap script execution (Only existing API changes)
1 parent effc106 commit a1bbaf0

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

examples/big_data_service/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ variable "bds_instance_state" {
114114
default = "ACTIVE"
115115
}
116116

117+
data "oci_core_services" "test_bds_services" {
118+
}
119+
117120
#Uncomment this when running in home region (PHX)
118121
#variable "tag_namespace_description" {
119122
# default = "Just a test"
@@ -155,6 +158,30 @@ resource "oci_core_vcn" "vcn_bds" {
155158
dns_label = "bdsvcn"
156159
}
157160

161+
resource "oci_core_service_gateway" "export_sgw" {
162+
compartment_id = var.compartment_id
163+
display_name = "sgw"
164+
165+
services {
166+
service_id = data.oci_core_services.test_bds_services.services[0]["id"]
167+
}
168+
169+
vcn_id = oci_core_vcn.vcn_bds.id
170+
}
171+
172+
resource "oci_core_route_table" "private_rt" {
173+
compartment_id = var.compartment_id
174+
display_name = "private-rt"
175+
176+
route_rules {
177+
destination = data.oci_core_services.test_bds_services.services[0]["cidr_block"]
178+
destination_type = "SERVICE_CIDR_BLOCK"
179+
network_entity_id = oci_core_service_gateway.export_sgw.id
180+
}
181+
182+
vcn_id = oci_core_vcn.vcn_bds.id
183+
}
184+
158185
resource "oci_core_subnet" "regional_subnet_bds" {
159186
cidr_block = "111.111.0.0/24"
160187
display_name = "regionalSubnetBds"
@@ -177,6 +204,7 @@ resource "oci_bds_bds_instance" "test_bds_instance" {
177204
is_secure = var.bds_instance_is_secure
178205
kms_key_id = var.kms_key_id
179206
cluster_profile = var.cluster_profile
207+
bootstrap_script_url = "https://objectstorage.us-ashburn-1.oraclecloud.com/p/5M6CdCgyfNKcMGvdSIdK20tC9TAf0mVFkMsSlMdmmCaKusIX3DVixBS-_oDhJoxi/n/oraclebigdatadb/b/bootstrap-script-sdk-test/o/bootstrapScriptTemplate1bootstrapScript1.sh"
180208

181209
master_node {
182210
#Required

internal/integrationtest/bds_odh_instance_resource_test.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var (
6060
"master_node": acctest.RepresentationGroup{RepType: acctest.Required, Group: bdsInstanceNodeFlexShapeRepresentation},
6161
"util_node": acctest.RepresentationGroup{RepType: acctest.Required, Group: bdsInstanceNodeFlexShapeRepresentation},
6262
"worker_node": acctest.RepresentationGroup{RepType: acctest.Required, Group: bdsInstanceNodesOdhWorkerRepresentation},
63-
"bootstrap_script_url": acctest.Representation{RepType: acctest.Optional, Create: `${var.bootstrap_script_url}`},
63+
"bootstrap_script_url": acctest.Representation{RepType: acctest.Optional, Create: `${var.bootstrap_script_url}`, Update: `${var.bootstrap_script_urlU}`},
6464
"compute_only_worker_node": acctest.RepresentationGroup{RepType: acctest.Required, Group: bdsInstanceNodeFlexShapeRepresentation},
6565
"edge_node": acctest.RepresentationGroup{RepType: acctest.Required, Group: bdsInstanceNodeFlexShapeRepresentation},
6666

@@ -167,6 +167,9 @@ func TestResourceBdsOdhInstance(t *testing.T) {
167167
bootstrapScriptUrl := utils.GetEnvSettingWithBlankDefault("bootstrap_script_url")
168168
bootstrapScriptUrlVariableStr := fmt.Sprintf("variable \"bootstrap_script_url\" { default = \"%s\" }\n", bootstrapScriptUrl)
169169

170+
bootstrapScriptUrlU := utils.GetEnvSettingWithBlankDefault("bootstrap_script_urlU")
171+
bootstrapScriptUrlUVariableStr := fmt.Sprintf("variable \"bootstrap_script_urlU\" { default = \"%s\" }\n", bootstrapScriptUrlU)
172+
170173
resourceName := "oci_bds_bds_instance.test_bds_instance"
171174
datasourceName := "data.oci_bds_bds_instances.test_bds_instances"
172175
singularDatasourceName := "data.oci_bds_bds_instance.test_bds_instance"
@@ -177,10 +180,42 @@ func TestResourceBdsOdhInstance(t *testing.T) {
177180
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Optional, acctest.Create, bdsInstanceOdhRepresentation), "bds", "bdsInstanceOdh", t)
178181

179182
acctest.ResourceTest(t, testAccCheckBdsBdsInstanceOdhDestroy, []resource.TestStep{
180-
// verify Create, cluster will be force stopped after create
183+
184+
// verify Create with required fields
181185
{
182186
Config: config + compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies + bootstrapScriptUrlVariableStr +
183-
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Required, acctest.Create,
187+
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Required, acctest.Create, bdsInstanceOdhRepresentation),
188+
Check: resource.ComposeAggregateTestCheckFunc(
189+
resource.TestCheckResourceAttr(resourceName, "cluster_admin_password", "T3JhY2xlVGVhbVVTQSExMjM="),
190+
resource.TestCheckResourceAttrSet(resourceName, "cluster_public_key"),
191+
resource.TestCheckResourceAttr(resourceName, "cluster_version", "ODH1"),
192+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
193+
resource.TestCheckResourceAttr(resourceName, "is_high_availability", "true"),
194+
resource.TestCheckResourceAttr(resourceName, "is_secure", "true"),
195+
resource.TestCheckResourceAttr(resourceName, "nodes.#", "11"),
196+
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.node_type"),
197+
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.shape"),
198+
resource.TestCheckResourceAttrSet(resourceName, "nodes.0.subnet_id"),
199+
200+
func(s *terraform.State) (err error) {
201+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
202+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
203+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
204+
return errExport
205+
}
206+
}
207+
return err
208+
},
209+
),
210+
},
211+
// delete before next Create
212+
{
213+
Config: config + compartmentIdVariableStr + BdsInstanceOdhResourceDependencies + bootstrapScriptUrlVariableStr,
214+
},
215+
// verify Create, cluster will be force stopped after create
216+
{
217+
Config: config + compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies + bootstrapScriptUrlVariableStr + bootstrapScriptUrlUVariableStr +
218+
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Optional, acctest.Create,
184219
acctest.RepresentationCopyWithNewProperties(bdsInstanceOdhRepresentation, map[string]interface{}{
185220
"is_force_stop_jobs": acctest.Representation{RepType: acctest.Required, Create: `true`},
186221
"state": acctest.Representation{RepType: acctest.Required, Create: `INACTIVE`},
@@ -207,8 +242,8 @@ func TestResourceBdsOdhInstance(t *testing.T) {
207242

208243
// start the cluster
209244
{
210-
Config: config + compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies + bootstrapScriptUrlVariableStr +
211-
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Required, acctest.Create,
245+
Config: config + compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies + bootstrapScriptUrlVariableStr + bootstrapScriptUrlUVariableStr +
246+
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Optional, acctest.Create,
212247
acctest.RepresentationCopyWithNewProperties(bdsInstanceOdhRepresentation, map[string]interface{}{
213248
"is_force_stop_jobs": acctest.Representation{RepType: acctest.Required, Create: `true`},
214249
"state": acctest.Representation{RepType: acctest.Required, Create: `ACTIVE`},
@@ -335,7 +370,7 @@ func TestResourceBdsOdhInstance(t *testing.T) {
335370

336371
// verify updates to updatable parameters, add a worker, update compute worker flex->regular, update util regular -> flex
337372
{
338-
Config: config + compartmentIdVariableStr + kmsKeyIdUVariableStr + bootstrapScriptUrlVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies +
373+
Config: config + compartmentIdVariableStr + kmsKeyIdUVariableStr + bootstrapScriptUrlVariableStr + bootstrapScriptUrlUVariableStr + subnetIdVariableStr + BdsInstanceOdhResourceDependencies +
339374
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Optional, acctest.Update, bdsInstanceOdhWithRegularComputeAndFlexMasterUtilRepresentation),
340375
Check: resource.ComposeAggregateTestCheckFunc(
341376
resource.TestCheckResourceAttr(resourceName, "cluster_admin_password", "T3JhY2xlVGVhbVVTQSExMjM="),
@@ -384,7 +419,7 @@ func TestResourceBdsOdhInstance(t *testing.T) {
384419
{
385420
Config: config +
386421
acctest.GenerateDataSourceFromRepresentationMap("oci_bds_bds_instances", "test_bds_instances", acctest.Optional, acctest.Update, bdsInstanceOdhDataSourceRepresentation) +
387-
compartmentIdVariableStr + kmsKeyIdUVariableStr + subnetIdVariableStr + bootstrapScriptUrlVariableStr + BdsInstanceOdhResourceDependencies +
422+
compartmentIdVariableStr + kmsKeyIdUVariableStr + subnetIdVariableStr + bootstrapScriptUrlVariableStr + bootstrapScriptUrlUVariableStr + BdsInstanceOdhResourceDependencies +
388423
acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Optional, acctest.Update, bdsInstanceOdhWithRegularComputeAndFlexMasterUtilRepresentation),
389424
Check: resource.ComposeAggregateTestCheckFunc(
390425
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
@@ -409,7 +444,7 @@ func TestResourceBdsOdhInstance(t *testing.T) {
409444
{
410445
Config: config +
411446
acctest.GenerateDataSourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Required, acctest.Create, bdsInstanceOdhSingularDataSourceRepresentation) +
412-
compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + kmsKeyIdUVariableStr + bootstrapScriptUrlVariableStr + BdsInstanceOdhWithRegularComputeWorkerResourceConfig,
447+
compartmentIdVariableStr + kmsKeyIdVariableStr + subnetIdVariableStr + kmsKeyIdUVariableStr + bootstrapScriptUrlVariableStr + bootstrapScriptUrlUVariableStr + BdsInstanceOdhWithRegularComputeWorkerResourceConfig,
413448
Check: resource.ComposeAggregateTestCheckFunc(
414449
resource.TestCheckResourceAttrSet(singularDatasourceName, "bds_instance_id"),
415450

internal/service/bds/bds_bds_instance_resource.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,11 @@ func (s *BdsBdsInstanceResourceCrud) Update() error {
12621262
}
12631263
}
12641264

1265+
err := s.ExecuteBootstrapScript()
1266+
if err != nil {
1267+
return err
1268+
}
1269+
12651270
if compartment, ok := s.D.GetOkExists("compartment_id"); ok && s.D.HasChange("compartment_id") {
12661271
oldRaw, newRaw := s.D.GetChange("compartment_id")
12671272
if newRaw != "" && oldRaw != "" {
@@ -1717,6 +1722,36 @@ func (s *BdsBdsInstanceResourceCrud) StopBdsInstance() error {
17171722
return tfresource.WaitForResourceCondition(s, retentionPolicyFunc, s.D.Timeout(schema.TimeoutUpdate))
17181723
}
17191724

1725+
func (s *BdsBdsInstanceResourceCrud) ExecuteBootstrapScript() error {
1726+
request := oci_bds.ExecuteBootstrapScriptRequest{}
1727+
1728+
idTmp := s.D.Id()
1729+
request.BdsInstanceId = &idTmp
1730+
1731+
if bootstrapScriptUrl, ok := s.D.GetOkExists("bootstrap_script_url"); ok {
1732+
tmp := bootstrapScriptUrl.(string)
1733+
request.BootstrapScriptUrl = &tmp
1734+
}
1735+
1736+
if clusterAdminPassword, ok := s.D.GetOkExists("cluster_admin_password"); ok {
1737+
tmp := clusterAdminPassword.(string)
1738+
request.ClusterAdminPassword = &tmp
1739+
}
1740+
1741+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "bds")
1742+
1743+
response, err := s.Client.ExecuteBootstrapScript(context.Background(), request)
1744+
if err != nil {
1745+
return err
1746+
}
1747+
1748+
if waitErr := tfresource.WaitForUpdatedState(s.D, s); waitErr != nil {
1749+
return waitErr
1750+
}
1751+
1752+
workId := response.OpcWorkRequestId
1753+
return s.getBdsInstanceFromWorkRequest(workId, tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "bds"), oci_bds.ActionTypesUpdated, s.D.Timeout(schema.TimeoutUpdate))
1754+
}
17201755
func (s *BdsBdsInstanceResourceCrud) deleteShapeConfigIfMissingInInput(node_type string, node_map map[string]interface{}) {
17211756
if _, ok := s.D.GetOkExists(node_type); ok {
17221757
fieldKey := fmt.Sprintf("%s.%d.%s", node_type, 0, "shape_config")

0 commit comments

Comments
 (0)