From ae5903a10332ef11b493ed4c6439bfbb1dd4645b Mon Sep 17 00:00:00 2001 From: = Date: Mon, 27 Mar 2017 11:25:43 -0600 Subject: [PATCH] Fixes TestAccAWSOpsworksInstance --- .../aws/resource_aws_opsworks_instance.go | 5 ++++- builtin/providers/aws/structure.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_opsworks_instance.go b/builtin/providers/aws/resource_aws_opsworks_instance.go index 0e42e30f07..2b2b51c492 100644 --- a/builtin/providers/aws/resource_aws_opsworks_instance.go +++ b/builtin/providers/aws/resource_aws_opsworks_instance.go @@ -565,6 +565,10 @@ func resourceAwsOpsworksInstanceRead(d *schema.ResourceData, meta interface{}) e for _, v := range instance.LayerIds { layerIds = append(layerIds, *v) } + layerIds, err = sortListBasedonTFFile(layerIds, d, "layer_ids") + if err != nil { + return fmt.Errorf("[DEBUG] Error sorting layer_ids attribute: %#v", err) + } if err := d.Set("layer_ids", layerIds); err != nil { return fmt.Errorf("[DEBUG] Error setting layer_ids attribute: %#v, error: %#v", layerIds, err) } @@ -820,7 +824,6 @@ func resourceAwsOpsworksInstanceUpdate(d *schema.ResourceData, meta interface{}) if v, ok := d.GetOk("layer_ids"); ok { req.LayerIds = expandStringList(v.([]interface{})) - } if v, ok := d.GetOk("os"); ok { diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 302571c6c4..dfe053b9a5 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -1490,6 +1490,22 @@ func sortInterfaceSlice(in []interface{}) []interface{} { return b } +// This function sorts List A to look like a list found in the tf file. +func sortListBasedonTFFile(in []string, d *schema.ResourceData, listName string) ([]string, error) { + if attributeCount, ok := d.Get(listName + ".#").(int); ok { + for i := 0; i < attributeCount; i++ { + currAttributeId := d.Get(listName + "." + strconv.Itoa(i)) + for j := 0; j < len(in); j++ { + if currAttributeId == in[j] { + in[i], in[j] = in[j], in[i] + } + } + } + return in, nil + } + return in, fmt.Errorf("Could not find list: %s", listName) +} + func flattenApiGatewayThrottleSettings(settings *apigateway.ThrottleSettings) []map[string]interface{} { result := make([]map[string]interface{}, 0, 1)