-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore whitespace when comparing ssh keys
- Loading branch information
1 parent
6800d2c
commit dc91c36
Showing
5 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package validators | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"strings" | ||
) | ||
|
||
type DiffSuppressFunc[T any] struct { | ||
isEqual func(T, T) bool | ||
} | ||
|
||
var IgnoringWhitespace = NewDiffSuppressFunc(func(val1 string, val2 string) bool { | ||
return strings.TrimSpace(val1) == strings.TrimSpace(val2) | ||
}) | ||
|
||
func NewDiffSuppressFunc[T any](isEqual func(T, T) bool) DiffSuppressFunc[T] { | ||
return DiffSuppressFunc[T]{isEqual: isEqual} | ||
} | ||
|
||
func (m DiffSuppressFunc[T]) Description(_ context.Context) string { | ||
return fmt.Sprintf("Sets value to always be null, as resource status should be empty when no drift is detected.") | ||
} | ||
|
||
func (m DiffSuppressFunc[T]) MarkdownDescription(_ context.Context) string { | ||
return fmt.Sprintf("Sets value to always be null, as resource status should be empty when no drift is detected.") | ||
} | ||
|
||
func (m DiffSuppressFunc[T]) Modify(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) { | ||
if req.AttributeConfig == nil || req.AttributeConfig.IsNull() || req.AttributeConfig.IsUnknown() { | ||
return | ||
} | ||
if req.AttributeState == nil || req.AttributeState.IsNull() || req.AttributeState.IsUnknown() { | ||
return | ||
} | ||
|
||
if req.AttributeConfig.Equal(req.AttributeState) { | ||
return | ||
} | ||
|
||
stateVal, err := req.AttributeState.ToTerraformValue(ctx) | ||
if err != nil { | ||
tflog.Error(ctx, fmt.Sprintf("DiffSupressFunc: Unable to convert state value to tf value, %s", err)) | ||
return | ||
} | ||
|
||
configVal, err := req.AttributeConfig.ToTerraformValue(ctx) | ||
if err != nil { | ||
tflog.Error(ctx, fmt.Sprintf("DiffSupressFunc: Unable to convert config value to tf value, %s", err)) | ||
return | ||
} | ||
|
||
var c, s T | ||
|
||
err = stateVal.As(&s) | ||
if err != nil { | ||
tflog.Error(ctx, fmt.Sprintf("DiffSupressFunc: Unable to convert state value, %s", err)) | ||
return | ||
} | ||
|
||
err = configVal.As(&c) | ||
if err != nil { | ||
tflog.Error(ctx, fmt.Sprintf("DiffSupressFunc: Unable to convert config value, %s", err)) | ||
return | ||
} | ||
|
||
if m.isEqual(c, s) { | ||
tflog.Info(ctx, fmt.Sprintf("DiffSupressFunc: Diff has been suprressed.")) | ||
resp.AttributePlan = req.AttributeState | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,6 @@ resource multy_virtual_machine vm { | |
cloud = var.cloud | ||
location = var.location | ||
network_security_group_ids = [multy_network_security_group.nsg.id] | ||
public_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQJRMv5ix5QPfs3+t6mLcXvtBuMdxHc5aitbWE4myzVf33UttLI4td1Q2WZ+kfn5SwiF7b9YowqWlM0kiIFGoJhcBwN0Mq4TOcGmn5Hidl94Rf8xzk88+W0LJEd+JEKY4czZNNgdWhhsxuZgt9P4NdzONqFC2XL5AggLau7SdDVV9JCHHI+dw1C0FLq1Y/5Ga7rJN2Zm7vmT4I/tCPEheEDYN2MH2ClKgQf4Ni2KoiHLxvrbBmcXOuknn+/yjN+dpiAncQFnMjykV5lKMnXFm6u43KlMLpr/XKKmdaLDZWBVaNRdPeqt2FiWisGFowAuUsXWUhSBcwXArZbWRbc0rp+ASh9is2fC9BvkOcCdMZTqJmoXFib23KaSKi1wZhGOPB93YJvZ/Gnr6n0GHWryqPJ6QvijmN20zYJq1j4ZUrNsxLgIMkGNMtCId+pbJ1amn1DM7X2fT99k+rcycTIuI83OEASs49hJfty0AM1ChSxvkm0ZAZQcFsdUnuAAyhXgU= [email protected]" | ||
public_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQJRMv5ix5QPfs3+t6mLcXvtBuMdxHc5aitbWE4myzVf33UttLI4td1Q2WZ+kfn5SwiF7b9YowqWlM0kiIFGoJhcBwN0Mq4TOcGmn5Hidl94Rf8xzk88+W0LJEd+JEKY4czZNNgdWhhsxuZgt9P4NdzONqFC2XL5AggLau7SdDVV9JCHHI+dw1C0FLq1Y/5Ga7rJN2Zm7vmT4I/tCPEheEDYN2MH2ClKgQf4Ni2KoiHLxvrbBmcXOuknn+/yjN+dpiAncQFnMjykV5lKMnXFm6u43KlMLpr/XKKmdaLDZWBVaNRdPeqt2FiWisGFowAuUsXWUhSBcwXArZbWRbc0rp+ASh9is2fC9BvkOcCdMZTqJmoXFib23KaSKi1wZhGOPB93YJvZ/Gnr6n0GHWryqPJ6QvijmN20zYJq1j4ZUrNsxLgIMkGNMtCId+pbJ1amn1DM7X2fT99k+rcycTIuI83OEASs49hJfty0AM1ChSxvkm0ZAZQcFsdUnuAAyhXgU= [email protected]\n" | ||
depends_on = [multy_route_table_association.rta1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters