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

r/elastic_transcoder_pipeline - add validations #13973

Merged
merged 12 commits into from
Feb 12, 2021
5 changes: 5 additions & 0 deletions .changelog/13973.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:enhancement
resource/aws_elastictranscoder_pipeline: Add plan time validations `content_config.storage_class`, `content_config_permissions.access`, `content_config_permissions.grantee`, `content_config_permissions.grantee_type`,
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
`notifications.completed`, `notifications.error`, `notifications.progressing`, `notifications.warning`,
`thumbnail_config.storage_class`, `thumbnail_config_permissions.access`, `thumbnail_config_permissions.grantee`, `thumbnail_config_permissions.grantee_type`
```
88 changes: 66 additions & 22 deletions aws/resource_aws_elastic_transcoder_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/service/elastictranscoder"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceAwsElasticTranscoderPipeline() *schema.Resource {
Expand Down Expand Up @@ -51,6 +52,10 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
"storage_class": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Standard",
"ReducedRedundancy",
}, false),
},
},
},
Expand All @@ -64,15 +69,33 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
"access": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"Read",
"ReadAcp",
"WriteAcp",
"FullControl",
}, false),
},
},
"grantee": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
"AllUsers",
"AuthenticatedUsers",
"LogDelivery",
}, false),
},
"grantee_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Canonical",
"Email",
"Group",
}, false),
},
},
},
Expand All @@ -88,17 +111,11 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[.0-9A-Za-z-_]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters, hyphens, underscores, and periods allowed in %q", k))
}
if len(value) > 40 {
errors = append(errors, fmt.Errorf("%q cannot be longer than 40 characters", k))
}
return
},
ValidateFunc: validation.All(
validation.StringMatch(regexp.MustCompile(`^[.0-9A-Za-z-_]+$`),
"only alphanumeric characters, hyphens, underscores, and periods allowed"),
validation.StringLenBetween(1, 40),
),
},

"notifications": {
Expand All @@ -108,20 +125,24 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"completed": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"error": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"progressing": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"warning": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
},
},
Expand Down Expand Up @@ -160,6 +181,10 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
"storage_class": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Standard",
"ReducedRedundancy",
}, false),
},
},
},
Expand All @@ -173,15 +198,33 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
"access": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"Read",
"ReadAcp",
"WriteAcp",
"FullControl",
}, false),
},
},
"grantee": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
"AllUsers",
"AuthenticatedUsers",
"LogDelivery",
}, false),
},
"grantee_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Canonical",
"Email",
"Group",
}, false),
},
},
},
Expand Down Expand Up @@ -408,7 +451,8 @@ func resourceAwsElasticTranscoderPipelineUpdate(d *schema.ResourceData, meta int
}

for _, w := range output.Warnings {
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", *w.Code, *w.Message)
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", aws.StringValue(w.Code),
aws.StringValue(w.Message))
}

return resourceAwsElasticTranscoderPipelineRead(d, meta)
Expand Down
37 changes: 10 additions & 27 deletions aws/resource_aws_elastic_transcoder_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package aws
import (
"fmt"
"reflect"
"regexp"
"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-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -29,6 +29,7 @@ func TestAccAWSElasticTranscoderPipeline_basic(t *testing.T) {
Config: awsElasticTranscoderPipelineConfigBasic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticTranscoderPipelineExists(resourceName, pipeline),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "elastictranscoder", regexp.MustCompile(`pipeline/.+`)),
),
},
{
Expand Down Expand Up @@ -110,16 +111,16 @@ func testAccCheckAWSElasticTranscoderPipeline_notifications(
return func(s *terraform.State) error {

var notes []string
if p.Notifications.Completed != nil && *p.Notifications.Completed != "" {
if p.Notifications.Completed != nil && aws.StringValue(p.Notifications.Completed) != "" {
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
notes = append(notes, "completed")
}
if p.Notifications.Error != nil && *p.Notifications.Error != "" {
if p.Notifications.Error != nil && aws.StringValue(p.Notifications.Error) != "" {
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
notes = append(notes, "error")
}
if p.Notifications.Progressing != nil && *p.Notifications.Progressing != "" {
if p.Notifications.Progressing != nil && aws.StringValue(p.Notifications.Progressing) != "" {
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
notes = append(notes, "progressing")
}
if p.Notifications.Warning != nil && *p.Notifications.Warning != "" {
if p.Notifications.Warning != nil && aws.StringValue(p.Notifications.Warning) != "" {
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
notes = append(notes, "warning")
}

Expand Down Expand Up @@ -212,7 +213,7 @@ func TestAccAWSElasticTranscoderPipeline_disappears(t *testing.T) {
Config: awsElasticTranscoderPipelineConfigBasic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticTranscoderPipelineExists(resourceName, pipeline),
testAccCheckAWSElasticTranscoderPipelineDisappears(pipeline),
testAccCheckResourceDisappears(testAccProvider, resourceAwsElasticTranscoderPipeline(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -247,18 +248,6 @@ func testAccCheckAWSElasticTranscoderPipelineExists(n string, res *elastictransc
}
}

func testAccCheckAWSElasticTranscoderPipelineDisappears(res *elastictranscoder.Pipeline) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn

_, err := conn.DeletePipeline(&elastictranscoder.DeletePipelineInput{
Id: res.Id,
})

return err
}
}

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

Expand All @@ -272,20 +261,14 @@ func testAccCheckElasticTranscoderPipelineDestroy(s *terraform.State) error {
})

if err == nil {
if out.Pipeline != nil && *out.Pipeline.Id == rs.Primary.ID {
if out.Pipeline != nil && aws.StringValue(out.Pipeline.Id) == rs.Primary.ID {
return fmt.Errorf("Elastic Transcoder Pipeline still exists")
}
}

awsErr, ok := err.(awserr.Error)
if !ok {
return err
}

if awsErr.Code() != "ResourceNotFoundException" {
return fmt.Errorf("unexpected error: %s", awsErr)
if !isAWSErr(err, elastictranscoder.ErrCodeResourceNotFoundException, "") {
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("unexpected error: %s", err)
}

}
return nil
}
Expand Down