Skip to content

Commit

Permalink
fix: always return in case of error, and require recreation if resour…
Browse files Browse the repository at this point in the history
…ce names change

OTT-6942
  • Loading branch information
thatsddr committed Jan 13, 2025
1 parent 0a45802 commit 6827da2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions awsmt/resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *resourceChannel) Schema(_ context.Context, _ resource.SchemaRequest, re
Attributes: map[string]schema.Attribute{
"id": computedString,
"arn": computedString,
"name": requiredString,
"name": requiredStringWithRequiresReplace,
// @ADR
// Context: We cannot test the deletion of a running channel if we cannot set the channel_state property
// through the provider
Expand Down Expand Up @@ -233,6 +233,7 @@ func (r *resourceChannel) Update(ctx context.Context, req resource.UpdateRequest
"Error while describing channel "+err.Error(),
err.Error(),
)
return
}

err = UpdatesTags(r.client, channel.Tags, plan.Tags, *channel.Arn)
Expand All @@ -241,6 +242,7 @@ func (r *resourceChannel) Update(ctx context.Context, req resource.UpdateRequest
"Error while updating channel tags"+err.Error(),
err.Error(),
)
return
}

previousState := channel.ChannelState
Expand All @@ -249,16 +251,18 @@ func (r *resourceChannel) Update(ctx context.Context, req resource.UpdateRequest
err = stopChannel(previousState, channelName, r.client)
if err != nil {
resp.Diagnostics.AddError(
"Error while stopping running channel "+*channelName+" "+err.Error(),
"Error while stopping to run channel "+*channelName+" "+err.Error(),
err.Error(),
)
return
}

if err := handlePolicyUpdate(ctx, r.client, plan); err != nil {
resp.Diagnostics.AddError(
"Error while updating channel policy "+err.Error(),
err.Error(),
)
return
}

updatedChannel, err := r.client.UpdateChannel(ctx, getUpdateChannelInput(plan))
Expand All @@ -267,6 +271,7 @@ func (r *resourceChannel) Update(ctx context.Context, req resource.UpdateRequest
"Error while updating channel "+*channel.ChannelName+" "+err.Error(),
err.Error(),
)
return
}

if shouldStartChannel(previousState, newState) {
Expand Down
2 changes: 2 additions & 0 deletions awsmt/resource_live_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (r *resourceLiveSource) Update(ctx context.Context, req resource.UpdateRequ
"Error while updating live source "+err.Error(),
err.Error(),
)
return
}

plan = readLiveSource(plan, mediatailor.CreateLiveSourceOutput(*updatedLiveSource))
Expand Down Expand Up @@ -172,6 +173,7 @@ func (r *resourceLiveSource) Delete(ctx context.Context, req resource.DeleteRequ
"Error while deleting live source "+err.Error(),
err.Error(),
)
return
}
}

Expand Down
3 changes: 2 additions & 1 deletion awsmt/resource_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *resourcePlaybackConfiguration) Schema(_ context.Context, _ resource.Sch
},
},
},
"name": requiredString,
"name": requiredStringWithRequiresReplace,
"personalization_threshold_seconds": optionalInt64,
"playback_configuration_arn": computedStringWithStateForUnknown,
"playback_endpoint_prefix": computedStringWithStateForUnknown,
Expand Down Expand Up @@ -248,6 +248,7 @@ func (r *resourcePlaybackConfiguration) Update(ctx context.Context, req resource
"Error while updating playback configuration tags"+err.Error(),
err.Error(),
)
return
}

p := putPlaybackConfigurationInputBuilder{input: &mediatailor.PutPlaybackConfigurationInput{}, model: plan}
Expand Down
3 changes: 2 additions & 1 deletion awsmt/resource_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *resourceSourceLocation) Schema(_ context.Context, _ resource.SchemaRequ
},
},
},
"name": requiredString,
"name": requiredStringWithRequiresReplace,
"tags": optionalMap,
},
}
Expand Down Expand Up @@ -169,6 +169,7 @@ func (r *resourceSourceLocation) Update(ctx context.Context, req resource.Update
"Error while updating playback configuration tags"+err.Error(),
err.Error(),
)
return
}
if !currentState.AccessConfiguration.Equal(plan.AccessConfiguration) {
updatedSourceLocation, err := recreateSourceLocation(r.client, plan)
Expand Down
3 changes: 3 additions & 0 deletions awsmt/resource_vod_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (r *resourceVodSource) Update(ctx context.Context, req resource.UpdateReque
"Error while updating vod source tags"+err.Error(),
err.Error(),
)
return
}

updateInput := getUpdateVodSourceInput(plan)
Expand All @@ -152,6 +153,7 @@ func (r *resourceVodSource) Update(ctx context.Context, req resource.UpdateReque
"Error while updating vod source "+err.Error(),
err.Error(),
)
return
}

plan = readVodSourceToPlan(plan, mediatailor.CreateVodSourceOutput(*updatedVodSource))
Expand Down Expand Up @@ -181,6 +183,7 @@ func (r *resourceVodSource) Delete(ctx context.Context, req resource.DeleteReque
"Error while deleting vod source "+err.Error(),
err.Error(),
)
return
}
}

Expand Down

0 comments on commit 6827da2

Please sign in to comment.