From 22c7bf057906a756374cd74ae1b6897b48fd38a6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Oct 2024 16:18:31 -0400 Subject: [PATCH] Cosmetics. --- internal/service/deploy/deployment_config.go | 208 ++++++++++--------- 1 file changed, 110 insertions(+), 98 deletions(-) diff --git a/internal/service/deploy/deployment_config.go b/internal/service/deploy/deployment_config.go index a2f67b44ab7..14000d17464 100644 --- a/internal/service/deploy/deployment_config.go +++ b/internal/service/deploy/deployment_config.go @@ -128,6 +128,7 @@ func resourceDeploymentConfig() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + Default: types.TrafficRoutingTypeAllAtOnce, ValidateDiagFunc: enum.Validate[types.TrafficRoutingType](), }, }, @@ -285,175 +286,186 @@ func findDeploymentConfigByName(ctx context.Context, conn *codedeploy.Client, na } func expandMinimumHealthyHosts(d *schema.ResourceData) *types.MinimumHealthyHosts { - hosts, ok := d.GetOk("minimum_healthy_hosts") + v, ok := d.GetOk("minimum_healthy_hosts") if !ok { return nil } - host := hosts.([]interface{})[0].(map[string]interface{}) - minimumHealthyHost := types.MinimumHealthyHosts{ - Type: types.MinimumHealthyHostsType(host[names.AttrType].(string)), - Value: int32(host[names.AttrValue].(int)), + tfMap := v.([]interface{})[0].(map[string]interface{}) + + apiObject := &types.MinimumHealthyHosts{ + Type: types.MinimumHealthyHostsType(tfMap[names.AttrType].(string)), + Value: int32(tfMap[names.AttrValue].(int)), } - return &minimumHealthyHost + return apiObject } func expandTrafficRoutingConfig(d *schema.ResourceData) *types.TrafficRoutingConfig { - block, ok := d.GetOk("traffic_routing_config") + v, ok := d.GetOk("traffic_routing_config") if !ok { return nil } - config := block.([]interface{})[0].(map[string]interface{}) - trafficRoutingConfig := types.TrafficRoutingConfig{} - if trafficType, ok := config[names.AttrType]; ok { - trafficRoutingConfig.Type = types.TrafficRoutingType(trafficType.(string)) + tfMap := v.([]interface{})[0].(map[string]interface{}) + apiObject := &types.TrafficRoutingConfig{} + + if v, ok := tfMap["time_based_canary"]; ok && len(v.([]interface{})) > 0 { + apiObject.TimeBasedCanary = expandTimeBasedCanary(v.([]interface{})[0].(map[string]interface{})) } - if canary, ok := config["time_based_canary"]; ok && len(canary.([]interface{})) > 0 { - canaryConfig := canary.([]interface{})[0].(map[string]interface{}) - trafficRoutingConfig.TimeBasedCanary = expandTimeBasedCanary(canaryConfig) + if v, ok := tfMap["time_based_linear"]; ok && len(v.([]interface{})) > 0 { + apiObject.TimeBasedLinear = expandTimeBasedLinear(v.([]interface{})[0].(map[string]interface{})) } - if linear, ok := config["time_based_linear"]; ok && len(linear.([]interface{})) > 0 { - linearConfig := linear.([]interface{})[0].(map[string]interface{}) - trafficRoutingConfig.TimeBasedLinear = expandTimeBasedLinear(linearConfig) + if v, ok := tfMap[names.AttrType]; ok { + apiObject.Type = types.TrafficRoutingType(v.(string)) } - return &trafficRoutingConfig + return apiObject } -func expandTimeBasedCanary(config map[string]interface{}) *types.TimeBasedCanary { - canary := types.TimeBasedCanary{} - if interval, ok := config[names.AttrInterval]; ok { - canary.CanaryInterval = int32(interval.(int)) +func expandTimeBasedCanary(tfMap map[string]interface{}) *types.TimeBasedCanary { + apiObject := &types.TimeBasedCanary{} + + if v, ok := tfMap[names.AttrInterval]; ok { + apiObject.CanaryInterval = int32(v.(int)) } - if percentage, ok := config["percentage"]; ok { - canary.CanaryPercentage = int32(percentage.(int)) + if v, ok := tfMap["percentage"]; ok { + apiObject.CanaryPercentage = int32(v.(int)) } - return &canary + + return apiObject } -func expandTimeBasedLinear(config map[string]interface{}) *types.TimeBasedLinear { - linear := types.TimeBasedLinear{} - if interval, ok := config[names.AttrInterval]; ok { - linear.LinearInterval = int32(interval.(int)) +func expandTimeBasedLinear(tfMap map[string]interface{}) *types.TimeBasedLinear { + apiObject := &types.TimeBasedLinear{} + + if v, ok := tfMap[names.AttrInterval]; ok { + apiObject.LinearInterval = int32(v.(int)) } - if percentage, ok := config["percentage"]; ok { - linear.LinearPercentage = int32(percentage.(int)) + if v, ok := tfMap["percentage"]; ok { + apiObject.LinearPercentage = int32(v.(int)) } - return &linear + + return apiObject } func expandZonalConfig(d *schema.ResourceData) *types.ZonalConfig { - block, ok := d.GetOk("zonal_config") + v, ok := d.GetOk("zonal_config") if !ok { return nil } - config := block.([]interface{})[0].(map[string]interface{}) - zonalConfig := types.ZonalConfig{} - if firstZoneMonitorDurationInSeconds, ok := config["first_zone_monitor_duration_in_seconds"].(int); ok { - zonalConfig.FirstZoneMonitorDurationInSeconds = aws.Int64(int64(firstZoneMonitorDurationInSeconds)) + + tfMap := v.([]interface{})[0].(map[string]interface{}) + apiObject := &types.ZonalConfig{} + + if v, ok := tfMap["first_zone_monitor_duration_in_seconds"].(int); ok { + apiObject.FirstZoneMonitorDurationInSeconds = aws.Int64(int64(v)) } - if minimumHealthyHostsPerZoneType, ok := config["minimum_healthy_hosts_per_zone"]; ok && len(minimumHealthyHostsPerZoneType.([]interface{})) > 0 { - minimumHealthyHostsPerZoneConfig := minimumHealthyHostsPerZoneType.([]interface{})[0].(map[string]interface{}) - zonalConfig.MinimumHealthyHostsPerZone = expandMinimumHealthyHostsPerZone(minimumHealthyHostsPerZoneConfig) + if v, ok := tfMap["minimum_healthy_hosts_per_zone"]; ok && len(v.([]interface{})) > 0 { + apiObject.MinimumHealthyHostsPerZone = expandMinimumHealthyHostsPerZone(v.([]interface{})[0].(map[string]interface{})) } - if monitorDurationInSeconds, ok := config["monitor_duration_in_seconds"].(int); ok { - zonalConfig.MonitorDurationInSeconds = aws.Int64(int64(monitorDurationInSeconds)) + if v, ok := tfMap["monitor_duration_in_seconds"].(int); ok { + apiObject.MonitorDurationInSeconds = aws.Int64(int64(v)) } - return &zonalConfig + return apiObject } -func expandMinimumHealthyHostsPerZone(config map[string]interface{}) *types.MinimumHealthyHostsPerZone { - minimumHealthyHostsPerZone := types.MinimumHealthyHostsPerZone{ - Type: types.MinimumHealthyHostsPerZoneType(config[names.AttrType].(string)), - Value: int32(config[names.AttrValue].(int)), +func expandMinimumHealthyHostsPerZone(tfMap map[string]interface{}) *types.MinimumHealthyHostsPerZone { + if tfMap == nil { + return nil } - return &minimumHealthyHostsPerZone + apiObject := &types.MinimumHealthyHostsPerZone{ + Type: types.MinimumHealthyHostsPerZoneType(tfMap[names.AttrType].(string)), + Value: int32(tfMap[names.AttrValue].(int)), + } + + return apiObject } -func flattenMinimumHealthHosts(hosts *types.MinimumHealthyHosts) []map[string]interface{} { - result := make([]map[string]interface{}, 0) - if hosts == nil { - return result - } +func flattenMinimumHealthHosts(apiObject *types.MinimumHealthyHosts) []interface{} { + tfList := make([]interface{}, 0) - item := make(map[string]interface{}) + if apiObject == nil { + return tfList + } - item[names.AttrType] = string(hosts.Type) - item[names.AttrValue] = hosts.Value + tfMap := make(map[string]interface{}) + tfMap[names.AttrType] = apiObject.Type + tfMap[names.AttrValue] = apiObject.Value - return append(result, item) + return append(tfList, tfMap) } -func flattenTrafficRoutingConfig(config *types.TrafficRoutingConfig) []map[string]interface{} { - result := make([]map[string]interface{}, 0) - if config == nil { - return result - } +func flattenTrafficRoutingConfig(apiObject *types.TrafficRoutingConfig) []interface{} { + tfList := make([]interface{}, 0) - item := make(map[string]interface{}) + if apiObject == nil { + return tfList + } - item[names.AttrType] = string(config.Type) - item["time_based_canary"] = flattenTimeBasedCanary(config.TimeBasedCanary) - item["time_based_linear"] = flattenTimeBasedLinear(config.TimeBasedLinear) + tfMap := make(map[string]interface{}) + tfMap["time_based_canary"] = flattenTimeBasedCanary(apiObject.TimeBasedCanary) + tfMap["time_based_linear"] = flattenTimeBasedLinear(apiObject.TimeBasedLinear) + tfMap[names.AttrType] = apiObject.Type - return append(result, item) + return append(tfList, tfMap) } -func flattenTimeBasedCanary(canary *types.TimeBasedCanary) []map[string]interface{} { - result := make([]map[string]interface{}, 0) - if canary == nil { - return result +func flattenTimeBasedCanary(apiObject *types.TimeBasedCanary) []interface{} { + tfList := make([]interface{}, 0) + + if apiObject == nil { + return tfList } - item := make(map[string]interface{}) - item[names.AttrInterval] = canary.CanaryInterval - item["percentage"] = canary.CanaryPercentage + tfMap := make(map[string]interface{}) + tfMap[names.AttrInterval] = apiObject.CanaryInterval + tfMap["percentage"] = apiObject.CanaryPercentage - return append(result, item) + return append(tfList, tfMap) } -func flattenTimeBasedLinear(linear *types.TimeBasedLinear) []map[string]interface{} { - result := make([]map[string]interface{}, 0) - if linear == nil { - return result +func flattenTimeBasedLinear(apiObject *types.TimeBasedLinear) []interface{} { + tfList := make([]interface{}, 0) + + if apiObject == nil { + return tfList } - item := make(map[string]interface{}) - item[names.AttrInterval] = linear.LinearInterval - item["percentage"] = linear.LinearPercentage + tfMap := make(map[string]interface{}) + tfMap[names.AttrInterval] = apiObject.LinearInterval + tfMap["percentage"] = apiObject.LinearPercentage - return append(result, item) + return append(tfList, tfMap) } -func flattenZonalConfig(config *types.ZonalConfig) []map[string]interface{} { - result := make([]map[string]interface{}, 0) +func flattenZonalConfig(apiObject *types.ZonalConfig) []interface{} { + tfList := make([]interface{}, 0) - if config == nil { + if apiObject == nil { return nil } - item := make(map[string]interface{}) - item["first_zone_monitor_duration_in_seconds"] = aws.Int64(*config.FirstZoneMonitorDurationInSeconds) - item["minimum_healthy_hosts_per_zone"] = flattenMinimumHealthHostsPerZone(config.MinimumHealthyHostsPerZone) - item["monitor_duration_in_seconds"] = aws.Int64(*config.MonitorDurationInSeconds) + tfMap := make(map[string]interface{}) + tfMap["first_zone_monitor_duration_in_seconds"] = aws.ToInt64(apiObject.FirstZoneMonitorDurationInSeconds) + tfMap["minimum_healthy_hosts_per_zone"] = flattenMinimumHealthHostsPerZone(apiObject.MinimumHealthyHostsPerZone) + tfMap["monitor_duration_in_seconds"] = aws.ToInt64(apiObject.MonitorDurationInSeconds) - return append(result, item) + return append(tfList, tfMap) } -func flattenMinimumHealthHostsPerZone(config *types.MinimumHealthyHostsPerZone) []map[string]interface{} { - result := make([]map[string]interface{}, 0) +func flattenMinimumHealthHostsPerZone(apiObject *types.MinimumHealthyHostsPerZone) []interface{} { + tfList := make([]interface{}, 0) - if config == nil { + if apiObject == nil { return nil } - item := make(map[string]interface{}) - item[names.AttrType] = string(config.Type) - item[names.AttrValue] = config.Value + tfMap := make(map[string]interface{}) + tfMap[names.AttrType] = apiObject.Type + tfMap[names.AttrValue] = apiObject.Value - return append(result, item) + return append(tfList, tfMap) }