From e6780795057b2aa1ea30d3cccef3947a704749b3 Mon Sep 17 00:00:00 2001 From: Gary Marjoram Date: Tue, 28 Nov 2023 15:18:51 +0000 Subject: [PATCH] CD Pipeline 404 retry --- .../resource_ibm_cd_tekton_pipeline.go | 18 +++++++++++++++++- ...source_ibm_cd_tekton_pipeline_definition.go | 18 +++++++++++++++++- ...resource_ibm_cd_tekton_pipeline_property.go | 18 +++++++++++++++++- .../resource_ibm_cd_tekton_pipeline_trigger.go | 18 +++++++++++++++++- ..._ibm_cd_tekton_pipeline_trigger_property.go | 18 +++++++++++++++++- 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go index 78e39e3861..f593f017e0 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline.go @@ -7,8 +7,10 @@ import ( "context" "fmt" "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" @@ -591,7 +593,21 @@ func resourceIBMCdTektonPipelineRead(context context.Context, d *schema.Resource getTektonPipelineOptions.SetID(d.Id()) - tektonPipeline, response, err := cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions) + var tektonPipeline *cdtektonpipelinev2.TektonPipeline + var response *core.DetailedResponse + err = resource.RetryContext(context, 10*time.Second, func() *resource.RetryError { + tektonPipeline, response, err = cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions) + if err != nil || tektonPipeline == nil { + if response != nil && response.StatusCode == 404 { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + if conns.IsResourceTimeoutError(err) { + tektonPipeline, response, err = cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions) + } if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go index fbd5ce3a4b..b94847e593 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_definition.go @@ -7,8 +7,10 @@ import ( "context" "fmt" "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" @@ -170,7 +172,21 @@ func resourceIBMCdTektonPipelineDefinitionRead(context context.Context, d *schem getTektonPipelineDefinitionOptions.SetPipelineID(parts[0]) getTektonPipelineDefinitionOptions.SetDefinitionID(parts[1]) - definition, response, err := cdTektonPipelineClient.GetTektonPipelineDefinitionWithContext(context, getTektonPipelineDefinitionOptions) + var definition *cdtektonpipelinev2.Definition + var response *core.DetailedResponse + err = resource.RetryContext(context, 10*time.Second, func() *resource.RetryError { + definition, response, err = cdTektonPipelineClient.GetTektonPipelineDefinitionWithContext(context, getTektonPipelineDefinitionOptions) + if err != nil || definition == nil { + if response != nil && response.StatusCode == 404 { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + if conns.IsResourceTimeoutError(err) { + definition, response, err = cdTektonPipelineClient.GetTektonPipelineDefinitionWithContext(context, getTektonPipelineDefinitionOptions) + } if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go index 0be5e231d2..03519b1a27 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_property.go @@ -7,8 +7,10 @@ import ( "context" "fmt" "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" @@ -181,7 +183,21 @@ func resourceIBMCdTektonPipelinePropertyRead(context context.Context, d *schema. getTektonPipelinePropertyOptions.SetPipelineID(parts[0]) getTektonPipelinePropertyOptions.SetPropertyName(parts[1]) - property, response, err := cdTektonPipelineClient.GetTektonPipelinePropertyWithContext(context, getTektonPipelinePropertyOptions) + var property *cdtektonpipelinev2.Property + var response *core.DetailedResponse + err = resource.RetryContext(context, 10*time.Second, func() *resource.RetryError { + property, response, err = cdTektonPipelineClient.GetTektonPipelinePropertyWithContext(context, getTektonPipelinePropertyOptions) + if err != nil || property == nil { + if response != nil && response.StatusCode == 404 { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + if conns.IsResourceTimeoutError(err) { + property, response, err = cdTektonPipelineClient.GetTektonPipelinePropertyWithContext(context, getTektonPipelinePropertyOptions) + } if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go index 319b4963ba..a2da942e1f 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger.go @@ -8,8 +8,10 @@ import ( "fmt" "log" "sort" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" @@ -438,7 +440,21 @@ func resourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema.R getTektonPipelineTriggerOptions.SetPipelineID(parts[0]) getTektonPipelineTriggerOptions.SetTriggerID(parts[1]) - triggerIntf, response, err := cdTektonPipelineClient.GetTektonPipelineTriggerWithContext(context, getTektonPipelineTriggerOptions) + var triggerIntf cdtektonpipelinev2.TriggerIntf + var response *core.DetailedResponse + err = resource.RetryContext(context, 10*time.Second, func() *resource.RetryError { + triggerIntf, response, err = cdTektonPipelineClient.GetTektonPipelineTriggerWithContext(context, getTektonPipelineTriggerOptions) + if err != nil || triggerIntf == nil { + if response != nil && response.StatusCode == 404 { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + if conns.IsResourceTimeoutError(err) { + triggerIntf, response, err = cdTektonPipelineClient.GetTektonPipelineTriggerWithContext(context, getTektonPipelineTriggerOptions) + } if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") diff --git a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go index 7de7108c3a..11f86f02b7 100644 --- a/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go +++ b/ibm/service/cdtektonpipeline/resource_ibm_cd_tekton_pipeline_trigger_property.go @@ -7,8 +7,10 @@ import ( "context" "fmt" "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" @@ -199,7 +201,21 @@ func resourceIBMCdTektonPipelineTriggerPropertyRead(context context.Context, d * getTektonPipelineTriggerPropertyOptions.SetTriggerID(parts[1]) getTektonPipelineTriggerPropertyOptions.SetPropertyName(parts[2]) - triggerProperty, response, err := cdTektonPipelineClient.GetTektonPipelineTriggerPropertyWithContext(context, getTektonPipelineTriggerPropertyOptions) + var triggerProperty *cdtektonpipelinev2.TriggerProperty + var response *core.DetailedResponse + err = resource.RetryContext(context, 10*time.Second, func() *resource.RetryError { + triggerProperty, response, err = cdTektonPipelineClient.GetTektonPipelineTriggerPropertyWithContext(context, getTektonPipelineTriggerPropertyOptions) + if err != nil || triggerProperty == nil { + if response != nil && response.StatusCode == 404 { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + if conns.IsResourceTimeoutError(err) { + triggerProperty, response, err = cdTektonPipelineClient.GetTektonPipelineTriggerPropertyWithContext(context, getTektonPipelineTriggerPropertyOptions) + } if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("")