Skip to content

Commit

Permalink
test(flink): fix application version flakiness (#1406)
Browse files Browse the repository at this point in the history
(cherry picked from commit eaa7300)
  • Loading branch information
Serpentiel committed Oct 25, 2023
1 parent 16008ee commit 31f8250
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions internal/sdkprovider/service/flink/flink_application_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 31f8250

Please sign in to comment.