From 31f82508f0c3d0e268fc20e466eef1a11c8e40db Mon Sep 17 00:00:00 2001 From: Aleksander Zaruczewski Date: Tue, 24 Oct 2023 02:22:16 -0400 Subject: [PATCH] test(flink): fix application version flakiness (#1406) (cherry picked from commit eaa7300d6119206e84cd63c5dcc7dcf8b6d293b6) --- .../flink/flink_application_version.go | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/internal/sdkprovider/service/flink/flink_application_version.go b/internal/sdkprovider/service/flink/flink_application_version.go index 9a6405697..25c9e10ca 100644 --- a/internal/sdkprovider/service/flink/flink_application_version.go +++ b/internal/sdkprovider/service/flink/flink_application_version.go @@ -2,9 +2,12 @@ package flink import ( "context" + "regexp" + "time" "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -186,13 +189,40 @@ func resourceFlinkApplicationVersionCreate(ctx context.Context, d *schema.Resour sinks = expandFlinkApplicationVersionSourcesOrSinks(d.Get("sink").(*schema.Set).List()) } - r, err := client.FlinkApplicationVersions.Create(ctx, project, serviceName, applicationID, aiven.GenericFlinkApplicationVersionRequest{ - Statement: d.Get("statement").(string), - Sources: sources, - Sinks: sinks, - }) - if err != nil { - return diag.Errorf("cannot create Flink Application Version: %+v - %v", expandFlinkApplicationVersionSourcesOrSinks(d.Get("sources").(*schema.Set).List()), err) + var r *aiven.DetailedFlinkApplicationVersionResponse + + if err := retry.RetryContext(ctx, time.Second*30, func() *retry.RetryError { + var err error + + r, err = client.FlinkApplicationVersions.Create( + ctx, + project, + serviceName, + applicationID, + aiven.GenericFlinkApplicationVersionRequest{ + Statement: d.Get("statement").(string), + Sources: sources, + Sinks: sinks, + }, + ) + if err != nil { + return &retry.RetryError{ + Err: err, + Retryable: regexp.MustCompile( + "Integration not found: " + + "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", + ).MatchString(err.Error()), + } + } + return nil + }); err != nil { + return diag.Errorf( + "cannot create Flink Application Version: %+v - %v", + expandFlinkApplicationVersionSourcesOrSinks( + d.Get("sources").(*schema.Set).List(), + ), + err, + ) } d.SetId(schemautil.BuildResourceID(project, serviceName, applicationID, r.ID))