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 Resource: aws_media_store_container #2448

Merged
Merged
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 aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lightsail"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/aws/aws-sdk-go/service/rds"
Expand Down Expand Up @@ -188,6 +189,7 @@ type AWSClient struct {
batchconn *batch.Batch
athenaconn *athena.Athena
dxconn *directconnect.DirectConnect
mediastoreconn *mediastore.MediaStore
}

func (c *AWSClient) S3() *s3.S3 {
Expand Down Expand Up @@ -426,6 +428,7 @@ func (c *Config) Client() (interface{}, error) {
client.batchconn = batch.New(sess)
client.athenaconn = athena.New(sess)
client.dxconn = directconnect.New(sess)
client.mediastoreconn = mediastore.New(sess)

// Workaround for https://github.com/aws/aws-sdk-go/issues/1376
client.kinesisconn.Handlers.Retry.PushBack(func(r *request.Request) {
Expand Down
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func Provider() terraform.ResourceProvider {
"aws_main_route_table_association": resourceAwsMainRouteTableAssociation(),
"aws_mq_broker": resourceAwsMqBroker(),
"aws_mq_configuration": resourceAwsMqConfiguration(),
"aws_media_store_container": resourceAwsMediaStoreContainer(),
"aws_nat_gateway": resourceAwsNatGateway(),
"aws_network_acl": resourceAwsNetworkAcl(),
"aws_default_network_acl": resourceAwsDefaultNetworkAcl(),
Expand Down
136 changes: 136 additions & 0 deletions aws/resource_aws_media_store_container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package aws

import (
"fmt"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsMediaStoreContainer() *schema.Resource {
return &schema.Resource{
Create: resourceAwsMediaStoreContainerCreate,
Read: resourceAwsMediaStoreContainerRead,
Delete: resourceAwsMediaStoreContainerDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile("^\\w+$").MatchString(value) {
errors = append(errors, fmt.Errorf("%q must contain alphanumeric characters or underscores", k))
}
return
},
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceAwsMediaStoreContainerCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn

input := &mediastore.CreateContainerInput{
ContainerName: aws.String(d.Get("name").(string)),
}

_, err := conn.CreateContainer(input)
if err != nil {
return err
}
stateConf := &resource.StateChangeConf{
Pending: []string{mediastore.ContainerStatusCreating},
Target: []string{mediastore.ContainerStatusActive},
Refresh: mediaStoreContainerRefreshStatusFunc(conn, d.Get("name").(string)),
Timeout: 10 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

_, err = stateConf.WaitForState()
if err != nil {
return err
}

d.SetId(d.Get("name").(string))
return resourceAwsMediaStoreContainerRead(d, meta)
}

func resourceAwsMediaStoreContainerRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn

input := &mediastore.DescribeContainerInput{
ContainerName: aws.String(d.Id()),
}
resp, err := conn.DescribeContainer(input)
if err != nil {
return err
}
d.Set("arn", resp.Container.ARN)
d.Set("endpoint", resp.Container.Endpoint)
return nil
}

func resourceAwsMediaStoreContainerDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn

input := &mediastore.DeleteContainerInput{
ContainerName: aws.String(d.Id()),
}
_, err := conn.DeleteContainer(input)
if err != nil {
if isAWSErr(err, mediastore.ErrCodeContainerNotFoundException, "") {
d.SetId("")
return nil
}
return err
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
dcinput := &mediastore.DescribeContainerInput{
ContainerName: aws.String(d.Id()),
}
_, err := conn.DescribeContainer(dcinput)
if err != nil {
if isAWSErr(err, mediastore.ErrCodeContainerNotFoundException, "") {
return nil
}
return resource.NonRetryableError(err)
}
return resource.RetryableError(nil)
})
if err != nil {
return err
}

d.SetId("")
return nil
}

func mediaStoreContainerRefreshStatusFunc(conn *mediastore.MediaStore, cn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &mediastore.DescribeContainerInput{
ContainerName: aws.String(cn),
}
resp, err := conn.DescribeContainer(input)
if err != nil {
return nil, "failed", err
}
return resp, *resp.Container.Status, nil
}
}
73 changes: 73 additions & 0 deletions aws/resource_aws_media_store_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package aws

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAwsMediaStoreContainer_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsMediaStoreContainerDestroy,
Steps: []resource.TestStep{
{
Config: testAccMediaStoreContainerConfig(acctest.RandString(5)),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMediaStoreContainerExists("aws_media_store_container.test"),
),
},
},
})
}

func testAccCheckAwsMediaStoreContainerDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).mediastoreconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_media_store_container" {
continue
}

input := &mediastore.DescribeContainerInput{
ContainerName: aws.String(rs.Primary.ID),
}

resp, err := conn.DescribeContainer(input)
if err != nil {
if isAWSErr(err, mediastore.ErrCodeContainerNotFoundException, "") {
return nil
}
return err
}

if *resp.Container.Status != mediastore.ContainerStatusDeleting {
return fmt.Errorf("Media Store Container (%s) not deleted", rs.Primary.ID)
}
}
return nil
}

func testAccCheckAwsMediaStoreContainerExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

return nil
}
}

func testAccMediaStoreContainerConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_media_store_container" "test" {
name = "tf_mediastore_%s"
}`, rName)
}
12 changes: 12 additions & 0 deletions website/aws.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,18 @@
<li<%= sidebar_current("docs-aws-resource-mq-configuration") %>>
<a href="/docs/providers/aws/r/mq_configuration.html">aws_mq_configuration</a>
</li>

</ul>
</li>

<li<%= sidebar_current("docs-aws-resource-media-store") %>>
<a href="#">MediaStore Resources</a>
<ul class="nav nav-visible">

<li<%= sidebar_current("docs-aws-resource-media-store-container") %>>
<a href="/docs/providers/aws/r/media_store_container.html">aws_media_store_container</a>
</li>

</ul>
</li>

Expand Down
32 changes: 32 additions & 0 deletions website/docs/r/media_store_container.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: "aws"
page_title: "AWS: aws_media_store_container"
sidebar_current: "docs-aws-resource-media-store-container"
description: |-
Provides a MediaStore Container.
---

# aws_media_store_container

Provides a MediaStore Container.

## Example Usage

```hcl
resource "aws_media_store_container" "example" {
name = "example"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the container. Must contain alphanumeric characters or underscores.

## Attributes Reference

The following attributes are exported:

* `arn` - The ARN of the container.
* `endpoint` - The DNS endpoint of the container.