From a0c08676aa9b9d8c1588e7e56182a568761f7885 Mon Sep 17 00:00:00 2001 From: Tony Fouchard Date: Fri, 10 Mar 2023 18:10:38 +0100 Subject: [PATCH 1/2] Keep as much as possible traffic targets and liveness tests declaration order --- go.mod | 1 + go.sum | 4 + .../gtm/resource_akamai_gtm_geomap.go | 91 ++++-- .../gtm/resource_akamai_gtm_property.go | 295 ++++++++++-------- 4 files changed, 235 insertions(+), 156 deletions(-) diff --git a/go.mod b/go.mod index 79eedfac7..000d0d2ac 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/spf13/cast v1.3.1 github.com/stretchr/testify v1.7.2 github.com/tj/assert v0.0.3 + golang.org/x/exp v0.0.0-20230307190834-24139beb5833 google.golang.org/grpc v1.50.1 ) diff --git a/go.sum b/go.sum index a3da93d45..eb84032db 100644 --- a/go.sum +++ b/go.sum @@ -263,6 +263,8 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0= golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKMIXrEpFxNMs0spT3/5s= +golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -318,6 +320,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/pkg/providers/gtm/resource_akamai_gtm_geomap.go b/pkg/providers/gtm/resource_akamai_gtm_geomap.go index fae89cfef..2846d712e 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_geomap.go +++ b/pkg/providers/gtm/resource_akamai_gtm_geomap.go @@ -11,6 +11,8 @@ import ( "github.com/akamai/terraform-provider-akamai/v3/pkg/tools" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "golang.org/x/exp/slices" ) func resourceGTMv1Geomap() *schema.Resource { @@ -456,47 +458,70 @@ func populateGeoAssignmentsObject(d *schema.ResourceData, geo *gtm.GeoMap, m int } } -// create and populate Terraform geoMap assignments schema -func populateTerraformGeoAssignmentsState(d *schema.ResourceData, geo *gtm.GeoMap, m interface{}) { +func setGeoAssignmentAtIndex(asArr *[]interface{}, as *gtm.GeoAssignment, index int, doReplace bool, m interface{}) { meta := akamai.Meta(m) - logger := meta.Log("Akamai GTM", "populateTerraformGeoAssignmentsState") + logger := meta.Log("Akamai GTM", "setGeoAssignmentAtIndex") - objectInventory := make(map[int]*gtm.GeoAssignment, len(geo.Assignments)) - if len(geo.Assignments) > 0 { - for _, aObj := range geo.Assignments { - objectInventory[aObj.DatacenterId] = aObj + if !doReplace { + newInt := make([]interface{}, 1) + newInt[0] = make(map[string]interface{}) + if index == 0 { + *asArr = append(newInt, *asArr...) + } else { + *asArr = append((*asArr)[:index], append(newInt, (*asArr)[index:]...)...) } } - aStateList, _ := tools.GetInterfaceArrayValue("assignment", d) - for _, aMap := range aStateList { - a := aMap.(map[string]interface{}) - objIndex := a["datacenter_id"].(int) - aObject := objectInventory[objIndex] - if aObject == nil { - logger.Warnf("Geo Assignment %d NOT FOUND in returned GTM Object", a["datacenter_id"]) - continue - } - a["datacenter_id"] = aObject.DatacenterId - a["nickname"] = aObject.Nickname - countries, ok := a["countries"].(*schema.Set) - if !ok { + + targetAs := (*asArr)[index].(map[string]interface{}) + targetAs["datacenter_id"] = as.DatacenterId + targetAs["nickname"] = as.Nickname + + cts, ok := targetAs["countries"] + if ok { + countries, cOk := cts.(*schema.Set) + if !cOk { logger.Warnf("wrong type conversion: expected *schema.Set, got %T", countries) } - a["countries"] = reconcileTerraformLists(countries.List(), convertStringToInterfaceList(aObject.Countries, m), m) - // remove object - delete(objectInventory, objIndex) - } - if len(objectInventory) > 0 { - logger.Debugf("Geo Assignment objects left...") - // Objects not in the state yet. Add. Unfortunately, they not align with instance indices in the config - for _, maObj := range objectInventory { - aNew := map[string]interface{}{ - "datacenter_id": maObj.DatacenterId, - "nickname": maObj.Nickname, - "countries": maObj.Countries, + targetAs["countries"] = reconcileTerraformLists(countries.List(), convertStringToInterfaceList(as.Countries, m), m) + } else { + targetAs["countries"] = as.Countries + } +} + +// create and populate Terraform geoMap assignments schema +func populateTerraformGeoAssignmentsState(d *schema.ResourceData, geo *gtm.GeoMap, m interface{}) { + meta := akamai.Meta(m) + logger := meta.Log("Akamai GTM", "populateTerraformGeoAssignmentsState") + + aStateList, _ := tools.GetInterfaceArrayValue("assignment", d) + stateIdx := 0 + + for _, aObj := range geo.Assignments { + idx := slices.IndexFunc(aStateList, func(as interface{}) bool { + return as.(map[string]interface{})["datacenter_id"].(int) == aObj.DatacenterId + }) + + if idx == -1 { + if stateIdx == 0 { + logger.Debugf("assignment for dc %s not found into the state, prepending it", aObj.DatacenterId) + setGeoAssignmentAtIndex(&aStateList, aObj, 0, false, m) + } else { + logger.Debugf("assignment for dc %s not found into the state, inserting it at position %s into the state", aObj.DatacenterId, stateIdx) + setGeoAssignmentAtIndex(&aStateList, aObj, stateIdx, false, m) + } + } else { + if idx < stateIdx { + stateIdx-- + logger.Debugf("assignment for dc %s will now be placed after the position it was in the past (moving it from %s to %s)", aObj.DatacenterId, idx, stateIdx) + aStateList = append(aStateList[:idx], aStateList[idx+1:]...) + setGeoAssignmentAtIndex(&aStateList, aObj, stateIdx, false, m) + } else { + logger.Debugf("assignment for dc %s will be updated in-place into the state (index %s)", aObj.DatacenterId, idx) + setGeoAssignmentAtIndex(&aStateList, aObj, idx, true, m) + stateIdx = idx } - aStateList = append(aStateList, aNew) } + stateIdx++ } if err := d.Set("assignment", aStateList); err != nil { logger.Errorf("populateTerraformGeoAssignmentsState failed: %s", err.Error()) diff --git a/pkg/providers/gtm/resource_akamai_gtm_property.go b/pkg/providers/gtm/resource_akamai_gtm_property.go index fdf3c5268..dc66a8ea2 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_property.go +++ b/pkg/providers/gtm/resource_akamai_gtm_property.go @@ -14,6 +14,8 @@ import ( "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "golang.org/x/exp/slices" ) func resourceGTMv1Property() *schema.Resource { @@ -181,6 +183,7 @@ func resourceGTMv1Property() *schema.Resource { Optional: true, MinItems: 1, DiffSuppressFunc: trafficTargetDiffSuppress, + //DiffSuppressOnRefresh: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "datacenter_id": { @@ -939,51 +942,112 @@ func populateTrafficTargetObject(ctx context.Context, d *schema.ResourceData, pr } } +func setTrafficTargetAtIndex(ttArr *[]interface{}, tt *gtm.TrafficTarget, index int, doReplace bool) { + if !doReplace { + newInt := make([]interface{}, 1) + newInt[0] = make(map[string]interface{}) + if index == 0 { + *ttArr = append(newInt, *ttArr...) + } else { + *ttArr = append((*ttArr)[:index], append(newInt, (*ttArr)[index:]...)...) + } + } + + targetTt := (*ttArr)[index].(map[string]interface{}) + targetTt["datacenter_id"] = tt.DatacenterId + targetTt["enabled"] = tt.Enabled + targetTt["weight"] = tt.Weight + targetTt["name"] = tt.Name + targetTt["handout_cname"] = tt.HandoutCName + targetTt["servers"] = tt.Servers +} + // create and populate Terraform traffic_targets schema func populateTerraformTrafficTargetState(d *schema.ResourceData, prop *gtm.Property, m interface{}) { meta := akamai.Meta(m) logger := meta.Log("Akamai GTM", "populateTerraformTrafficTargetState") - objectInventory := make(map[int]*gtm.TrafficTarget, len(prop.TrafficTargets)) - if len(prop.TrafficTargets) > 0 { - for _, aObj := range prop.TrafficTargets { - objectInventory[aObj.DatacenterId] = aObj - } - } ttStateList, _ := tools.GetInterfaceArrayValue("traffic_target", d) - for _, ttMap := range ttStateList { - tt := ttMap.(map[string]interface{}) - objIndex := tt["datacenter_id"].(int) - ttObject := objectInventory[objIndex] - if ttObject == nil { - logger.Warnf("Property TrafficTarget %d NOT FOUND in returned GTM Object", tt["datacenter_id"]) - continue - } - tt["datacenter_id"] = ttObject.DatacenterId - tt["name"] = ttObject.Name - tt["enabled"] = ttObject.Enabled - tt["weight"] = ttObject.Weight - tt["handout_cname"] = ttObject.HandoutCName - tt["servers"] = ttObject.Servers - // remove object - delete(objectInventory, objIndex) - } - if len(objectInventory) > 0 { - // Objects not in the state yet. Add. Unfortunately, they not align with instance indices in the config - for _, mttObj := range objectInventory { - logger.Debugf("Property TrafficObject NEW State Object: %d", mttObj.DatacenterId) - ttNew := map[string]interface{}{ - "datacenter_id": mttObj.DatacenterId, - "enabled": mttObj.Enabled, - "weight": mttObj.Weight, - "name": mttObj.Name, - "handout_cname": mttObj.HandoutCName, - "servers": mttObj.Servers, + stateIdx := 0 + + for _, aObj := range prop.TrafficTargets { + idx := slices.IndexFunc(ttStateList, func(tt interface{}) bool { + return tt.(map[string]interface{})["datacenter_id"].(int) == aObj.DatacenterId + }) + + if idx == -1 { + if stateIdx == 0 { + logger.Debugf("traffic_target for dc %s not found into the state, prepending it", aObj.DatacenterId) + setTrafficTargetAtIndex(&ttStateList, aObj, 0, false) + } else { + logger.Debugf("traffic_target for dc %s not found into the state, inserting it at position %s into the state", aObj.DatacenterId, stateIdx) + setTrafficTargetAtIndex(&ttStateList, aObj, stateIdx, false) + } + } else { + if idx < stateIdx { + stateIdx-- + logger.Debugf("traffic_target for dc %s will now be placed after the position it was in the past (moving it from %s to %s)", aObj.DatacenterId, idx, stateIdx) + ttStateList = append(ttStateList[:idx], ttStateList[idx+1:]...) + setTrafficTargetAtIndex(&ttStateList, aObj, stateIdx, false) + } else { + logger.Debugf("traffic_target for dc %s will be updated in-place into the state (index %s)", aObj.DatacenterId, idx) + setTrafficTargetAtIndex(&ttStateList, aObj, idx, true) + stateIdx = idx } - ttStateList = append(ttStateList, ttNew) } + stateIdx++ } _ = d.Set("traffic_target", ttStateList) + /* + meta := akamai.Meta(m) + logger := meta.Log("Akamai GTM", "populateTerraformTrafficTargetState") + + objectInventory := make(map[int]*gtm.TrafficTarget, len(prop.TrafficTargets)) + objectInventoryDcs := make([]int, len(prop.TrafficTargets)) + if len(prop.TrafficTargets) > 0 { + for i, aObj := range prop.TrafficTargets { + objectInventory[aObj.DatacenterId] = aObj + objectInventoryDcs[i] = aObj.DatacenterId + } + } + + ttStateList, _ := tools.GetInterfaceArrayValue("traffic_target", d) + for _, ttMap := range ttStateList { + tt := ttMap.(map[string]interface{}) + objIndex := tt["datacenter_id"].(int) + ttObject := objectInventory[objIndex] + if ttObject == nil { + logger.Warnf("Property TrafficTarget %d NOT FOUND in returned GTM Object", tt["datacenter_id"]) + continue + } + tt["datacenter_id"] = ttObject.DatacenterId + tt["name"] = ttObject.Name + tt["enabled"] = ttObject.Enabled + tt["weight"] = ttObject.Weight + tt["handout_cname"] = ttObject.HandoutCName + tt["servers"] = ttObject.Servers + // Get dc index in objectInventoryDcs slice and remove object + elementBaseIdx := slices.Index(objectInventoryDcs, ttObject.DatacenterId) + objectInventoryDcs = append(objectInventoryDcs[:elementBaseIdx], objectInventoryDcs[elementBaseIdx+1:]...) + } + if len(objectInventoryDcs) > 0 { + // Objects not in the state yet. Add. + for _, dcId := range objectInventoryDcs { + mttObj := objectInventory[dcId] + logger.Debugf("Property TrafficObject NEW State Object: %d", mttObj.DatacenterId) + ttNew := map[string]interface{}{ + "datacenter_id": mttObj.DatacenterId, + "enabled": mttObj.Enabled, + "weight": mttObj.Weight, + "name": mttObj.Name, + "handout_cname": mttObj.HandoutCName, + "servers": mttObj.Servers, + } + ttStateList = append(ttStateList, ttNew) + } + } + _ = d.Set("traffic_target", ttStateList) + */ } // Populate existing static_rr_sets object from resource data @@ -1102,104 +1166,89 @@ func populateLivenessTestObject(ctx context.Context, meta akamai.OperationMeta, } } +func setLivenessTestAtIndex(ltArr *[]interface{}, lt *gtm.LivenessTest, index int, doReplace bool) { + if !doReplace { + newInt := make([]interface{}, 1) + newInt[0] = make(map[string]interface{}) + if index == 0 { + *ltArr = append(newInt, *ltArr...) + } else { + *ltArr = append((*ltArr)[:index], append(newInt, (*ltArr)[index:]...)...) + } + } + + httpHeaderListNew := make([]interface{}, len(lt.HttpHeaders)) + for i, r := range lt.HttpHeaders { + httpHeaderNew := map[string]interface{}{ + "name": r.Name, + "value": r.Value, + } + httpHeaderListNew[i] = httpHeaderNew + } + + targetLt := (*ltArr)[index].(map[string]interface{}) + targetLt["name"] = lt.Name + targetLt["error_penalty"] = lt.ErrorPenalty + targetLt["peer_certificate_verification"] = lt.PeerCertificateVerification + targetLt["test_interval"] = lt.TestInterval + targetLt["test_object"] = lt.TestObject + targetLt["request_string"] = lt.RequestString + targetLt["response_string"] = lt.ResponseString + targetLt["http_error3xx"] = lt.HttpError3xx + targetLt["http_error4xx"] = lt.HttpError4xx + targetLt["http_error5xx"] = lt.HttpError5xx + targetLt["disabled"] = lt.Disabled + targetLt["test_object_protocol"] = lt.TestObjectProtocol + targetLt["test_object_password"] = lt.TestObjectPassword + targetLt["test_object_port"] = lt.TestObjectPort + targetLt["ssl_client_private_key"] = lt.SslClientPrivateKey + targetLt["ssl_client_certificate"] = lt.SslClientCertificate + targetLt["disable_nonstandard_port_warning"] = lt.DisableNonstandardPortWarning + targetLt["test_object_username"] = lt.TestObjectUsername + targetLt["test_timeout"] = lt.TestTimeout + targetLt["timeout_penalty"] = lt.TimeoutPenalty + targetLt["answers_required"] = lt.AnswersRequired + targetLt["resource_type"] = lt.ResourceType + targetLt["recursion_requested"] = lt.RecursionRequested + targetLt["http_header"] = httpHeaderListNew +} + // create and populate Terraform liveness_test schema func populateTerraformLivenessTestState(d *schema.ResourceData, prop *gtm.Property, m interface{}) { meta := akamai.Meta(m) - logger := meta.Log("Akamai GTM", "populateTerraformLivenessTestState") + logger := meta.Log("Akamai GTM", "populateTerraformTrafficTargetState") - objectInventory := make(map[string]*gtm.LivenessTest, len(prop.LivenessTests)) - if len(prop.LivenessTests) > 0 { - for _, aObj := range prop.LivenessTests { - objectInventory[aObj.Name] = aObj - } - } ltStateList, _ := tools.GetInterfaceArrayValue("liveness_test", d) - for _, ltMap := range ltStateList { - lt := ltMap.(map[string]interface{}) - objIndex := lt["name"].(string) - ltObject := objectInventory[objIndex] - if ltObject == nil { - logger.Warnf("Property LivenessTest %s NOT FOUND in returned GTM Object", lt["name"]) - continue - } - lt["name"] = ltObject.Name - lt["error_penalty"] = ltObject.ErrorPenalty - lt["peer_certificate_verification"] = ltObject.PeerCertificateVerification - lt["test_interval"] = ltObject.TestInterval - lt["test_object"] = ltObject.TestObject - lt["request_string"] = ltObject.RequestString - lt["response_string"] = ltObject.ResponseString - lt["http_error3xx"] = ltObject.HttpError3xx - lt["http_error4xx"] = ltObject.HttpError4xx - lt["http_error5xx"] = ltObject.HttpError5xx - lt["disabled"] = ltObject.Disabled - lt["test_object_protocol"] = ltObject.TestObjectProtocol - lt["test_object_password"] = ltObject.TestObjectPassword - lt["test_object_port"] = ltObject.TestObjectPort - lt["ssl_client_private_key"] = ltObject.SslClientPrivateKey - lt["ssl_client_certificate"] = ltObject.SslClientCertificate - lt["disable_nonstandard_port_warning"] = ltObject.DisableNonstandardPortWarning - lt["test_object_username"] = ltObject.TestObjectUsername - lt["test_timeout"] = ltObject.TestTimeout - lt["timeout_penalty"] = ltObject.TimeoutPenalty - lt["answers_required"] = ltObject.AnswersRequired - lt["resource_type"] = ltObject.ResourceType - lt["recursion_requested"] = ltObject.RecursionRequested - httpHeaderListNew := make([]interface{}, len(ltObject.HttpHeaders)) - for i, r := range ltObject.HttpHeaders { - httpHeaderNew := map[string]interface{}{ - "name": r.Name, - "value": r.Value, - } - httpHeaderListNew[i] = httpHeaderNew - } - lt["http_header"] = httpHeaderListNew - // remove object - delete(objectInventory, objIndex) - } - if len(objectInventory) > 0 { - logger.Debugf("Property LivenessTest objects left...") - // Objects not in the state yet. Add. Unfortunately, they not align with instance indices in the config - for _, l := range objectInventory { - ltNew := map[string]interface{}{ - "name": l.Name, - "error_penalty": l.ErrorPenalty, - "peer_certificate_verification": l.PeerCertificateVerification, - "test_interval": l.TestInterval, - "test_object": l.TestObject, - "request_string": l.RequestString, - "response_string": l.ResponseString, - "http_error3xx": l.HttpError3xx, - "http_error4xx": l.HttpError4xx, - "http_error5xx": l.HttpError5xx, - "disabled": l.Disabled, - "test_object_protocol": l.TestObjectProtocol, - "test_object_password": l.TestObjectPassword, - "test_object_port": l.TestObjectPort, - "ssl_client_private_key": l.SslClientPrivateKey, - "ssl_client_certificate": l.SslClientCertificate, - "disable_nonstandard_port_warning": l.DisableNonstandardPortWarning, - "test_object_username": l.TestObjectUsername, - "test_timeout": l.TestTimeout, - "timeout_penalty": l.TimeoutPenalty, - "answers_required": l.AnswersRequired, - "resource_type": l.ResourceType, - "recursion_requested": l.RecursionRequested, + stateIdx := 0 + + for _, aObj := range prop.LivenessTests { + idx := slices.IndexFunc(ltStateList, func(lt interface{}) bool { + return lt.(map[string]interface{})["name"].(string) == aObj.Name + }) + + if idx == -1 { + if stateIdx == 0 { + logger.Debugf("liveness_test %s not found into the state, prepending it", aObj.Name) + setLivenessTestAtIndex(<StateList, aObj, 0, false) + } else { + logger.Debugf("liveness_test %s not found into the state, inserting it at position %s into the state", aObj.Name, stateIdx) + setLivenessTestAtIndex(<StateList, aObj, stateIdx, false) } - httpHeaderListNew := make([]interface{}, len(l.HttpHeaders)) - for i, r := range l.HttpHeaders { - httpHeaderNew := map[string]interface{}{ - "name": r.Name, - "value": r.Value, - } - httpHeaderListNew[i] = httpHeaderNew + } else { + if idx < stateIdx { + stateIdx-- + logger.Debugf("liveness_test %s will now be placed after the position it was in the past (moving it from %s to %s)", aObj.Name, idx, stateIdx) + ltStateList = append(ltStateList[:idx], ltStateList[idx+1:]...) + setLivenessTestAtIndex(<StateList, aObj, stateIdx, false) + } else { + logger.Debugf("liveness_test %s will be updated in-place into the state (index %s)", aObj.Name, idx) + setLivenessTestAtIndex(<StateList, aObj, idx, true) + stateIdx = idx } - ltNew["http_header"] = httpHeaderListNew - ltStateList = append(ltStateList, ltNew) } + stateIdx++ } _ = d.Set("liveness_test", ltStateList) - } func convertStringToInterfaceList(stringList []string, m interface{}) []interface{} { From 9ae85af8e3981e645f93c6bc05855e8396bef5a2 Mon Sep 17 00:00:00 2001 From: Tony Fouchard Date: Mon, 13 Mar 2023 20:53:24 +0100 Subject: [PATCH 2/2] Remove comment --- .../gtm/resource_akamai_gtm_property.go | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/pkg/providers/gtm/resource_akamai_gtm_property.go b/pkg/providers/gtm/resource_akamai_gtm_property.go index dc66a8ea2..0d2a6fd1e 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_property.go +++ b/pkg/providers/gtm/resource_akamai_gtm_property.go @@ -998,56 +998,6 @@ func populateTerraformTrafficTargetState(d *schema.ResourceData, prop *gtm.Prope stateIdx++ } _ = d.Set("traffic_target", ttStateList) - /* - meta := akamai.Meta(m) - logger := meta.Log("Akamai GTM", "populateTerraformTrafficTargetState") - - objectInventory := make(map[int]*gtm.TrafficTarget, len(prop.TrafficTargets)) - objectInventoryDcs := make([]int, len(prop.TrafficTargets)) - if len(prop.TrafficTargets) > 0 { - for i, aObj := range prop.TrafficTargets { - objectInventory[aObj.DatacenterId] = aObj - objectInventoryDcs[i] = aObj.DatacenterId - } - } - - ttStateList, _ := tools.GetInterfaceArrayValue("traffic_target", d) - for _, ttMap := range ttStateList { - tt := ttMap.(map[string]interface{}) - objIndex := tt["datacenter_id"].(int) - ttObject := objectInventory[objIndex] - if ttObject == nil { - logger.Warnf("Property TrafficTarget %d NOT FOUND in returned GTM Object", tt["datacenter_id"]) - continue - } - tt["datacenter_id"] = ttObject.DatacenterId - tt["name"] = ttObject.Name - tt["enabled"] = ttObject.Enabled - tt["weight"] = ttObject.Weight - tt["handout_cname"] = ttObject.HandoutCName - tt["servers"] = ttObject.Servers - // Get dc index in objectInventoryDcs slice and remove object - elementBaseIdx := slices.Index(objectInventoryDcs, ttObject.DatacenterId) - objectInventoryDcs = append(objectInventoryDcs[:elementBaseIdx], objectInventoryDcs[elementBaseIdx+1:]...) - } - if len(objectInventoryDcs) > 0 { - // Objects not in the state yet. Add. - for _, dcId := range objectInventoryDcs { - mttObj := objectInventory[dcId] - logger.Debugf("Property TrafficObject NEW State Object: %d", mttObj.DatacenterId) - ttNew := map[string]interface{}{ - "datacenter_id": mttObj.DatacenterId, - "enabled": mttObj.Enabled, - "weight": mttObj.Weight, - "name": mttObj.Name, - "handout_cname": mttObj.HandoutCName, - "servers": mttObj.Servers, - } - ttStateList = append(ttStateList, ttNew) - } - } - _ = d.Set("traffic_target", ttStateList) - */ } // Populate existing static_rr_sets object from resource data