From a4f0af1434d16b1f468bf8c85996fcd56fd75c3e Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 6 Mar 2019 13:09:04 -0800 Subject: [PATCH] Safely access maps in storage transfer (#1476) Merged PR #1476. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../resource_storage_transfer_job.go | 47 ++++++++++++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/build/terraform b/build/terraform index 11bb32121955..92dff97bbc2a 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 11bb32121955b2c675ddda56c365d95cb075a56f +Subproject commit 92dff97bbc2a661b8903379db7b397cbac07f1e1 diff --git a/build/terraform-beta b/build/terraform-beta index f38e731247e1..333524cf0e51 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit f38e731247e181eda2c78516f8da801455d11872 +Subproject commit 333524cf0e5115507e62e15cea322b5a851230fb diff --git a/third_party/terraform/resources/resource_storage_transfer_job.go b/third_party/terraform/resources/resource_storage_transfer_job.go index 5e9455533cc7..e2b0711503db 100644 --- a/third_party/terraform/resources/resource_storage_transfer_job.go +++ b/third_party/terraform/resources/resource_storage_transfer_job.go @@ -491,12 +491,23 @@ func expandDates(dates []interface{}) *storagetransfer.Date { return nil } - date := dates[0].([]interface{}) - return &storagetransfer.Date{ - Day: int64(extractFirstMapConfig(date)["day"].(int)), - Month: int64(extractFirstMapConfig(date)["month"].(int)), - Year: int64(extractFirstMapConfig(date)["year"].(int)), + dateElem := dates[0].([]interface{}) + date := &storagetransfer.Date{} + + dateMap := extractFirstMapConfig(dateElem) + if v, ok := dateMap["day"]; ok { + date.Day = int64(v.(int)) + } + + if v, ok := dateMap["month"]; ok { + date.Month = int64(v.(int)) } + + if v, ok := dateMap["year"]; ok { + date.Year = int64(v.(int)) + } + + return date } func flattenDate(date *storagetransfer.Date) []map[string]interface{} { @@ -514,13 +525,27 @@ func expandTimeOfDays(times []interface{}) *storagetransfer.TimeOfDay { return nil } - time := times[0].([]interface{}) - return &storagetransfer.TimeOfDay{ - Hours: int64(extractFirstMapConfig(time)["hours"].(int)), - Minutes: int64(extractFirstMapConfig(time)["minutes"].(int)), - Seconds: int64(extractFirstMapConfig(time)["seconds"].(int)), - Nanos: int64(extractFirstMapConfig(time)["nanos"].(int)), + timeElem := times[0].([]interface{}) + time := &storagetransfer.TimeOfDay{} + + timeMap := extractFirstMapConfig(timeElem) + if v, ok := timeMap["hours"]; ok { + time.Hours = int64(v.(int)) + } + + if v, ok := timeMap["minutes"]; ok { + time.Minutes = int64(v.(int)) + } + + if v, ok := timeMap["seconds"]; ok { + time.Seconds = int64(v.(int)) } + + if v, ok := timeMap["nanos"]; ok { + time.Nanos = int64(v.(int)) + } + + return time } func flattenTimeOfDay(timeOfDay *storagetransfer.TimeOfDay) []map[string]interface{} {