@@ -36,7 +36,7 @@ func resourceOkeClusterHelmReleaseDiff(c context.Context, d *schema.ResourceDiff
3636 // Add DRY_RUN = true if there is a Helm Artifact in pipeline
3737 // and trigger a deployment
3838 if isHelmArtifactInPipeline (devopsClient , deployParams .deployPipelineId ) {
39-
39+ checkPipelineForHydrationWorkRequest ( deployParams . deployPipelineId , m )
4040 deploymentArguments := deployParams .deploymentArguments
4141
4242 if len (deploymentArguments ) > 0 {
@@ -64,8 +64,10 @@ func resourceOkeClusterHelmReleaseDiff(c context.Context, d *schema.ResourceDiff
6464 }}},
6565 }
6666 case "SINGLE_STAGE_DEPLOYMENT" :
67+ log .Printf ("[WARN] Creating a single stage deployment with deploy stage id %s" , deployParams .deployStageId )
6768 deploymentDetails = oci_devops.CreateSingleDeployStageDeploymentDetails {
6869 DeployPipelineId : & deployParams .deployPipelineId ,
70+ DeployStageId : & deployParams .deployStageId ,
6971 DisplayName : & deploymentName ,
7072 DeploymentArguments : & oci_devops.DeploymentArgumentCollection {Items : []oci_devops.DeploymentArgument {oci_devops.DeploymentArgument {Name : common .String ("DRY_RUN" ),
7173 Value : common .String ("true" ),
@@ -77,11 +79,13 @@ func resourceOkeClusterHelmReleaseDiff(c context.Context, d *schema.ResourceDiff
7779 }
7880 if deployParams .deploymentType == "SINGLE_STAGE_DEPLOYMENT" || deployParams .deploymentType == "PIPELINE_DEPLOYMENT" {
7981 // API call for deployment
82+ log .Printf ("[WARN] Deployment Details %s" , deploymentDetails )
8083 req := oci_devops.CreateDeploymentRequest {CreateDeploymentDetails : deploymentDetails }
8184 resp , _ := devopsClient .CreateDeployment (context .Background (), req )
8285
8386 // Get API Deployment call for querying status
8487 request := oci_devops.GetDeploymentRequest {}
88+ log .Printf ("[WARN] Deployment request %s" , request )
8589 request .DeploymentId = resp .GetId ()
8690 deploymentResponse , _ := devopsClient .GetDeployment (context .Background (), request )
8791 status := deploymentResponse .GetLifecycleState ()
@@ -229,6 +233,30 @@ func extractDeploymentParameters(d *schema.ResourceDiff) *DeploymentParams {
229233
230234}
231235
236+ func checkPipelineForHydrationWorkRequest (pipelineId string , m interface {}) {
237+ common .Debugf ("checkPipelineForHydrationWorkRequest: enter, pipelineId=%v\n " , pipelineId )
238+
239+ getDeployPipelineRequest := oci_devops.GetDeployPipelineRequest {}
240+ listWorkRequestsRequest := oci_devops.ListWorkRequestsRequest {}
241+ devOpsClient := m .(* client.OracleClients ).DevopsClient ()
242+
243+ listWorkRequestsRequest .ResourceId = & pipelineId
244+ getDeployPipelineRequest .DeployPipelineId = & pipelineId
245+ // Get the compartment id from the Pipeline
246+ common .Debugf ("checkPipelineForHydrationWorkRequest: getDeployPipelineRequest= %v\n " , getDeployPipelineRequest )
247+ getDeployPipelineResponse , err := devOpsClient .GetDeployPipeline (context .Background (), getDeployPipelineRequest )
248+ if err != nil {
249+ common .Debugf ("checkPipelineForHydrationWorkRequest: getDeployPipelineResponse err= %v\n " , err )
250+ } else {
251+ common .Debugf ("checkPipelineForHydrationWorkRequest: getDeployPipelineResponse.OpcRequestId= %v\n " , * getDeployPipelineResponse .OpcRequestId )
252+ deployPipeline := getDeployPipelineResponse .DeployPipeline
253+ listWorkRequestsRequest .CompartmentId = deployPipeline .CompartmentId
254+ }
255+
256+ waitForHydrationWorkRequest (listWorkRequestsRequest , devOpsClient )
257+ common .Debugf ("checkPipelineForHydrationWorkRequest: exit" )
258+ }
259+
232260func checkForHydrationWorkRequest (d * schema.ResourceData , m interface {}) {
233261 common .Debugf ("checkForHydrationWorkRequest: enter, ResourceData= %v\n " , d )
234262
@@ -258,15 +286,20 @@ func checkForHydrationWorkRequest(d *schema.ResourceData, m interface{}) {
258286 listWorkRequestsRequest .CompartmentId = deployPipeline .CompartmentId
259287 }
260288 }
261-
289+ waitForHydrationWorkRequest (listWorkRequestsRequest , devOpsClient )
290+ common .Debugf ("checkForHydrationWorkRequest: exit" )
291+ }
292+ func waitForHydrationWorkRequest (listWorkRequestsRequest oci_devops.ListWorkRequestsRequest , devOpsClient * oci_devops.DevopsClient ) {
262293 common .Debugf ("checkForHydrationWorkRequest: listWorkRequestsRequest= %v\n " , listWorkRequestsRequest )
263294 if listWorkRequestsRequest .CompartmentId != nil {
264295 workRequestInProgress := true
265296 // Wait until all hydration work requests for the pipeline are complete.
266- workRequestInProgressLoop:
267297 for workRequestInProgress {
268298 workRequestInProgress = false
299+ InProgress:
300+ log .Printf (" InProgress Block Execution" )
269301 listWorkRequestsResponse , err := devOpsClient .ListWorkRequests (context .Background (), listWorkRequestsRequest )
302+ common .Debugf ("checkForHydrationWorkRequest: listWorkRequestsResponse= %v\n " , listWorkRequestsResponse )
270303 if err != nil {
271304 // If we can't list the work requests, we'll just continue with the deployment.
272305 common .Debugf ("checkForHydrationWorkRequest: listWorkRequestResponse err= %v\n " , err )
@@ -278,11 +311,11 @@ func checkForHydrationWorkRequest(d *schema.ResourceData, m interface{}) {
278311 if len (workRequestCollection .Items ) > 0 {
279312 common .Debugf ("checkForHydrationWorkRequest: workRequestCollection.Items= %i\n " , len (workRequestCollection .Items ))
280313 for i , summary := range workRequestCollection .Items {
281- if ! (* summary . PercentComplete > 99.0 || summary .Status == "SUCCEEDED" || summary .Status == "FAILED" ||
314+ if ! (summary .Status == "SUCCEEDED" || summary .Status == "FAILED" ||
282315 summary .Status == "CANCELED" || summary .Status == "NEEDS_ATTENTION" ) {
283316 workRequestInProgress = true
284317 common .Debugf ("checkForHydrationWorkRequest: WorkRequestSummary found in progress= %i %v\n " , i , summary )
285- break workRequestInProgressLoop
318+ goto InProgress
286319 }
287320 }
288321 }
@@ -306,5 +339,4 @@ func checkForHydrationWorkRequest(d *schema.ResourceData, m interface{}) {
306339 }
307340 }
308341 }
309- common .Debugf ("checkForHydrationWorkRequest: exit" )
310342}
0 commit comments