provider/aws: Update ElasticTranscoder to allow empty notifications, removing notifications, etc (#8207)

* provider/aws: Add failing ETC + notifications test

* tidy up the docs some

* provider/aws: Update ElasticTranscoder to allow empty notifications, removing notifications, etc
This commit is contained in:
Clint 2016-08-16 13:41:12 -05:00 committed by GitHub
parent 601c757f90
commit 72a81ff3ae
3 changed files with 204 additions and 11 deletions

View File

@ -233,18 +233,23 @@ func expandETNotifications(d *schema.ResourceData) *elastictranscoder.Notificati
return nil
}
s := set.(*schema.Set)
if s == nil || s.Len() == 0 {
s := set.(*schema.Set).List()
if s == nil || len(s) == 0 {
return nil
}
m := s.List()[0].(map[string]interface{})
if s[0] == nil {
log.Printf("[ERR] First element of Notifications set is nil")
return nil
}
rN := s[0].(map[string]interface{})
return &elastictranscoder.Notifications{
Completed: getStringPtr(m, "completed"),
Error: getStringPtr(m, "error"),
Progressing: getStringPtr(m, "progressing"),
Warning: getStringPtr(m, "warning"),
Completed: aws.String(rN["completed"].(string)),
Error: aws.String(rN["error"].(string)),
Progressing: aws.String(rN["progressing"].(string)),
Warning: aws.String(rN["warning"].(string)),
}
}

View File

@ -2,11 +2,14 @@ package aws
import (
"fmt"
"reflect"
"sort"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elastictranscoder"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -30,6 +33,71 @@ func TestAccAWSElasticTranscoderPipeline_basic(t *testing.T) {
})
}
func TestAccAWSElasticTranscoderPipeline_notifications(t *testing.T) {
pipeline := elastictranscoder.Pipeline{}
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_elastictranscoder_pipeline.bar",
Providers: testAccProviders,
CheckDestroy: testAccCheckElasticTranscoderPipelineDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: awsElasticTranscoderNotifications(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.bar", &pipeline),
testAccCheckAWSElasticTranscoderPipeline_notifications(&pipeline, []string{"warning", "completed"}),
),
},
// update and check that we have 1 less notification
resource.TestStep{
Config: awsElasticTranscoderNotifications_update(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.bar", &pipeline),
testAccCheckAWSElasticTranscoderPipeline_notifications(&pipeline, []string{"completed"}),
),
},
},
})
}
// testAccCheckTags can be used to check the tags on a resource.
func testAccCheckAWSElasticTranscoderPipeline_notifications(
p *elastictranscoder.Pipeline, notifications []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
var notes []string
if p.Notifications.Completed != nil && *p.Notifications.Completed != "" {
notes = append(notes, "completed")
}
if p.Notifications.Error != nil && *p.Notifications.Error != "" {
notes = append(notes, "error")
}
if p.Notifications.Progressing != nil && *p.Notifications.Progressing != "" {
notes = append(notes, "progressing")
}
if p.Notifications.Warning != nil && *p.Notifications.Warning != "" {
notes = append(notes, "warning")
}
if len(notes) != len(notifications) {
return fmt.Errorf("ETC notifications didn't match:\n\texpected: %#v\n\tgot: %#v\n\n", notifications, notes)
}
sort.Strings(notes)
sort.Strings(notifications)
if !reflect.DeepEqual(notes, notifications) {
return fmt.Errorf("ETC notifications were not equal:\n\texpected: %#v\n\tgot: %#v\n\n", notifications, notes)
}
return nil
}
}
func TestAccAWSElasticTranscoderPipeline_withContentConfig(t *testing.T) {
pipeline := &elastictranscoder.Pipeline{}
@ -326,3 +394,122 @@ resource "aws_s3_bucket" "content_bucket" {
acl = "private"
}
`
func awsElasticTranscoderNotifications(r int) string {
return fmt.Sprintf(`
resource "aws_elastictranscoder_pipeline" "bar" {
input_bucket = "${aws_s3_bucket.test_bucket.bucket}"
output_bucket = "${aws_s3_bucket.test_bucket.bucket}"
name = "tf-transcoder-%d"
role = "${aws_iam_role.test_role.arn}"
notifications {
completed = "${aws_sns_topic.topic_example.arn}"
warning = "${aws_sns_topic.topic_example.arn}"
}
}
resource "aws_iam_role" "test_role" {
name = "tf-transcoder-%d"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_s3_bucket" "test_bucket" {
bucket = "tf-transcoder-%d"
acl = "private"
}
resource "aws_sns_topic" "topic_example" {
name = "tf-transcoder-%d"
policy = <<EOF
{
"Version": "2012-10-17",
"Id": "AWSAccountTopicAccess",
"Statement": [
{
"Sid": "*",
"Effect": "Allow",
"Principal": "*",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
EOF
}`, r, r, r, r)
}
func awsElasticTranscoderNotifications_update(r int) string {
return fmt.Sprintf(`
resource "aws_elastictranscoder_pipeline" "bar" {
input_bucket = "${aws_s3_bucket.test_bucket.bucket}"
output_bucket = "${aws_s3_bucket.test_bucket.bucket}"
name = "tf-transcoder-%d"
role = "${aws_iam_role.test_role.arn}"
notifications {
completed = "${aws_sns_topic.topic_example.arn}"
}
}
resource "aws_iam_role" "test_role" {
name = "tf-transcoder-%d"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_s3_bucket" "test_bucket" {
bucket = "tf-transcoder-%d"
acl = "private"
}
resource "aws_sns_topic" "topic_example" {
name = "tf-transcoder-%d"
policy = <<EOF
{
"Version": "2012-10-17",
"Id": "AWSAccountTopicAccess",
"Statement": [
{
"Sid": "*",
"Effect": "Allow",
"Principal": "*",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
EOF
}`, r, r, r, r)
}

View File

@ -66,20 +66,21 @@ The `content_config_permissions` object supports the following:
The `notifications` object supports the following:
* `completed` - The topic ARN for the Amazon SNS topic that you want to notify when Elastic Transcoder has finished processing a job in this pipeline.
* `error` - The topic ARN for the Amazon SNS topic that you want to notify when Elastic Transcoder encounters an error condition while processing a job in this pipeline.
* `progressing` - The topic ARN for the Amazon Simple Notification Service (Amazon SNS) topic that you want to notify when Elastic Transcoder has started to process a job in this pipeline.
* `warning` - The topic ARN for the Amazon SNS topic that you want to notify when Elastic Transcoder encounters a warning condition while processing a job in this pipeline.
The thumbnail_config object specifies information about the Amazon S3 bucket in
The `thumbnail_config` object specifies information about the Amazon S3 bucket in
which you want Elastic Transcoder to save thumbnail files: which bucket to use,
which users you want to have access to the files, the type of access you want
users to have, and the storage class that you want to assign to the files. If
you specify values for ContentConfig, you must also specify values for
ThumbnailConfig even if you don't want to create thumbnails. (You control
you specify values for `content_config`, you must also specify values for
`thumbnail_config` even if you don't want to create thumbnails. (You control
whether to create thumbnails when you create a job. For more information, see
ThumbnailPattern in the topic Create Job.) If you specify values for
ContentConfig and ThumbnailConfig, omit the OutputBucket object.
`content_config` and `thumbnail_config`, omit the OutputBucket object.
The `thumbnail_config` object supports the following: