Skip to content

Commit

Permalink
fix(app): #40505 fixed name bug with openapi definition
Browse files Browse the repository at this point in the history
Modified the reimportOpenAPIDefinition to make consistent the name in input. The original behavior was altered by the resourceAPIRead that would cause to change the name (and the version) of the ApiGateway at the creation state.
  • Loading branch information
Hugo Joubert authored and Hugo Joubert committed Dec 27, 2024
1 parent a1c56f2 commit 5ee5088
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/service/apigatewayv2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func resourceAPIRead(ctx context.Context, d *schema.ResourceData, meta interface
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

output, err := findAPIByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] API Gateway v2 API (%s) not found, removing from state", d.Id())
d.SetId("")
Expand Down Expand Up @@ -271,7 +270,6 @@ func resourceAPIRead(ctx context.Context, d *schema.ResourceData, meta interface
func resourceAPIUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

corsConfigurationDeleted := false
if d.HasChange("cors_configuration") {
if v := d.Get("cors_configuration"); len(v.([]interface{})) == 0 {
Expand Down Expand Up @@ -377,18 +375,18 @@ func reimportOpenAPIDefinition(ctx context.Context, d *schema.ResourceData, meta
if err != nil {
return fmt.Errorf("reimporting API Gateway v2 API (%s) OpenAPI definition: %w", d.Id(), err)
}

corsConfiguration := d.Get("cors_configuration")

apiName := d.Get(names.AttrName).(string)
versionInput := d.Get(names.AttrVersion).(string)
if diags := resourceAPIRead(ctx, d, meta); diags.HasError() {
return sdkdiag.DiagnosticsError(diags)
}

inputU := &apigatewayv2.UpdateApiInput{
ApiId: aws.String(d.Id()),
Name: aws.String(d.Get(names.AttrName).(string)),
Name: aws.String(apiName),
Description: aws.String(d.Get(names.AttrDescription).(string)),
Version: aws.String(d.Get(names.AttrVersion).(string)),
Version: aws.String(versionInput),
}

if !reflect.DeepEqual(corsConfiguration, d.Get("cors_configuration")) {
Expand Down Expand Up @@ -429,7 +427,6 @@ func findAPIByID(ctx context.Context, conn *apigatewayv2.Client, id string) (*ap

func findAPI(ctx context.Context, conn *apigatewayv2.Client, input *apigatewayv2.GetApiInput) (*apigatewayv2.GetApiOutput, error) {
output, err := conn.GetApi(ctx, input)

if errs.IsA[*awstypes.NotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
Expand Down

0 comments on commit 5ee5088

Please sign in to comment.