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_autoscaling_group: Prevent unexpected differences in tags for Terraform 0.11 and earlier with boolean propagate_at_launch values #13912

Merged
merged 1 commit into from
Jul 1, 2020
Merged
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
38 changes: 38 additions & 0 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package aws

import (
"bytes"
"fmt"
"log"
"regexp"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -397,6 +400,41 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
ConflictsWith: []string{"tag"},
// Terraform 0.11 and earlier can provide incorrect type
// information during difference handling, in which boolean
// values are represented as "0" and "1". This Set function
// normalizes these hashing variations, while the Terraform
// Plugin SDK automatically suppresses the boolean/string
// difference in the value itself.
Set: func(v interface{}) int {
var buf bytes.Buffer

m, ok := v.(map[string]interface{})

if !ok {
return 0
}

if v, ok := m["key"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}

if v, ok := m["value"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}

if v, ok := m["propagate_at_launch"].(bool); ok {
buf.WriteString(fmt.Sprintf("%t-", v))
} else if v, ok := m["propagate_at_launch"].(string); ok {
if b, err := strconv.ParseBool(v); err == nil {
buf.WriteString(fmt.Sprintf("%t-", b))
} else {
buf.WriteString(fmt.Sprintf("%s-", v))
}
}

return hashcode.String(buf.String())
},
},

"service_linked_role_arn": {
Expand Down