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

resource/aws_elastictranscoder_preset: Prevent empty configuration block panics #14092

Merged
merged 1 commit into from
Jul 31, 2020
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
12 changes: 8 additions & 4 deletions aws/resource_aws_elastic_transcoder_preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func expandETThumbnails(d *schema.ResourceData) *elastictranscoder.Thumbnails {
}

l := list.([]interface{})
if len(l) == 0 {
if len(l) == 0 || l[0] == nil {
return nil
}
t := l[0].(map[string]interface{})
Expand Down Expand Up @@ -410,7 +410,7 @@ func expandETAudioParams(d *schema.ResourceData) *elastictranscoder.AudioParamet
}

l := list.([]interface{})
if len(l) == 0 {
if len(l) == 0 || l[0] == nil {
return nil
}
audio := l[0].(map[string]interface{})
Expand All @@ -427,7 +427,7 @@ func expandETAudioParams(d *schema.ResourceData) *elastictranscoder.AudioParamet

func expandETAudioCodecOptions(d *schema.ResourceData) *elastictranscoder.AudioCodecOptions {
l := d.Get("audio_codec_options").([]interface{})
if len(l) == 0 {
if len(l) == 0 || l[0] == nil {
return nil
}

Expand Down Expand Up @@ -456,7 +456,7 @@ func expandETAudioCodecOptions(d *schema.ResourceData) *elastictranscoder.AudioC

func expandETVideoParams(d *schema.ResourceData) *elastictranscoder.VideoParameters {
l := d.Get("video").([]interface{})
if len(l) == 0 {
if len(l) == 0 || l[0] == nil {
return nil
}
p := l[0].(map[string]interface{})
Expand Down Expand Up @@ -541,6 +541,10 @@ func expandETVideoWatermarks(d *schema.ResourceData) []*elastictranscoder.Preset
var watermarks []*elastictranscoder.PresetWatermark

for _, w := range s.List() {
if w == nil {
continue
}

p := w.(map[string]interface{})
watermark := &elastictranscoder.PresetWatermark{
HorizontalAlign: aws.String(p["horizontal_align"].(string)),
Expand Down
46 changes: 46 additions & 0 deletions aws/resource_aws_elastic_transcoder_preset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ func TestAccAWSElasticTranscoderPreset_disappears(t *testing.T) {
})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/14087
func TestAccAWSElasticTranscoderPreset_AudioCodecOptions_empty(t *testing.T) {
var preset elastictranscoder.Preset
resourceName := "aws_elastictranscoder_preset.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSElasticTranscoder(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckElasticTranscoderPresetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsElasticTranscoderPresetConfigAudioCodecOptionsEmpty(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckElasticTranscoderPresetExists(resourceName, &preset),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"audio_codec_options.#"}, // Due to incorrect schema (should be nested under audio)
},
},
})
}

func TestAccAWSElasticTranscoderPreset_Description(t *testing.T) {
var preset elastictranscoder.Preset
resourceName := "aws_elastictranscoder_preset.test"
Expand Down Expand Up @@ -213,6 +240,25 @@ resource "aws_elastictranscoder_preset" "test" {
`, rName)
}

func testAccAwsElasticTranscoderPresetConfigAudioCodecOptionsEmpty(rName string) string {
return fmt.Sprintf(`
resource "aws_elastictranscoder_preset" "test" {
container = "mp4"
name = %[1]q

audio {
audio_packing_mode = "SingleTrack"
bit_rate = 320
channels = 2
codec = "mp3"
sample_rate = 44100
}

audio_codec_options {}
}
`, rName)
}

func testAccAwsElasticTranscoderPresetConfigDescription(rName string, description string) string {
return fmt.Sprintf(`
resource "aws_elastictranscoder_preset" "test" {
Expand Down