diff --git a/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline.go b/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline.go index 5bf78bd614..6b9b8a5bed 100644 --- a/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline.go +++ b/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline.go @@ -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 + } + + if s[0] == nil { + log.Printf("[ERR] First element of Notifications set is nil") return nil } - m := s.List()[0].(map[string]interface{}) + 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)), } } diff --git a/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline_test.go b/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline_test.go index 7806bc1839..5c744a5644 100644 --- a/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline_test.go +++ b/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline_test.go @@ -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 = <