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

New Data Source - AWS MediaConvert Queue #27075

Merged
merged 12 commits into from
Oct 19, 2023
Merged
3 changes: 3 additions & 0 deletions .changelog/27075.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_media_convert_queue
```
84 changes: 84 additions & 0 deletions internal/service/mediaconvert/queue_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package mediaconvert

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mediaconvert"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)

// @SDKDataSource("aws_media_convert_queue", name="Queue")
func DataSourceQueue() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceQueueRead,

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
},
}
}

func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient))
if err != nil {
return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err)
}

id := d.Get("id").(string)

resp, err := conn.GetQueueWithContext(ctx, &mediaconvert.GetQueueInput{
Name: aws.String(id),
})

if err != nil {
return sdkdiag.AppendErrorf(diags, "getting Media Convert Queue (%s): %s", id, err)
}

if resp == nil || resp.Queue == nil {
return sdkdiag.AppendErrorf(diags, "getting Media Convert Queue (%s): empty response", id)
}

d.SetId(aws.StringValue(resp.Queue.Name))
d.Set("name", resp.Queue.Name)
d.Set("arn", resp.Queue.Arn)
d.Set("status", resp.Queue.Status)

ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig
tags, err := listTags(ctx, conn, aws.StringValue(resp.Queue.Arn))

if err != nil {
return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", id, err)
}

if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tags for Media Convert Queue (%s): %s", id, err)
}

return diags
}
116 changes: 116 additions & 0 deletions internal/service/mediaconvert/queue_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package mediaconvert_test

import (
"testing"

"github.com/aws/aws-sdk-go/service/mediaconvert"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccMediaConvertQueueDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_media_convert_queue.test"
dataSourceName := "data.aws_media_convert_queue.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckQueueDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccQueueDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
),
},
},
})
}

func TestAccMediaConvertQueueDataSource_withStatus(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_media_convert_queue.test"
dataSourceName := "data.aws_media_convert_queue.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckQueueDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccQueueDataSourceConfig_status(rName, mediaconvert.QueueStatusActive),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "status", dataSourceName, "status"),
),
},
},
})
}

func TestAccMediaConvertQueueDataSource_withTags(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_media_convert_queue.test"
dataSourceName := "data.aws_media_convert_queue.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckQueueDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccQueueDataSourceConfig_tags(rName, "foo", "bar", "fizz", "buzz"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "tags.foo", dataSourceName, "tags.foo"),
resource.TestCheckResourceAttrPair(resourceName, "tags.fizz", dataSourceName, "tags.fizz"),
),
},
},
})
}

func testAccQueueDataSourceConfig_basic(rName string) string {
return acctest.ConfigCompose(
testAccQueueConfig_basic(rName),
`
data "aws_media_convert_queue" "test" {
id = aws_media_convert_queue.test.id
}
`)
}

func testAccQueueDataSourceConfig_status(rName, status string) string {
return acctest.ConfigCompose(
testAccQueueConfig_status(rName, status),
`
data "aws_media_convert_queue" "test" {
id = aws_media_convert_queue.test.id
}
`)
}

func testAccQueueDataSourceConfig_tags(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return acctest.ConfigCompose(
testAccQueueConfig_tags(rName, tagKey1, tagValue1, tagKey2, tagValue2),
`
data "aws_media_convert_queue" "test" {
id = aws_media_convert_queue.test.id
}
`)
}
8 changes: 7 additions & 1 deletion internal/service/mediaconvert/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions website/docs/d/media_convert_queue.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
subcategory: "Elemental MediaConvert"
layout: "aws"
page_title: "AWS: aws_media_convert_queue"
description: |-
Retrieve information about a AWS Elemental MediaConvert Queue.
---

# Resource: aws_media_convert_queue

Retrieve information about a AWS Elemental MediaConvert Queue.

## Example Usage

```terraform
data "aws_media_convert_queue" "example" {
id = "tf-example-queue"
}
```

## Argument Reference

The following arguments are supported:

* `id` - (Required) Unique identifier of the queue. The same as `name`.

## Attributes Reference

* `arn` - The Arn of the queue.
* `name` - The same as `id`.
* `status` - The status of the queue.
* `tags` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
Loading