Skip to content

Commit f14db80

Browse files
authored
Merge pull request #94 from crussell10/Issue#93-add-enabled-logging-strategies
feat: add support for enabled logging strategies
2 parents a6c03f6 + b47134e commit f14db80

10 files changed

+195
-80
lines changed

awsmt/data_source_playback_configuration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (d *dataSourcePlaybackConfiguration) Schema(_ context.Context, _ datasource
7676
},
7777
},
7878
"log_configuration_percent_enabled": computedInt64,
79+
"log_configuration_enabled_logging_strategies": schema.ListAttribute{
80+
Computed: true,
81+
ElementType: types.StringType,
82+
},
7983
"manifest_processing_rules": schema.SingleNestedAttribute{
8084
Computed: true,
8185

awsmt/data_source_playback_configuration_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ func TestAccPlaybackConfigurationDataSourceBasic(t *testing.T) {
3636
resource.TestCheckResourceAttr(resourceName, "tags.Environment", "dev"),
3737
resource.TestCheckResourceAttr(resourceName, "video_content_source_url", "https://exampleurl.com/"),
3838
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", "0"),
39-
),
39+
resource.TestCheckResourceAttrSet(resourceName, "log_configuration_enabled_logging_strategies.#"),
40+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.0", "LEGACY_CLOUDWATCH"),
41+
),
4042
},
4143
},
4244
})
@@ -94,6 +96,8 @@ func playbackConfigDS() string {
9496
slate_ad_url = "https://exampleurl.com/"
9597
tags = {"Environment": "dev"}
9698
video_content_source_url = "https://exampleurl.com/"
99+
log_configuration_percent_enabled = 0
100+
log_configuration_enabled_logging_strategies = ["LEGACY_CLOUDWATCH"]
97101
}
98102
99103
data "awsmt_playback_configuration" "test"{
@@ -140,6 +144,8 @@ func playbackConfigDSError() string {
140144
slate_ad_url = "https://exampleurl.com/"
141145
tags = {"Environment": "dev"}
142146
video_content_source_url = "https://exampleurl.com/"
147+
log_configuration_percent_enabled = 0
148+
log_configuration_enabled_logging_strategies = ["LEGACY_CLOUDWATCH"]
143149
}
144150
145151
data "awsmt_playback_configuration" "test"{

awsmt/helpers_playback_configuration.go

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/aws/aws-sdk-go-v2/service/mediatailor"
77
awsTypes "github.com/aws/aws-sdk-go-v2/service/mediatailor/types"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
910
"terraform-provider-mediatailor/awsmt/models"
1011
)
1112

@@ -304,6 +305,18 @@ func (m *putPlaybackConfigurationModelbuilder) addOptionalFieldsToModel() {
304305
} else if !m.isResource {
305306
m.model.LogConfigurationPercentEnabled = types.Int64Value(int64(m.output.LogConfiguration.PercentEnabled))
306307
}
308+
309+
if len(m.output.LogConfiguration.EnabledLoggingStrategies) > 0 {
310+
strategies := make([]attr.Value, 0, len(m.output.LogConfiguration.EnabledLoggingStrategies))
311+
for _, strategy := range m.output.LogConfiguration.EnabledLoggingStrategies {
312+
strategies = append(strategies, types.StringValue(string(strategy)))
313+
}
314+
listValue, _ := types.ListValue(types.StringType, strategies)
315+
m.model.LogConfigurationEnabledLoggingStrategies = listValue
316+
} else {
317+
emptyList, _ := types.ListValue(types.StringType, []attr.Value{})
318+
m.model.LogConfigurationEnabledLoggingStrategies = emptyList
319+
}
307320
}
308321

309322
if m.output.PersonalizationThresholdSeconds != nil {
@@ -327,21 +340,28 @@ func (m *putPlaybackConfigurationModelbuilder) addOptionalFieldsToModel() {
327340
}
328341
}
329342

330-
// Log percentage configuration helper
331-
func setLogPercentage(client *mediatailor.Client, model models.PlaybackConfigurationModel) (*mediatailor.PutPlaybackConfigurationOutput, error) {
332-
_, err := client.ConfigureLogsForPlaybackConfiguration(context.TODO(), &mediatailor.ConfigureLogsForPlaybackConfigurationInput{
333-
PlaybackConfigurationName: model.Name,
334-
PercentEnabled: int32(model.LogConfigurationPercentEnabled.ValueInt64()),
335-
})
336-
337-
if err != nil {
338-
return nil, err
339-
}
340-
341-
playbackConfiguration, err := client.GetPlaybackConfiguration(context.TODO(), &mediatailor.GetPlaybackConfigurationInput{Name: model.Name})
342-
if err != nil {
343-
return nil, err
344-
}
345-
output := mediatailor.PutPlaybackConfigurationOutput(*playbackConfiguration)
346-
return &output, nil
347-
}
343+
// Log percentage & strategies configuration helper
344+
func configureLogging(client *mediatailor.Client, model models.PlaybackConfigurationModel) (*mediatailor.GetPlaybackConfigurationOutput, error) {
345+
input := &mediatailor.ConfigureLogsForPlaybackConfigurationInput{
346+
PlaybackConfigurationName: model.Name,
347+
PercentEnabled: int32(model.LogConfigurationPercentEnabled.ValueInt64()),
348+
}
349+
350+
// Add logging strategies if they exist
351+
if !model.LogConfigurationEnabledLoggingStrategies.IsNull() && len(model.LogConfigurationEnabledLoggingStrategies.Elements()) > 0 {
352+
var enabledStrategies []awsTypes.LoggingStrategy
353+
for _, element := range model.LogConfigurationEnabledLoggingStrategies.Elements() {
354+
if stringVal, ok := element.(types.String); ok && !stringVal.IsNull() {
355+
enabledStrategies = append(enabledStrategies, awsTypes.LoggingStrategy(stringVal.ValueString()))
356+
}
357+
}
358+
input.EnabledLoggingStrategies = enabledStrategies
359+
}
360+
361+
_, err := client.ConfigureLogsForPlaybackConfiguration(context.TODO(), input)
362+
if err != nil {
363+
return nil, err
364+
}
365+
366+
return client.GetPlaybackConfiguration(context.TODO(), &mediatailor.GetPlaybackConfigurationInput{Name: model.Name})
367+
}

awsmt/models/models_playback_configuration.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ type PlaybackConfigurationModel struct {
1414
// Context: The Provider Framework does not allow computed blocks
1515
// Decision: We decided to flatten the Log Configuration and the HLS Configuration blocks into the resource.
1616
// Consequences: The schema of the object differs from that of the SDK.
17-
HlsConfigurationManifestEndpointPrefix types.String `tfsdk:"hls_configuration_manifest_endpoint_prefix"`
18-
LogConfigurationPercentEnabled types.Int64 `tfsdk:"log_configuration_percent_enabled"`
19-
LivePreRollConfiguration *LivePreRollConfigurationModel `tfsdk:"live_pre_roll_configuration"`
20-
ManifestProcessingRules *ManifestProcessingRulesModel `tfsdk:"manifest_processing_rules"`
21-
Name *string `tfsdk:"name"`
22-
PersonalizationThresholdSeconds *int32 `tfsdk:"personalization_threshold_seconds"`
23-
PlaybackConfigurationArn types.String `tfsdk:"playback_configuration_arn"`
24-
PlaybackEndpointPrefix types.String `tfsdk:"playback_endpoint_prefix"`
25-
SessionInitializationEndpointPrefix types.String `tfsdk:"session_initialization_endpoint_prefix"`
26-
SlateAdUrl *string `tfsdk:"slate_ad_url"`
27-
Tags map[string]string `tfsdk:"tags"`
28-
TranscodeProfileName *string `tfsdk:"transcode_profile_name"`
29-
VideoContentSourceUrl *string `tfsdk:"video_content_source_url"`
17+
HlsConfigurationManifestEndpointPrefix types.String `tfsdk:"hls_configuration_manifest_endpoint_prefix"`
18+
LogConfigurationPercentEnabled types.Int64 `tfsdk:"log_configuration_percent_enabled"`
19+
LogConfigurationEnabledLoggingStrategies types.List `tfsdk:"log_configuration_enabled_logging_strategies"`
20+
LivePreRollConfiguration *LivePreRollConfigurationModel `tfsdk:"live_pre_roll_configuration"`
21+
ManifestProcessingRules *ManifestProcessingRulesModel `tfsdk:"manifest_processing_rules"`
22+
Name *string `tfsdk:"name"`
23+
PersonalizationThresholdSeconds *int32 `tfsdk:"personalization_threshold_seconds"`
24+
PlaybackConfigurationArn types.String `tfsdk:"playback_configuration_arn"`
25+
PlaybackEndpointPrefix types.String `tfsdk:"playback_endpoint_prefix"`
26+
SessionInitializationEndpointPrefix types.String `tfsdk:"session_initialization_endpoint_prefix"`
27+
SlateAdUrl *string `tfsdk:"slate_ad_url"`
28+
Tags map[string]string `tfsdk:"tags"`
29+
TranscodeProfileName *string `tfsdk:"transcode_profile_name"`
30+
VideoContentSourceUrl *string `tfsdk:"video_content_source_url"`
3031
}
3132

3233
type AvailSuppressionModel struct {

awsmt/resource_playback_configuration.go

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework/resource"
1010
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
1213
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
1314
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1415
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@@ -105,6 +106,14 @@ func (r *resourcePlaybackConfiguration) Schema(_ context.Context, _ resource.Sch
105106
int64planmodifier.UseStateForUnknown(),
106107
},
107108
},
109+
"log_configuration_enabled_logging_strategies": schema.ListAttribute{
110+
Optional: true,
111+
Computed: true,
112+
ElementType: types.StringType,
113+
PlanModifiers: []planmodifier.List{
114+
listplanmodifier.UseStateForUnknown(),
115+
},
116+
},
108117
"live_pre_roll_configuration": schema.SingleNestedAttribute{
109118
Optional: true,
110119
Attributes: map[string]schema.Attribute{
@@ -169,21 +178,26 @@ func (r *resourcePlaybackConfiguration) Create(ctx context.Context, req resource
169178
return
170179
}
171180

172-
playbackConfiguration, err := setLogPercentage(r.client, plan)
173-
if err != nil {
174-
resp.Diagnostics.AddError(
175-
"Error while setting the log percentage "+err.Error(),
176-
err.Error(),
177-
)
178-
return
179-
}
180-
181-
m := putPlaybackConfigurationModelbuilder{model: &plan, output: *playbackConfiguration, isResource: true}
182-
183-
resp.Diagnostics.Append(resp.State.Set(ctx, m.getModel())...)
184-
if resp.Diagnostics.HasError() {
185-
return
186-
}
181+
// Configure both log percentage and logging strategies
182+
finalPlaybackConfiguration, err := configureLogging(r.client, plan)
183+
if err != nil {
184+
resp.Diagnostics.AddError(
185+
"Error while configuring logging "+err.Error(),
186+
err.Error(),
187+
)
188+
return
189+
}
190+
191+
m := putPlaybackConfigurationModelbuilder{
192+
model: &plan,
193+
output: mediatailor.PutPlaybackConfigurationOutput(*finalPlaybackConfiguration),
194+
isResource: true,
195+
}
196+
197+
resp.Diagnostics.Append(resp.State.Set(ctx, m.getModel())...)
198+
if resp.Diagnostics.HasError() {
199+
return
200+
}
187201
}
188202

189203
func (r *resourcePlaybackConfiguration) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
@@ -245,7 +259,7 @@ func (r *resourcePlaybackConfiguration) Update(ctx context.Context, req resource
245259
err = UpdatesTags(r.client, playbackConfiguration.Tags, plan.Tags, *playbackConfiguration.PlaybackConfigurationArn)
246260
if err != nil {
247261
resp.Diagnostics.AddError(
248-
"Error while updating playback configuration tags"+err.Error(),
262+
"Error while updating playback configuration tags "+err.Error(),
249263
err.Error(),
250264
)
251265
return
@@ -263,21 +277,26 @@ func (r *resourcePlaybackConfiguration) Update(ctx context.Context, req resource
263277
return
264278
}
265279

266-
playbackConfigurationUpdate, err := setLogPercentage(r.client, plan)
267-
if err != nil {
268-
resp.Diagnostics.AddError(
269-
"Error while setting the log percentage "+err.Error(),
270-
err.Error(),
271-
)
272-
return
273-
}
274-
275-
m := putPlaybackConfigurationModelbuilder{model: &plan, output: *playbackConfigurationUpdate, isResource: true}
276-
277-
resp.Diagnostics.Append(resp.State.Set(ctx, m.getModel())...)
278-
if resp.Diagnostics.HasError() {
279-
return
280-
}
280+
// Configure both log percentage and logging strategies
281+
finalPlaybackConfiguration, err := configureLogging(r.client, plan)
282+
if err != nil {
283+
resp.Diagnostics.AddError(
284+
"Error while configuring logging "+err.Error(),
285+
err.Error(),
286+
)
287+
return
288+
}
289+
290+
m := putPlaybackConfigurationModelbuilder{
291+
model: &plan,
292+
output: mediatailor.PutPlaybackConfigurationOutput(*finalPlaybackConfiguration),
293+
isResource: true,
294+
}
295+
296+
resp.Diagnostics.Append(resp.State.Set(ctx, m.getModel())...)
297+
if resp.Diagnostics.HasError() {
298+
return
299+
}
281300
}
282301

283302
func (r *resourcePlaybackConfiguration) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {

awsmt/resource_playback_configuration_test.go

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ func TestAccPlaybackConfigurationLogPercentage(t *testing.T) {
9595
name := "test-acc-playback-configuration-log-percentage"
9696
adUrl := "https://www.foo.de/"
9797
videoSourceUrl := "https://www.bar.at"
98-
p1 := "5"
99-
p2 := "8"
98+
p1 := 5
99+
p2 := 8
100100
resource.Test(t, resource.TestCase{
101101
PreCheck: func() { testAccPreCheck(t) },
102102
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@@ -106,15 +106,49 @@ func TestAccPlaybackConfigurationLogPercentage(t *testing.T) {
106106
Check: resource.ComposeAggregateTestCheckFunc(
107107
resource.TestCheckResourceAttr(resourceName, "id", name),
108108
resource.TestCheckResourceAttr(resourceName, "name", name),
109-
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", p1),
109+
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", fmt.Sprintf("%d", p1)),
110110
),
111111
},
112112
{
113113
Config: logPercentagePlaybackConfiguration(name, adUrl, videoSourceUrl, p2),
114114
Check: resource.ComposeAggregateTestCheckFunc(
115115
resource.TestCheckResourceAttr(resourceName, "id", name),
116116
resource.TestCheckResourceAttr(resourceName, "name", name),
117-
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", p2),
117+
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", fmt.Sprintf("%d", p2)),
118+
),
119+
},
120+
},
121+
})
122+
}
123+
124+
func TestAccPlaybackConfigurationLoggingStrategies(t *testing.T) {
125+
resourceName := "awsmt_playback_configuration.r3"
126+
name := "test-acc-playback-configuration-enabled-logging-strategies"
127+
adUrl := "https://www.foo.de/"
128+
videoSourceUrl := "https://www.bar.at"
129+
p1 := `["LEGACY_CLOUDWATCH"]`
130+
p2 := `["LEGACY_CLOUDWATCH", "VENDED_LOGS"]`
131+
resource.Test(t, resource.TestCase{
132+
PreCheck: func() { testAccPreCheck(t) },
133+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
134+
Steps: []resource.TestStep{
135+
{
136+
Config: loggingStrategiesPlaybackConfiguration(name, adUrl, videoSourceUrl, p1),
137+
Check: resource.ComposeAggregateTestCheckFunc(
138+
resource.TestCheckResourceAttr(resourceName, "id", name),
139+
resource.TestCheckResourceAttr(resourceName, "name", name),
140+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.#", "1"),
141+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.0", "LEGACY_CLOUDWATCH"),
142+
),
143+
},
144+
{
145+
Config: loggingStrategiesPlaybackConfiguration(name, adUrl, videoSourceUrl, p2),
146+
Check: resource.ComposeAggregateTestCheckFunc(
147+
resource.TestCheckResourceAttr(resourceName, "id", name),
148+
resource.TestCheckResourceAttr(resourceName, "name", name),
149+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.#", "2"),
150+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.0", "LEGACY_CLOUDWATCH"),
151+
resource.TestCheckResourceAttr(resourceName, "log_configuration_enabled_logging_strategies.1", "VENDED_LOGS"),
118152
),
119153
},
120154
},
@@ -259,18 +293,30 @@ func configurationAliasesPlaybackConfiguration(name, adUrl, videoSourceUrl, conf
259293
)
260294
}
261295

262-
func logPercentagePlaybackConfiguration(name, adUrl, videoSourceUrl, logPercentage string) string {
296+
func logPercentagePlaybackConfiguration(name, adUrl, videoSourceUrl string, logPercentage int) string {
263297
return fmt.Sprintf(`
264298
resource "awsmt_playback_configuration" "r3" {
265299
ad_decision_server_url = "%[2]s"
266300
name = "%[1]s"
267301
video_content_source_url = "%[3]s"
268-
log_configuration_percent_enabled = "%[4]s"
302+
log_configuration_percent_enabled = %[4]d
269303
}
270304
`, name, adUrl, videoSourceUrl, logPercentage,
271305
)
272306
}
273307

308+
func loggingStrategiesPlaybackConfiguration(name, adUrl, videoSourceUrl, loggingStrategies string) string {
309+
return fmt.Sprintf(`
310+
resource "awsmt_playback_configuration" "r3" {
311+
ad_decision_server_url = "%[2]s"
312+
name = "%[1]s"
313+
video_content_source_url = "%[3]s"
314+
log_configuration_enabled_logging_strategies = %[4]s
315+
}
316+
`, name, adUrl, videoSourceUrl, loggingStrategies,
317+
)
318+
}
319+
274320
func completePlaybackConfiguration(name, adUrl, bumperE, bumperS, cdnUrl, maxD, pS, k1, v1, k2, v2 string) string {
275321
return fmt.Sprintf(`
276322
resource "awsmt_playback_configuration" "r1" {
@@ -311,4 +357,4 @@ func completePlaybackConfiguration(name, adUrl, bumperE, bumperS, cdnUrl, maxD,
311357
}
312358
`, name, adUrl, bumperE, bumperS, cdnUrl, maxD, pS, k1, v1, k2, v2,
313359
)
314-
}
360+
}

docs/data-sources/awsmt_playback_configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ In addition to all arguments above, the following attributes are exported:
4545
- `max_duration_seconds` - The maximum allowed duration for the pre-roll ad avail.
4646
- `log_configuration` - The Amazon CloudWatch log settings for a playback configuration.
4747
- `percent_enabled` - The percentage of session logs that MediaTailor sends to your Cloudwatch Logs account.
48+
- `log_configuration_enabled_logging_strategies` - The method used for collecting logs from AWS Elemental MediaTailor. Allowed values are "LEGACY_CLOUDWATCH" or "VENDED_LOGS", or both.
4849
- `manifest_processing_rules` – The configuration for manifest processing rules
4950
- `ad_marker_passthrough` – For HLS, when set to true, MediaTailor passes through EXT-X-CUE-IN, EXT-X-CUE-OUT, and EXT-X-SPLICEPOINT-SCTE35 ad markers from the origin manifest to the MediaTailor personalized manifest.
5051
- `enabled` - Enables ad marker passthrough for your configuration.

docs/resources/awsmt_playback_configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The following arguments are supported:
5858
- `ad_decision_server_url` - The URL for the ad decision server (ADS) for pre-roll ads.
5959
- `max_duration_seconds` - The maximum allowed duration for the pre-roll ad avail.
6060
- `log_configuration_percent_enabled` - The percentage of session logs that MediaTailor sends to your Cloudwatch Logs account.
61+
- `log_configuration_enabled_logging_strategies` - The method used for collecting logs from AWS Elemental MediaTailor. Allowed values are "LEGACY_CLOUDWATCH" or "VENDED_LOGS", or both.
6162
- `manifest_processing_rules` – The configuration for manifest processing rules
6263
- `ad_marker_passthrough` – For HLS, when set to true, MediaTailor passes through EXT-X-CUE-IN, EXT-X-CUE-OUT, and EXT-X-SPLICEPOINT-SCTE35 ad markers from the origin manifest to the MediaTailor personalized manifest.
6364
- `enabled` - Enables ad marker passthrough for your configuration.

examples/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ terraform {
33
awsmt = {
44
version = "~> 2.0.0"
55
source = "spring-media/awsmt"
6-
}
6+
}
77
}
88
}
9+
10+
provider "awsmt" {
11+
region = "eu-central-1"
12+
}

0 commit comments

Comments
 (0)