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

Fix tcp echo regex validation #26

Merged
merged 1 commit into from
Jun 13, 2024
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
17 changes: 6 additions & 11 deletions pkg/provider/resource_tcp_echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ func (r *TCPEchoResource) TCPEcho(ctx context.Context, data *TCPEchoResourceMode
ConsecutiveSuccesses: int(data.ConsecutiveSuccesses.ValueInt64()),
}

firstAttemptRegexValue := ""
regexValueStoredAttempt := 0
previousRegexValue := ""
var persistentResponseRegex *regexp.Regexp
var err error
if data.PersistentResponseRegex.ValueString() != "" {
Expand Down Expand Up @@ -273,15 +272,11 @@ func (r *TCPEchoResource) TCPEcho(ctx context.Context, data *TCPEchoResourceMode
// result := persistentResponseRegex.FindString(string(reply))
tflog.Info(ctx, fmt.Sprintf("Result: %s", result))

// Avoid comparison on first attempt
if regexValueStoredAttempt == 0 {
firstAttemptRegexValue = result
regexValueStoredAttempt = attempt
return true
}
if firstAttemptRegexValue != result {
tflog.Warn(ctx, fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, firstAttemptRegexValue))
diag.AddWarning("Check failed", fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, firstAttemptRegexValue))
if previousRegexValue != result {
tflog.Warn(ctx, fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, previousRegexValue))
diag.AddWarning("Check failed", fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, previousRegexValue))

previousRegexValue = result
return false
}
}
Expand Down
Loading