Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/medialive_input: export destinations attribute #36243

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/36243.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_medialive_input: Export attribute `destinations`
```
51 changes: 51 additions & 0 deletions internal/service/medialive/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,25 @@ func ResourceInput() *schema.Resource {
"destinations": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"stream_name": {
Type: schema.TypeString,
Required: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"port": {
Type: schema.TypeString,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -282,6 +295,7 @@ func resourceInputRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("input_partner_ids", out.InputPartnerIds)
d.Set("input_security_groups", out.SecurityGroups)
d.Set("input_source_type", out.InputSourceType)
d.Set("destinations", flattenInputDestinations(out.Destinations))
d.Set("role_arn", out.RoleArn)
d.Set("sources", flattenSources(out.Sources))
d.Set("type", out.Type)
Expand Down Expand Up @@ -570,6 +584,43 @@ func flattenSources(apiObjects []types.InputSource) []interface{} {
return l
}

func flattenInputDestination(apiObject types.InputDestination) map[string]interface{} {
if apiObject == (types.InputDestination{}) {
return nil
}

m := map[string]interface{}{}

if v := apiObject.Ip; v != nil {
m["ip"] = aws.ToString(v)
}
if v := apiObject.Port; v != nil {
m["port"] = aws.ToString(v)
}
if v := apiObject.Url; v != nil {
m["url"] = aws.ToString(v)
}
return m
}

func flattenInputDestinations(apiObjects []types.InputDestination) []interface{} {
if len(apiObjects) == 0 {
return nil
}

var l []interface{}

for _, apiObject := range apiObjects {
if apiObject == (types.InputDestination{}) {
continue
}

l = append(l, flattenInputDestination(apiObject))
}

return l
}

func expandDestinations(tfList []interface{}) []types.InputDestinationRequest {
if len(tfList) == 0 {
return nil
Expand Down
44 changes: 44 additions & 0 deletions internal/service/medialive/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"context"
"errors"
"fmt"
"regexp"
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/service/medialive"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -60,6 +62,48 @@ func TestAccMediaLiveInput_basic(t *testing.T) {
})
}

func TestAccMediaLiveInput_destinations(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var input medialive.DescribeInputOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_medialive_input.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.MediaLiveEndpointID)
testAccInputsPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.MediaLiveServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInputDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInputConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckInputExists(ctx, resourceName, &input),
resource.TestCheckResourceAttrSet(resourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestMatchTypeSetElemNestedAttrs(resourceName, "destinations.*", map[string]*regexp.Regexp{
"ip": regexache.MustCompile("^[0-9]+\\.[0-9:]+\\.[0-9:]+\\.[0-9:]+$"),
"port": regexache.MustCompile("^[0-9]{4,}$"),
"url": regexache.MustCompile("^udp://"),
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccMediaLiveInput_update(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/medialive_input.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ This resource exports the following attributes in addition to the arguments abov
* `input_class` - The input class.
* `input_partner_ids` - A list of IDs for all Inputs which are partners of this one.
* `input_source_type` - Source type of the input.
* `destinations` - Destination settings for PUSH type inputs.

## Timeouts

Expand Down
Loading