Skip to content

Commit

Permalink
Add 'destinationModel.Expand/Flatten'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 1, 2024
1 parent 0ec1941 commit 866afcd
Showing 1 changed file with 77 additions and 6 deletions.
83 changes: 77 additions & 6 deletions internal/service/appfabric/ingestion_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,18 @@ func (r *ingestionDestinationResource) ModifyPlan(ctx context.Context, request r
}

func findIngestionDestinationByThreePartKey(ctx context.Context, conn *appfabric.Client, appBundleARN, ingestionARN, arn string) (*awstypes.IngestionDestination, error) {
in := &appfabric.GetIngestionDestinationInput{
input := &appfabric.GetIngestionDestinationInput{
AppBundleIdentifier: aws.String(appBundleARN),
IngestionDestinationIdentifier: aws.String(arn),
IngestionIdentifier: aws.String(ingestionARN),
}

output, err := conn.GetIngestionDestination(ctx, in)
output, err := conn.GetIngestionDestination(ctx, input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: in,
LastRequest: input,
}
}

Expand All @@ -411,15 +411,15 @@ func findIngestionDestinationByThreePartKey(ctx context.Context, conn *appfabric
}

if output == nil || output.IngestionDestination == nil {
return nil, tfresource.NewEmptyResultError(in)
return nil, tfresource.NewEmptyResultError(input)
}

return output.IngestionDestination, nil
}

func statusIngestionDestination(ctx context.Context, conn *appfabric.Client, appBundleARN, ingestionARN, arn string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
out, err := findIngestionDestinationByThreePartKey(ctx, conn, appBundleARN, ingestionARN, arn)
output, err := findIngestionDestinationByThreePartKey(ctx, conn, appBundleARN, ingestionARN, arn)

if tfresource.NotFound(err) {
return nil, "", nil
Expand All @@ -429,7 +429,7 @@ func statusIngestionDestination(ctx context.Context, conn *appfabric.Client, app
return nil, "", err
}

return out, string(out.Status), nil
return output, string(output.Status), nil
}
}

Expand Down Expand Up @@ -567,6 +567,77 @@ type destinationModel struct {
S3Bucket fwtypes.ListNestedObjectValueOf[s3BucketModel] `tfsdk:"s3_bucket"`
}

var (
_ fwflex.Expander = destinationModel{}
_ fwflex.Flattener = &destinationModel{}
)

func (m destinationModel) Expand(ctx context.Context) (result any, diags diag.Diagnostics) {
switch {
case !m.FirehoseStream.IsNull():
firehoseStreamData, d := m.FirehoseStream.ToPtr(ctx)
diags.Append(d...)
if diags.HasError() {
return nil, diags
}

var r awstypes.DestinationMemberFirehoseStream
diags.Append(fwflex.Expand(ctx, firehoseStreamData, &r.Value)...)
if diags.HasError() {
return nil, diags
}

return &r, diags

case !m.S3Bucket.IsNull():
s3BucketData, d := m.S3Bucket.ToPtr(ctx)
diags.Append(d...)
if diags.HasError() {
return nil, diags
}

var r awstypes.DestinationMemberS3Bucket
diags.Append(fwflex.Expand(ctx, s3BucketData, &r.Value)...)
if diags.HasError() {
return nil, diags
}

return &r, diags
}

return nil, diags
}

func (m *destinationModel) Flatten(ctx context.Context, v any) (diags diag.Diagnostics) {
switch t := v.(type) {
case awstypes.DestinationMemberFirehoseStream:
var model firehoseStreamModel
d := fwflex.Flatten(ctx, t.Value, &model)
diags.Append(d...)
if diags.HasError() {
return diags
}

m.FirehoseStream = fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &model)

return diags

case awstypes.DestinationMemberS3Bucket:
var model s3BucketModel
d := fwflex.Flatten(ctx, t.Value, &model)
diags.Append(d...)
if diags.HasError() {
return diags
}

m.S3Bucket = fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &model)

return diags
}

return diags
}

type firehoseStreamModel struct {
StreamName types.String `tfsdk:"stream_name"`
}
Expand Down

0 comments on commit 866afcd

Please sign in to comment.