diff --git a/.gitignore b/.gitignore index 71858677203..44f865d0b8b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/aws/media_live_channel_structure.go b/aws/media_live_channel_structure.go index 5b8c04b2383..500093cbf37 100644 --- a/aws/media_live_channel_structure.go +++ b/aws/media_live_channel_structure.go @@ -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{} @@ -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{} @@ -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 + } +} diff --git a/aws/resource_aws_media_live_channel.go b/aws/resource_aws_media_live_channel.go index 3694fbdd6ff..a8ce1f38af7 100644 --- a/aws/resource_aws_media_live_channel.go +++ b/aws/resource_aws_media_live_channel.go @@ -65,7 +65,7 @@ func resourceAwsMediaLiveChannel() *schema.Resource { Schema: map[string]*schema.Schema{ "password_param": { Type: schema.TypeString, - Required: true, + Optional: true, }, "stream_name": { @@ -80,7 +80,7 @@ func resourceAwsMediaLiveChannel() *schema.Resource { "username": { Type: schema.TypeString, - Required: true, + Optional: true, }, }, }, @@ -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": { + // + // }, + }, + }, + }, }, }, }, @@ -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, + }, + }, + }, + }, + }, + }, + }, }, }, },