Skip to content

Commit 2b8b251

Browse files
authored
Merge pull request #92 from spring-media/fix/OTT-6909
Fix/ott 6909
2 parents 9abafc3 + afdc683 commit 2b8b251

9 files changed

+246
-192
lines changed

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches:
66
- "**"
77
env:
8-
GO_VERSION: 1.22
8+
GO_VERSION: 1.24
99

1010
permissions:
1111
id-token: write
@@ -24,7 +24,7 @@ jobs:
2424
go-version: ${{ env.GO_VERSION }}
2525
- uses: golangci/golangci-lint-action@v6
2626
with:
27-
version: v1.62
27+
version: latest
2828
- run: |
2929
pip install -r requirements.txt
3030
mkdocs build -f ../../mkdocs.yaml --strict

awsmt/data_source_source_location.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (d *dataSourceSourceLocation) Read(ctx context.Context, req datasource.Read
104104
return
105105
}
106106

107-
data = writeSourceLocationToPlan(data, mediatailor.CreateSourceLocationOutput(*sourceLocation), false)
107+
data = writeSourceLocationToPlan(data, mediatailor.CreateSourceLocationOutput(*sourceLocation))
108108

109109
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
110110
}

awsmt/helpers_source_location.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ func getUpdateSourceLocationInput(model models.SourceLocationModel) mediatailor.
137137
return params
138138
}
139139

140-
func writeSourceLocationToPlan(model models.SourceLocationModel, sourceLocation mediatailor.CreateSourceLocationOutput, isResource bool) models.SourceLocationModel {
140+
func writeSourceLocationToPlan(model models.SourceLocationModel, sourceLocation mediatailor.CreateSourceLocationOutput) models.SourceLocationModel {
141141
// Set state
142142

143143
model = readSourceLocationComputedValues(model, sourceLocation)
144144

145-
model = readAccessConfiguration(model, sourceLocation, isResource)
145+
model = readAccessConfiguration(model, sourceLocation)
146146

147147
model = readDefaultSegmentDeliveryConfiguration(model, sourceLocation)
148148

@@ -179,17 +179,14 @@ func readSourceLocationComputedValues(model models.SourceLocationModel, sourceLo
179179
return model
180180
}
181181

182-
func readAccessConfiguration(model models.SourceLocationModel, sourceLocation mediatailor.CreateSourceLocationOutput, isResource bool) models.SourceLocationModel {
182+
func readAccessConfiguration(model models.SourceLocationModel, sourceLocation mediatailor.CreateSourceLocationOutput) models.SourceLocationModel {
183183
if sourceLocation.AccessConfiguration == nil {
184184
return model
185185
}
186-
if model.AccessConfiguration == nil && isResource {
187-
return model
188-
}
189186

190187
model.AccessConfiguration = &models.AccessConfigurationModel{}
191188

192-
if !(isResource && model.AccessConfiguration == nil) {
189+
if string(sourceLocation.AccessConfiguration.AccessType) != "" {
193190
accessType := string(sourceLocation.AccessConfiguration.AccessType)
194191
model.AccessConfiguration.AccessType = &accessType
195192
}
@@ -304,6 +301,6 @@ func recreateSourceLocation(client *mediatailor.Client, plan models.SourceLocati
304301
if err != nil {
305302
return nil, fmt.Errorf("error while creating new source location with new access configuration %v", err.Error())
306303
}
307-
model := writeSourceLocationToPlan(plan, *sourceLocation, true)
304+
model := writeSourceLocationToPlan(plan, *sourceLocation)
308305
return &model, nil
309306
}

awsmt/resource_source_location.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/resource"
99
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1010
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
11+
"strings"
1112
"terraform-provider-mediatailor/awsmt/models"
1213
)
1314

@@ -108,7 +109,7 @@ func (r *resourceSourceLocation) Create(ctx context.Context, req resource.Create
108109
return
109110
}
110111

111-
plan = writeSourceLocationToPlan(plan, *sourceLocation, true)
112+
plan = writeSourceLocationToPlan(plan, *sourceLocation)
112113

113114
diags = resp.State.Set(ctx, plan)
114115
resp.Diagnostics.Append(diags...)
@@ -133,7 +134,7 @@ func (r *resourceSourceLocation) Read(ctx context.Context, req resource.ReadRequ
133134
return
134135
}
135136

136-
state = writeSourceLocationToPlan(state, mediatailor.CreateSourceLocationOutput(*sourceLocation), true)
137+
state = writeSourceLocationToPlan(state, mediatailor.CreateSourceLocationOutput(*sourceLocation))
137138

138139
diags = resp.State.Set(ctx, &state)
139140
resp.Diagnostics.Append(diags...)
@@ -189,7 +190,7 @@ func (r *resourceSourceLocation) Update(ctx context.Context, req resource.Update
189190
)
190191
return
191192
}
192-
plan = writeSourceLocationToPlan(plan, mediatailor.CreateSourceLocationOutput(*sourceLocationUpdated), true)
193+
plan = writeSourceLocationToPlan(plan, mediatailor.CreateSourceLocationOutput(*sourceLocationUpdated))
193194
}
194195

195196
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
@@ -218,5 +219,29 @@ func (r *resourceSourceLocation) Delete(ctx context.Context, req resource.Delete
218219
}
219220

220221
func (r *resourceSourceLocation) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
221-
resource.ImportStatePassthroughID(ctx, path.Root("name"), req, resp)
222+
// Split the import ID to support various import formats
223+
idParts := strings.Split(req.ID, "/")
224+
225+
if len(idParts) == 1 {
226+
resource.ImportStatePassthroughID(ctx, path.Root("name"), req, resp)
227+
return
228+
}
229+
230+
// Support ARN import format
231+
if strings.HasPrefix(req.ID, "arn:aws:mediatailor:") {
232+
arnParts := strings.Split(req.ID, ":")
233+
if len(arnParts) >= 6 {
234+
resourcePath := arnParts[5]
235+
resourceParts := strings.Split(resourcePath, "/")
236+
if len(resourceParts) >= 2 && resourceParts[0] == "sourceLocation" {
237+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), resourceParts[1])...)
238+
return
239+
}
240+
}
241+
}
242+
243+
resp.Diagnostics.AddError(
244+
"Invalid import ID",
245+
"Expected import ID to be either the source location name or the full ARN",
246+
)
222247
}

awsmt/resource_source_location_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ func TestAccSourceLocationResourceUpdateAccessControl(t *testing.T) {
112112
resource.TestCheckResourceAttr(resourceName, "tags.Environment", "dev"),
113113
),
114114
},
115+
// Import resource by arn
116+
{
117+
ResourceName: resourceName,
118+
ImportState: true,
119+
ImportStateId: "arn:aws:mediatailor:eu-central-1:985600762523:sourceLocation/" + name,
120+
},
115121
// Update and Read testing
116122
{
117123
Config: basicSourceLocationWithAccessConfig(name, baseUrl2, k3, v3, k2, v2),
@@ -130,6 +136,37 @@ func TestAccSourceLocationResourceUpdateAccessControl(t *testing.T) {
130136
})
131137
}
132138

139+
func TestAccSourceLocationAccessConfiguration_SMATC(t *testing.T) {
140+
secretStringKey := "access-token"
141+
headerName := "ACCESS-TOKEN"
142+
secretArn := "arn:aws:secretsmanager:eu-central-1:985600762523:secret:terraform-provider-aws-acceptance-testing-Hr2kg1"
143+
144+
resourceName := "awsmt_source_location.test_source_location_smatc"
145+
146+
resource.ParallelTest(t, resource.TestCase{
147+
PreCheck: func() {
148+
testAccPreCheck(t)
149+
},
150+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
151+
Steps: []resource.TestStep{
152+
{
153+
Config: sourceLocationWithSMATC(secretArn, secretStringKey, headerName),
154+
Check: resource.ComposeTestCheckFunc(
155+
resource.TestCheckResourceAttr(resourceName, "access_configuration.access_type", "SECRETS_MANAGER_ACCESS_TOKEN"),
156+
resource.TestCheckResourceAttr(resourceName, "access_configuration.smatc.header_name", headerName),
157+
resource.TestCheckResourceAttr(resourceName, "access_configuration.smatc.secret_arn", secretArn),
158+
resource.TestCheckResourceAttr(resourceName, "access_configuration.smatc.secret_string_key", secretStringKey),
159+
),
160+
},
161+
// Import resource
162+
{
163+
ResourceName: resourceName,
164+
ImportState: true,
165+
},
166+
},
167+
})
168+
}
169+
133170
func TestAccSourceLocationDeleteVodResource(t *testing.T) {
134171
resourceName := "awsmt_source_location.test_source_location"
135172
resource.Test(t, resource.TestCase{
@@ -260,3 +297,29 @@ func basicSourceLocationWithVodSource() string {
260297
}
261298
`
262299
}
300+
301+
func sourceLocationWithSMATC(secretArn, secretStringKey, headerName string) string {
302+
return fmt.Sprintf(`
303+
resource "awsmt_source_location" "test_source_location_smatc"{
304+
name = "sl-smatc"
305+
http_configuration = {
306+
base_url = "https://ott-mediatailor-test.s3.eu-central-1.amazonaws.com"
307+
}
308+
access_configuration = {
309+
access_type = "SECRETS_MANAGER_ACCESS_TOKEN"
310+
smatc = {
311+
header_name = "%[1]s"
312+
secret_arn = "%[2]s"
313+
secret_string_key = "%[3]s"
314+
}
315+
}
316+
}
317+
data "awsmt_source_location" "read" {
318+
name = awsmt_source_location.test_source_location_smatc.name
319+
}
320+
output "awsmt_source_location" {
321+
value = data.awsmt_source_location.read
322+
}
323+
324+
`, headerName, secretArn, secretStringKey)
325+
}

docs/resources/awsmt_source_location.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ In addition to all arguments above, the following attributes are exported:
6060

6161
## Import
6262

63-
Source Locations can be imported using their name as identifier. For example:
63+
Source Locations can be imported using either their name or their ARN as identifier. For example:
6464

6565
```
6666
$ terraform import awsmt_source_location.example example-source-location

examples/source_location.tf

-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,3 @@ data "awsmt_source_location" "read" {
1515
output "awsmt_source_location" {
1616
value = data.awsmt_source_location.read
1717
}
18-
19-
20-

go.mod

+41-42
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
11
module terraform-provider-mediatailor
22

3-
go 1.22.7
4-
5-
toolchain go1.23.3
3+
go 1.24.1
64

75
require (
8-
github.com/aws/aws-sdk-go-v2 v1.32.8
9-
github.com/aws/aws-sdk-go-v2/config v1.28.9
10-
github.com/aws/aws-sdk-go-v2/service/mediatailor v1.42.9
11-
github.com/hashicorp/terraform-plugin-framework v1.13.0
6+
github.com/aws/aws-sdk-go-v2 v1.36.3
7+
github.com/aws/aws-sdk-go-v2/config v1.29.9
8+
github.com/aws/aws-sdk-go-v2/service/mediatailor v1.45.1
9+
github.com/hashicorp/terraform-plugin-framework v1.14.1
1210
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0
13-
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
14-
github.com/hashicorp/terraform-plugin-go v0.25.0
11+
github.com/hashicorp/terraform-plugin-framework-validators v0.17.0
12+
github.com/hashicorp/terraform-plugin-go v0.26.0
1513
github.com/hashicorp/terraform-plugin-log v0.9.0
16-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
17-
github.com/onsi/ginkgo/v2 v2.22.0
18-
github.com/onsi/gomega v1.36.1
14+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1
15+
github.com/onsi/ginkgo/v2 v2.23.1
16+
github.com/onsi/gomega v1.36.2
1917
)
2018

2119
require (
22-
github.com/ProtonMail/go-crypto v1.1.0-alpha.5-proton // indirect
20+
github.com/ProtonMail/go-crypto v1.1.3 // indirect
2321
github.com/agext/levenshtein v1.2.2 // indirect
2422
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
25-
github.com/aws/aws-sdk-go-v2/credentials v1.17.50 // indirect
26-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.23 // indirect
27-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.27 // indirect
28-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.27 // indirect
29-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
30-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
31-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.8 // indirect
32-
github.com/aws/aws-sdk-go-v2/service/sso v1.24.9 // indirect
33-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.8 // indirect
34-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.5 // indirect
35-
github.com/aws/smithy-go v1.22.1 // indirect
23+
github.com/aws/aws-sdk-go-v2/credentials v1.17.62 // indirect
24+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
25+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
26+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
27+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
28+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
29+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1 // indirect
31+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 // indirect
33+
github.com/aws/smithy-go v1.22.3 // indirect
3634
github.com/cloudflare/circl v1.3.7 // indirect
3735
github.com/fatih/color v1.18.0 // indirect
3836
github.com/go-logr/logr v1.4.2 // indirect
3937
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4038
github.com/golang/protobuf v1.5.4 // indirect
41-
github.com/google/go-cmp v0.6.0 // indirect
42-
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
39+
github.com/google/go-cmp v0.7.0 // indirect
40+
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e // indirect
4341
github.com/hashicorp/errwrap v1.0.0 // indirect
4442
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
4543
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
4644
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
4745
github.com/hashicorp/go-hclog v1.6.3 // indirect
4846
github.com/hashicorp/go-multierror v1.1.1 // indirect
4947
github.com/hashicorp/go-plugin v1.6.2 // indirect
48+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
5049
github.com/hashicorp/go-uuid v1.0.3 // indirect
51-
github.com/hashicorp/go-version v1.6.0 // indirect
52-
github.com/hashicorp/hc-install v0.6.4 // indirect
53-
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
50+
github.com/hashicorp/go-version v1.7.0 // indirect
51+
github.com/hashicorp/hc-install v0.9.1 // indirect
52+
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
5453
github.com/hashicorp/logutils v1.0.0 // indirect
55-
github.com/hashicorp/terraform-exec v0.21.0 // indirect
56-
github.com/hashicorp/terraform-json v0.22.1 // indirect
57-
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
54+
github.com/hashicorp/terraform-exec v0.22.0 // indirect
55+
github.com/hashicorp/terraform-json v0.24.0 // indirect
56+
github.com/hashicorp/terraform-registry-address v0.2.4 // indirect
5857
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5958
github.com/hashicorp/yamux v0.1.2 // indirect
6059
github.com/mattn/go-colorable v0.1.14 // indirect
@@ -68,17 +67,17 @@ require (
6867
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
6968
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
7069
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
71-
github.com/zclconf/go-cty v1.14.4 // indirect
72-
golang.org/x/crypto v0.32.0 // indirect
73-
golang.org/x/mod v0.21.0 // indirect
74-
golang.org/x/net v0.34.0 // indirect
75-
golang.org/x/sync v0.10.0 // indirect
76-
golang.org/x/sys v0.29.0 // indirect
77-
golang.org/x/text v0.21.0 // indirect
78-
golang.org/x/tools v0.26.0 // indirect
70+
github.com/zclconf/go-cty v1.16.2 // indirect
71+
golang.org/x/crypto v0.36.0 // indirect
72+
golang.org/x/mod v0.24.0 // indirect
73+
golang.org/x/net v0.37.0 // indirect
74+
golang.org/x/sync v0.12.0 // indirect
75+
golang.org/x/sys v0.31.0 // indirect
76+
golang.org/x/text v0.23.0 // indirect
77+
golang.org/x/tools v0.31.0 // indirect
7978
google.golang.org/appengine v1.6.8 // indirect
8079
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
81-
google.golang.org/grpc v1.69.2 // indirect
82-
google.golang.org/protobuf v1.36.2 // indirect
80+
google.golang.org/grpc v1.69.4 // indirect
81+
google.golang.org/protobuf v1.36.3 // indirect
8382
gopkg.in/yaml.v3 v3.0.1 // indirect
8483
)

0 commit comments

Comments
 (0)