Skip to content

Commit

Permalink
Merge pull request #87 from spring-media/chore/OTT-6361
Browse files Browse the repository at this point in the history
Chore/ott 6361
  • Loading branch information
thatsddr authored Sep 2, 2024
2 parents 3298ec4 + c11fdca commit c625ff0
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 394 deletions.
10 changes: 5 additions & 5 deletions awsmt/data_source_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package awsmt

import (
"context"
"github.com/aws/aws-sdk-go/service/mediatailor"
"github.com/aws/aws-sdk-go-v2/service/mediatailor"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand All @@ -19,7 +19,7 @@ func DataSourceSourceLocation() datasource.DataSource {
}

type dataSourceSourceLocation struct {
client *mediatailor.MediaTailor
client *mediatailor.Client
}

func (d *dataSourceSourceLocation) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -84,7 +84,7 @@ func (d *dataSourceSourceLocation) Configure(_ context.Context, req datasource.C
return
}

d.client = req.ProviderData.(clients).v1
d.client = req.ProviderData.(clients).v2
}

func (d *dataSourceSourceLocation) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand All @@ -97,13 +97,13 @@ func (d *dataSourceSourceLocation) Read(ctx context.Context, req datasource.Read

sourceLocationName := data.Name

sourceLocation, err := d.client.DescribeSourceLocation(&mediatailor.DescribeSourceLocationInput{SourceLocationName: sourceLocationName})
sourceLocation, err := d.client.DescribeSourceLocation(ctx, &mediatailor.DescribeSourceLocationInput{SourceLocationName: sourceLocationName})
if err != nil {
resp.Diagnostics.AddError("Error while describing source location", err.Error())
return
}

data = readSourceLocationToPlan(data, mediatailor.CreateSourceLocationOutput(*sourceLocation))
data = writeSourceLocationToPlan(data, mediatailor.CreateSourceLocationOutput(*sourceLocation), false)

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
5 changes: 2 additions & 3 deletions awsmt/helpers_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/aws/aws-sdk-go-v2/service/mediatailor"
awsTypes "github.com/aws/aws-sdk-go-v2/service/mediatailor/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/types"
"reflect"
Expand Down Expand Up @@ -230,11 +229,11 @@ func readChannelComputedValues(model channelModel, arn *string, channelName *str
model.Name = channelName

if creationTime != nil {
model.CreationTime = types.StringValue((aws.TimeValue(creationTime)).String())
model.CreationTime = types.StringValue(creationTime.String())
}

if lastModifiedTime != nil {
model.LastModifiedTime = types.StringValue((aws.TimeValue(lastModifiedTime)).String())
model.LastModifiedTime = types.StringValue(lastModifiedTime.String())
}

return model
Expand Down
35 changes: 0 additions & 35 deletions awsmt/helpers_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,11 @@ import (
"context"
"fmt"
mediatailorV2 "github.com/aws/aws-sdk-go-v2/service/mediatailor"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mediatailor"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"reflect"
"strings"
)

func untagResource(client *mediatailor.MediaTailor, oldTags map[string]*string, resourceArn string) error {
var removeTags []*string
for k := range oldTags {
removeTags = append(removeTags, aws.String(k))
}
_, err := client.UntagResource(&mediatailor.UntagResourceInput{ResourceArn: &resourceArn, TagKeys: removeTags})
if err != nil {
return err
}
return nil
}

func tagResource(client *mediatailor.MediaTailor, newTags map[string]*string, resourceArn string) error {
_, err := client.TagResource(&mediatailor.TagResourceInput{ResourceArn: &resourceArn, Tags: newTags})
if err != nil {
return err
}
return nil
}

func updatesTags(client *mediatailor.MediaTailor, oldTags map[string]*string, newTags map[string]*string, resourceArn string) error {
if !reflect.DeepEqual(oldTags, newTags) {
if err := untagResource(client, oldTags, resourceArn); err != nil {
return err
}
if err := tagResource(client, newTags, resourceArn); err != nil {
return err
}
}
return nil
}

func v2Untag(client *mediatailorV2.Client, oldTags map[string]string, resourceArn string) error {
var removeTags []string
for k := range oldTags {
Expand Down
Loading

0 comments on commit c625ff0

Please sign in to comment.