Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .changelog/44506.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_instance: Don't store invalid string in user_data attribute
```
8 changes: 7 additions & 1 deletion internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -3382,7 +3383,12 @@ func resourceInstanceFlatten(ctx context.Context, client *conns.AWSClient, insta
if err != nil {
return sdkdiag.AppendErrorf(diags, "decoding user_data: %s", err)
}
rd.Set("user_data", string(data))
if utf8.Valid(data) {
rd.Set("user_data", string(data))
} else {
// The user_data wasn't valid UTF-8, so we need to store it as base64 instead of as the raw string.
rd.Set("user_data_base64", attr.UserData.Value)
}
}
}
}
Expand Down
Loading