-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36307 from hashicorp/f-medialive_input_data_source
[new data source] `aws_medialive_input`
- Loading branch information
Showing
5 changed files
with
314 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-data-source | ||
aws_medialive_input | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package medialive | ||
|
||
import ( | ||
"context" | ||
|
||
awstypes "github.com/aws/aws-sdk-go-v2/service/medialive/types" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
"github.com/hashicorp/terraform-provider-aws/internal/framework" | ||
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @FrameworkDataSource(name="Input") | ||
func newDataSourceInput(_ context.Context) (datasource.DataSourceWithConfigure, error) { | ||
return &dataSourceInput{}, nil | ||
} | ||
|
||
const ( | ||
DSNameInput = "Input Data Source" | ||
) | ||
|
||
type dataSourceInput struct { | ||
framework.DataSourceWithConfigure | ||
} | ||
|
||
func (d *dataSourceInput) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name | ||
resp.TypeName = "aws_medialive_input" | ||
} | ||
|
||
func (d *dataSourceInput) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"arn": framework.ARNAttributeComputedOnly(), | ||
"attached_channels": schema.ListAttribute{ | ||
CustomType: fwtypes.ListOfStringType, | ||
Computed: true, | ||
}, | ||
"destinations": schema.ListAttribute{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[dsDestination](ctx), | ||
Computed: true, | ||
}, | ||
"id": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
"input_class": schema.StringAttribute{ | ||
CustomType: fwtypes.StringEnumType[awstypes.InputClass](), | ||
Computed: true, | ||
}, | ||
"input_devices": schema.ListAttribute{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[dsInputDevice](ctx), | ||
Computed: true, | ||
}, | ||
"input_partner_ids": schema.ListAttribute{ | ||
CustomType: fwtypes.ListOfStringType, | ||
Computed: true, | ||
}, | ||
"input_source_type": schema.StringAttribute{ | ||
CustomType: fwtypes.StringEnumType[awstypes.InputSourceType](), | ||
Computed: true, | ||
}, | ||
"media_connect_flows": schema.ListAttribute{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[dsMediaConnectFlow](ctx), | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"role_arn": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"security_groups": schema.ListAttribute{ | ||
CustomType: fwtypes.ListOfStringType, | ||
Computed: true, | ||
}, | ||
"sources": schema.ListAttribute{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[dsInputSource](ctx), | ||
Computed: true, | ||
}, | ||
"state": schema.StringAttribute{ | ||
CustomType: fwtypes.StringEnumType[awstypes.InputState](), | ||
Computed: true, | ||
}, | ||
names.AttrTags: tags.TagsAttributeComputedOnly(), | ||
"type": schema.StringAttribute{ | ||
CustomType: fwtypes.StringEnumType[awstypes.InputType](), | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *dataSourceInput) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
conn := d.Meta().MediaLiveClient(ctx) | ||
|
||
var data dataSourceInputData | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
out, err := FindInputByID(ctx, conn, data.ID.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
create.ProblemStandardMessage(names.MediaLive, create.ErrActionReading, DSNameInput, data.ID.String(), err), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(fwflex.Flatten(ctx, out, &data)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
data.Tags = fwflex.FlattenFrameworkStringValueMap(ctx, out.Tags) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
type dataSourceInputData struct { | ||
ARN types.String `tfsdk:"arn"` | ||
AttachedChannels fwtypes.ListValueOf[types.String] `tfsdk:"attached_channels"` | ||
Destinations fwtypes.ListNestedObjectValueOf[dsDestination] `tfsdk:"destinations"` | ||
ID types.String `tfsdk:"id"` | ||
InputClass fwtypes.StringEnum[awstypes.InputClass] `tfsdk:"input_class"` | ||
InputDevices fwtypes.ListNestedObjectValueOf[dsInputDevice] `tfsdk:"input_devices"` | ||
InputPartnerIDs fwtypes.ListValueOf[types.String] `tfsdk:"input_partner_ids"` | ||
InputSourceType fwtypes.StringEnum[awstypes.InputSourceType] `tfsdk:"input_source_type"` | ||
MediaConnectFlows fwtypes.ListNestedObjectValueOf[dsMediaConnectFlow] `tfsdk:"media_connect_flows"` | ||
Name types.String `tfsdk:"name"` | ||
RoleARN types.String `tfsdk:"role_arn"` | ||
SecurityGroups fwtypes.ListValueOf[types.String] `tfsdk:"security_groups"` | ||
Sources fwtypes.ListNestedObjectValueOf[dsInputSource] `tfsdk:"sources"` | ||
State fwtypes.StringEnum[awstypes.InputState] `tfsdk:"state"` | ||
Tags types.Map `tfsdk:"tags"` | ||
Type fwtypes.StringEnum[awstypes.InputType] `tfsdk:"type"` | ||
} | ||
|
||
type dsDestination struct { | ||
IP types.String `tfsdk:"ip"` | ||
Port types.String `tfsdk:"port"` | ||
URL types.String `tfsdk:"url"` | ||
VPC fwtypes.ListNestedObjectValueOf[dsVPC] `tfsdk:"vpc"` | ||
} | ||
|
||
type dsVPC struct { | ||
AvailabilityZone types.String `tfsdk:"availability_zone"` | ||
NetworkInterfaceID types.String `tfsdk:"network_interface_id"` | ||
} | ||
|
||
type dsInputDevice struct { | ||
ID types.String `tfsdk:"id"` | ||
} | ||
|
||
type dsMediaConnectFlow struct { | ||
FlowARN types.String `tfsdk:"flow_arn"` | ||
} | ||
|
||
type dsInputSource struct { | ||
PasswordParam types.String `tfsdk:"password_param"` | ||
URL types.String `tfsdk:"url"` | ||
Username types.String `tfsdk:"username"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package medialive_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"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" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func TestAccMediaLiveInputDataSource_basic(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" | ||
dataSourceName := "data.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: testAccInputDataSourceConfig_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInputExists(ctx, dataSourceName, &input), | ||
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), | ||
resource.TestCheckResourceAttr(dataSourceName, "destinations.#", "2"), | ||
resource.TestCheckResourceAttrPair(resourceName, "input_class", dataSourceName, "input_class"), | ||
resource.TestCheckResourceAttrPair(resourceName, "input_devices", dataSourceName, "input_devices"), | ||
resource.TestCheckResourceAttrPair(resourceName, "input_partner_ids", dataSourceName, "input_partner_ids"), | ||
resource.TestCheckResourceAttrPair(resourceName, "input_source_type", dataSourceName, "input_source_type"), | ||
resource.TestCheckResourceAttrPair(resourceName, "security_groups", dataSourceName, "security_groups"), | ||
resource.TestCheckResourceAttrPair(resourceName, "sources", dataSourceName, "sources"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "state"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tag_all", dataSourceName, "tags"), | ||
resource.TestCheckResourceAttrPair(resourceName, "type", dataSourceName, "type"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccInputDataSourceConfig_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_medialive_input_security_group" "test" { | ||
whitelist_rules { | ||
cidr = "10.0.0.8/32" | ||
} | ||
tags = { | ||
Name = %[1]q | ||
} | ||
} | ||
resource "aws_medialive_input" "test" { | ||
name = %[1]q | ||
input_security_groups = [aws_medialive_input_security_group.test.id] | ||
type = "UDP_PUSH" | ||
tags = { | ||
Name = %[1]q | ||
} | ||
} | ||
data "aws_medialive_input" "test" { | ||
id = aws_medialive_input.test.id | ||
} | ||
`, rName) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
subcategory: "Elemental MediaLive" | ||
layout: "aws" | ||
page_title: "AWS: aws_medialive_input" | ||
description: |- | ||
Terraform data source for managing an AWS Elemental MediaLive Input. | ||
--- | ||
|
||
# Data Source: aws_medialive_input | ||
|
||
Terraform data source for managing an AWS Elemental MediaLive Input. | ||
|
||
## Example Usage | ||
|
||
### Basic Usage | ||
|
||
```terraform | ||
data "aws_medialive_input" "example" { | ||
id = aws_medialive_input.example.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are required: | ||
|
||
* `id` - (Required) The ID of the Input. | ||
|
||
## Attribute Reference | ||
|
||
This data source exports the following attributes in addition to the arguments above: | ||
|
||
* `arn` - ARN of the Input. | ||
* `attached_channels` - Channels attached to Input. | ||
* `destionations` - Destination settings for PUSH type inputs. | ||
* `input_class` - The input class. | ||
* `input_devices` - Settings for the devices. | ||
* `input_partner_ids` - A list of IDs for all Inputs which are partners of this one. | ||
* `input_source_type` - Source type of the input. | ||
* `media_connect_flows` - A list of the MediaConnect Flows. | ||
* `name` - Name of the input. | ||
* `role_arn` - The ARN of the role this input assumes during and after creation. | ||
* `security_groups` - List of input security groups. | ||
* `sources` - The source URLs for a PULL-type input. | ||
* `state` - The state of the input. | ||
* `tags` - A map of tags assigned to the Input. | ||
* `type` - The type of the input. |