Skip to content

Commit c16b1c0

Browse files
authored
Merge pull request #13973 from DrFaust92/r/elastictrascoder_refactor
r/elastic_transcoder_pipeline - add validations
2 parents 1b94378 + 683c0cf commit c16b1c0

4 files changed

Lines changed: 85 additions & 56 deletions

File tree

.changelog/13973.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```release-note:enhancement
2+
resource/aws_elastictranscoder_pipeline: Add plan time validations to `content_config.storage_class`, `content_config_permissions.access`, `content_config_permissions.grantee_type`,
3+
`notifications.completed`, `notifications.error`, `notifications.progressing`, `notifications.warning`,
4+
`thumbnail_config.storage_class`, `thumbnail_config_permissions.access`, `thumbnail_config_permissions.grantee_type`
5+
```

aws/resource_aws_elastic_transcoder_pipeline.go

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/aws/aws-sdk-go/service/elastictranscoder"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1213
)
1314

1415
func resourceAwsElasticTranscoderPipeline() *schema.Resource {
@@ -51,6 +52,10 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
5152
"storage_class": {
5253
Type: schema.TypeString,
5354
Optional: true,
55+
ValidateFunc: validation.StringInSlice([]string{
56+
"Standard",
57+
"ReducedRedundancy",
58+
}, false),
5459
},
5560
},
5661
},
@@ -64,7 +69,15 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
6469
"access": {
6570
Type: schema.TypeList,
6671
Optional: true,
67-
Elem: &schema.Schema{Type: schema.TypeString},
72+
Elem: &schema.Schema{
73+
Type: schema.TypeString,
74+
ValidateFunc: validation.StringInSlice([]string{
75+
"Read",
76+
"ReadAcp",
77+
"WriteAcp",
78+
"FullControl",
79+
}, false),
80+
},
6881
},
6982
"grantee": {
7083
Type: schema.TypeString,
@@ -73,6 +86,11 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
7386
"grantee_type": {
7487
Type: schema.TypeString,
7588
Optional: true,
89+
ValidateFunc: validation.StringInSlice([]string{
90+
"Canonical",
91+
"Email",
92+
"Group",
93+
}, false),
7694
},
7795
},
7896
},
@@ -88,17 +106,11 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
88106
Optional: true,
89107
Computed: true,
90108
ForceNew: true,
91-
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
92-
value := v.(string)
93-
if !regexp.MustCompile(`^[.0-9A-Za-z-_]+$`).MatchString(value) {
94-
errors = append(errors, fmt.Errorf(
95-
"only alphanumeric characters, hyphens, underscores, and periods allowed in %q", k))
96-
}
97-
if len(value) > 40 {
98-
errors = append(errors, fmt.Errorf("%q cannot be longer than 40 characters", k))
99-
}
100-
return
101-
},
109+
ValidateFunc: validation.All(
110+
validation.StringMatch(regexp.MustCompile(`^[.0-9A-Za-z-_]+$`),
111+
"only alphanumeric characters, hyphens, underscores, and periods allowed"),
112+
validation.StringLenBetween(1, 40),
113+
),
102114
},
103115

104116
"notifications": {
@@ -108,20 +120,24 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
108120
Elem: &schema.Resource{
109121
Schema: map[string]*schema.Schema{
110122
"completed": {
111-
Type: schema.TypeString,
112-
Optional: true,
123+
Type: schema.TypeString,
124+
Optional: true,
125+
ValidateFunc: validateArn,
113126
},
114127
"error": {
115-
Type: schema.TypeString,
116-
Optional: true,
128+
Type: schema.TypeString,
129+
Optional: true,
130+
ValidateFunc: validateArn,
117131
},
118132
"progressing": {
119-
Type: schema.TypeString,
120-
Optional: true,
133+
Type: schema.TypeString,
134+
Optional: true,
135+
ValidateFunc: validateArn,
121136
},
122137
"warning": {
123-
Type: schema.TypeString,
124-
Optional: true,
138+
Type: schema.TypeString,
139+
Optional: true,
140+
ValidateFunc: validateArn,
125141
},
126142
},
127143
},
@@ -160,6 +176,10 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
160176
"storage_class": {
161177
Type: schema.TypeString,
162178
Optional: true,
179+
ValidateFunc: validation.StringInSlice([]string{
180+
"Standard",
181+
"ReducedRedundancy",
182+
}, false),
163183
},
164184
},
165185
},
@@ -173,7 +193,15 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
173193
"access": {
174194
Type: schema.TypeList,
175195
Optional: true,
176-
Elem: &schema.Schema{Type: schema.TypeString},
196+
Elem: &schema.Schema{
197+
Type: schema.TypeString,
198+
ValidateFunc: validation.StringInSlice([]string{
199+
"Read",
200+
"ReadAcp",
201+
"WriteAcp",
202+
"FullControl",
203+
}, false),
204+
},
177205
},
178206
"grantee": {
179207
Type: schema.TypeString,
@@ -182,6 +210,11 @@ func resourceAwsElasticTranscoderPipeline() *schema.Resource {
182210
"grantee_type": {
183211
Type: schema.TypeString,
184212
Optional: true,
213+
ValidateFunc: validation.StringInSlice([]string{
214+
"Canonical",
215+
"Email",
216+
"Group",
217+
}, false),
185218
},
186219
},
187220
},
@@ -408,7 +441,8 @@ func resourceAwsElasticTranscoderPipelineUpdate(d *schema.ResourceData, meta int
408441
}
409442

410443
for _, w := range output.Warnings {
411-
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", *w.Code, *w.Message)
444+
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", aws.StringValue(w.Code),
445+
aws.StringValue(w.Message))
412446
}
413447

414448
return resourceAwsElasticTranscoderPipelineRead(d, meta)

aws/resource_aws_elastic_transcoder_pipeline_test.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package aws
33
import (
44
"fmt"
55
"reflect"
6+
"regexp"
67
"sort"
78
"testing"
89

910
"github.com/aws/aws-sdk-go/aws"
10-
"github.com/aws/aws-sdk-go/aws/awserr"
1111
"github.com/aws/aws-sdk-go/service/elastictranscoder"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -29,6 +29,7 @@ func TestAccAWSElasticTranscoderPipeline_basic(t *testing.T) {
2929
Config: awsElasticTranscoderPipelineConfigBasic(rName),
3030
Check: resource.ComposeTestCheckFunc(
3131
testAccCheckAWSElasticTranscoderPipelineExists(resourceName, pipeline),
32+
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "elastictranscoder", regexp.MustCompile(`pipeline/.+`)),
3233
),
3334
},
3435
{
@@ -110,16 +111,16 @@ func testAccCheckAWSElasticTranscoderPipeline_notifications(
110111
return func(s *terraform.State) error {
111112

112113
var notes []string
113-
if p.Notifications.Completed != nil && *p.Notifications.Completed != "" {
114+
if aws.StringValue(p.Notifications.Completed) != "" {
114115
notes = append(notes, "completed")
115116
}
116-
if p.Notifications.Error != nil && *p.Notifications.Error != "" {
117+
if aws.StringValue(p.Notifications.Error) != "" {
117118
notes = append(notes, "error")
118119
}
119-
if p.Notifications.Progressing != nil && *p.Notifications.Progressing != "" {
120+
if aws.StringValue(p.Notifications.Progressing) != "" {
120121
notes = append(notes, "progressing")
121122
}
122-
if p.Notifications.Warning != nil && *p.Notifications.Warning != "" {
123+
if aws.StringValue(p.Notifications.Warning) != "" {
123124
notes = append(notes, "warning")
124125
}
125126

@@ -212,7 +213,7 @@ func TestAccAWSElasticTranscoderPipeline_disappears(t *testing.T) {
212213
Config: awsElasticTranscoderPipelineConfigBasic(rName),
213214
Check: resource.ComposeTestCheckFunc(
214215
testAccCheckAWSElasticTranscoderPipelineExists(resourceName, pipeline),
215-
testAccCheckAWSElasticTranscoderPipelineDisappears(pipeline),
216+
testAccCheckResourceDisappears(testAccProvider, resourceAwsElasticTranscoderPipeline(), resourceName),
216217
),
217218
ExpectNonEmptyPlan: true,
218219
},
@@ -247,18 +248,6 @@ func testAccCheckAWSElasticTranscoderPipelineExists(n string, res *elastictransc
247248
}
248249
}
249250

250-
func testAccCheckAWSElasticTranscoderPipelineDisappears(res *elastictranscoder.Pipeline) resource.TestCheckFunc {
251-
return func(s *terraform.State) error {
252-
conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn
253-
254-
_, err := conn.DeletePipeline(&elastictranscoder.DeletePipelineInput{
255-
Id: res.Id,
256-
})
257-
258-
return err
259-
}
260-
}
261-
262251
func testAccCheckElasticTranscoderPipelineDestroy(s *terraform.State) error {
263252
conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn
264253

@@ -270,22 +259,16 @@ func testAccCheckElasticTranscoderPipelineDestroy(s *terraform.State) error {
270259
out, err := conn.ReadPipeline(&elastictranscoder.ReadPipelineInput{
271260
Id: aws.String(rs.Primary.ID),
272261
})
273-
274-
if err == nil {
275-
if out.Pipeline != nil && *out.Pipeline.Id == rs.Primary.ID {
276-
return fmt.Errorf("Elastic Transcoder Pipeline still exists")
277-
}
262+
if isAWSErr(err, elastictranscoder.ErrCodeResourceNotFoundException, "") {
263+
continue
278264
}
279-
280-
awsErr, ok := err.(awserr.Error)
281-
if !ok {
282-
return err
265+
if err != nil {
266+
return fmt.Errorf("unexpected error: %w", err)
283267
}
284268

285-
if awsErr.Code() != "ResourceNotFoundException" {
286-
return fmt.Errorf("unexpected error: %s", awsErr)
269+
if out.Pipeline != nil && aws.StringValue(out.Pipeline.Id) == rs.Primary.ID {
270+
return fmt.Errorf("Elastic Transcoder Pipeline still exists")
287271
}
288-
289272
}
290273
return nil
291274
}

website/docs/r/elastictranscoder_pipeline.html.markdown

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ you specify values for `content_config`, you must also specify values for
5757
The `content_config` object supports the following:
5858

5959
* `bucket` - The Amazon S3 bucket in which you want Elastic Transcoder to save transcoded files and playlists.
60-
* `storage_class` - The Amazon S3 storage class, Standard or ReducedRedundancy, that you want Elastic Transcoder to assign to the files and playlists that it stores in your Amazon S3 bucket.
60+
* `storage_class` - The Amazon S3 storage class, `Standard` or `ReducedRedundancy`, that you want Elastic Transcoder to assign to the files and playlists that it stores in your Amazon S3 bucket.
6161

6262
The `content_config_permissions` object supports the following:
6363

64-
* `access` - The permission that you want to give to the AWS user that you specified in `content_config_permissions.grantee`
64+
* `access` - The permission that you want to give to the AWS user that you specified in `content_config_permissions.grantee`. Valid values are `Read`, `ReadAcp`, `WriteAcp` or `FullControl`.
6565
* `grantee` - The AWS user or group that you want to have access to transcoded files and playlists.
6666
* `grantee_type` - Specify the type of value that appears in the `content_config_permissions.grantee` object. Valid values are `Canonical`, `Email` or `Group`.
6767

@@ -90,9 +90,16 @@ The `thumbnail_config` object supports the following:
9090

9191
The `thumbnail_config_permissions` object supports the following:
9292

93-
* `access` - The permission that you want to give to the AWS user that you specified in `thumbnail_config_permissions.grantee`.
93+
* `access` - The permission that you want to give to the AWS user that you specified in `thumbnail_config_permissions.grantee`. Valid values are `Read`, `ReadAcp`, `WriteAcp` or `FullControl`.
9494
* `grantee` - The AWS user or group that you want to have access to thumbnail files.
95-
* `grantee_type` - Specify the type of value that appears in the `thumbnail_config_permissions.grantee` object.
95+
* `grantee_type` - Specify the type of value that appears in the `thumbnail_config_permissions.grantee` object. Valid values are `Canonical`, `Email` or `Group`.
96+
97+
## Attributes Reference
98+
99+
In addition to all arguments above, the following attributes are exported:
100+
101+
* `id` - The ID of the Elastictranscoder pipeline.
102+
* `arn` - The ARN of the Elastictranscoder pipeline.
96103

97104
## Import
98105

0 commit comments

Comments
 (0)