Skip to content

Commit

Permalink
feat: Add rmtp output settings for medialive channels EP-11669 (#1013)
Browse files Browse the repository at this point in the history
* feat: Add rmtp output settings for medialive channels EP-11669

* chore: Add rmtp group and output definition EP-11669

* chore: Add rmtp output and group parser EP-11669

* feat: Mark destination parameters as optional EP-11669

The rtmp destination settings we need to create do not require username or password.
This commit marks the fields as optional

* feat: Extend parsers with rtmp output settings EP-11669

This commit adds the rtmpgroup and rtmpoutput settings to the outputgroup settings.
  • Loading branch information
sebastianhutter authored Feb 9, 2023
1 parent 9732765 commit c20b9e0
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ website/node_modules
log.txt
markdown-link-check*.txt
changelog.tmp
terraform-provider-aws
terraform-provider-aws*
aws/testdata/service/cloudformation/examplecompany-exampleservice-exampleresource/bin/handler
vendor/
# Test exclusions
Expand Down
79 changes: 75 additions & 4 deletions aws/media_live_channel_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,24 @@ func expandOutputGroups(outputGroups []interface{}) []*medialive.OutputGroup {
func expandOutputGroupSettings(s *schema.Set) *medialive.OutputGroupSettings {
if s.Len() > 0 {
settings := s.List()[0].(map[string]interface{})
return &medialive.OutputGroupSettings{
HlsGroupSettings: expandHlsGroupSettings(settings["hls_group_settings"].(*schema.Set)),

// we can now have either hls, rmtp group, or both settings specified,
// to ensure a working api we need to ensure not to attach an empty
// hls or rtmp group struct
outputGroupSettings := medialive.OutputGroupSettings{}
hlsGroupSettings := expandHlsGroupSettings(settings["hls_group_settings"].(*schema.Set))
rtmpGroupSettings := expandRtmpGroupSettings(settings["rtmp_group_settings"].(*schema.Set))

// hls and rtmp group settings dont implement comparison operators
// so we are checking for hardcoded fields in our module to not be NIL
if hlsGroupSettings.Mode != nil {
outputGroupSettings.HlsGroupSettings = hlsGroupSettings
}
if rtmpGroupSettings.AuthenticationScheme != nil {
outputGroupSettings.RtmpGroupSettings = rtmpGroupSettings
}

return &outputGroupSettings
} else {
log.Printf("[ERROR] MediaLive Channel: OutputGroupSettings can not be found")
return &medialive.OutputGroupSettings{}
Expand Down Expand Up @@ -227,9 +242,22 @@ func expandOutputs(outputs []interface{}) []*medialive.Output {
func expandOutputSettings(s *schema.Set) *medialive.OutputSettings {
if s.Len() > 0 {
settings := s.List()[0].(map[string]interface{})
return &medialive.OutputSettings{
HlsOutputSettings: expandHlsOutputSettings(settings["hls_output_settings"].(*schema.Set)),

// we can now have either hls or rmtp outputs, or both settings specified,
// to ensure a working api we need to ensure not to attach an empty
// hls or rtmp group struct
outputSettings := medialive.OutputSettings{}
hlsOutputSettings := expandHlsOutputSettings(settings["hls_output_settings"].(*schema.Set))
rtmpOutputSettings := expandRtmpOutputSettings(settings["rtmp_output_settings"].(*schema.Set))

if (*hlsOutputSettings != medialive.HlsOutputSettings{}) {
outputSettings.HlsOutputSettings = hlsOutputSettings
}
if (*rtmpOutputSettings != medialive.RtmpOutputSettings{}) {
outputSettings.RtmpOutputSettings = rtmpOutputSettings
}

return &outputSettings
} else {
log.Printf("[ERROR] MediaLive Channel: OutputSettings can not be found")
return &medialive.OutputSettings{}
Expand Down Expand Up @@ -611,3 +639,46 @@ func expandH264Settings(s *schema.Set) *medialive.H264Settings {
return &medialive.H264Settings{}
}
}

func expandRtmpGroupSettings(s *schema.Set) *medialive.RtmpGroupSettings {
if s.Len() > 0 {
settings := s.List()[0].(map[string]interface{})
return &medialive.RtmpGroupSettings{
AuthenticationScheme: aws.String(settings["authentication_scheme"].(string)),
CacheFullBehavior: aws.String(settings["cache_full_behavior"].(string)),
CacheLength: aws.Int64(int64(settings["cache_length"].(int))),
CaptionData: aws.String(settings["caption_data"].(string)),
InputLossAction: aws.String(settings["input_loss_action"].(string)),
RestartDelay: aws.Int64(int64(settings["restart_delay"].(int))),
}
} else {
log.Printf("[ERROR] MediaLive Channel: RtmpGroupSettings can not be found")
return &medialive.RtmpGroupSettings{}
}
}

func expandRtmpOutputSettings(s *schema.Set) *medialive.RtmpOutputSettings {
if s.Len() > 0 {
settings := s.List()[0].(map[string]interface{})
return &medialive.RtmpOutputSettings{
CertificateMode: aws.String(settings["certificate_mode"].(string)),
ConnectionRetryInterval: aws.Int64(int64(settings["connection_retry_interval"].(int))),
NumRetries: aws.Int64(int64(settings["num_retries"].(int))),
Destination: expandRtmpOutputDestination(settings["destination"].(*schema.Set)),
}
} else {
log.Printf("[ERROR] MediaLive Channel: RtmpOutputSettings can not be found")
return &medialive.RtmpOutputSettings{}
}
}

func expandRtmpOutputDestination(s *schema.Set) *medialive.OutputLocationRef {
if s.Len() > 0 {
settings := s.List()[0].(map[string]interface{})
return &medialive.OutputLocationRef{
DestinationRefId: aws.String(settings["destination_ref_id"].(string)),
}
} else {
return nil
}
}
73 changes: 71 additions & 2 deletions aws/resource_aws_media_live_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func resourceAwsMediaLiveChannel() *schema.Resource {
Schema: map[string]*schema.Schema{
"password_param": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"stream_name": {
Expand All @@ -80,7 +80,7 @@ func resourceAwsMediaLiveChannel() *schema.Resource {

"username": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
},
},
Expand Down Expand Up @@ -779,6 +779,43 @@ func resourceAwsMediaLiveChannel() *schema.Resource {
},
},
},
"rtmp_group_settings": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"authentication_scheme": {
Type: schema.TypeString,
Optional: true,
},
"cache_length": {
Type: schema.TypeInt,
Optional: true,
},
"restart_delay": {
Type: schema.TypeInt,
Optional: true,
},
"cache_full_behavior": {
Type: schema.TypeString,
Optional: true,
},
"caption_data": {
Type: schema.TypeString,
Optional: true,
},
"input_loss_action": {
Type: schema.TypeString,
Optional: true,
},
// excluding ad_markers as they aren't
// defined for the hls group settings either
// "ad_markers": {
//
// },
},
},
},
},
},
},
Expand Down Expand Up @@ -964,6 +1001,38 @@ func resourceAwsMediaLiveChannel() *schema.Resource {
},
},
},
"rtmp_output_settings": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_retry_interval": {
Type: schema.TypeInt,
Optional: true,
},
"num_retries": {
Type: schema.TypeInt,
Optional: true,
},
"certificate_mode": {
Type: schema.TypeString,
Optional: true,
},
"destination": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"destination_ref_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
},
},
},
Expand Down

0 comments on commit c20b9e0

Please sign in to comment.