Skip to content

Commit

Permalink
build(deps): bump the main group in /tools with 2 updates (#1892)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Murad Biashimov <murad.biashimov@aiven.io>
  • Loading branch information
dependabot[bot] and byashimov authored Nov 18, 2024
1 parent b6ac233 commit 179a133
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 176 deletions.
4 changes: 2 additions & 2 deletions internal/schemautil/custom_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func CustomizeDiffGenericService(serviceType string) schema.CustomizeDiffFunc {
)
}

func ShouldNotBeEmpty(_ context.Context, _, new, _ interface{}) bool {
switch t := new.(type) {
func ShouldNotBeEmpty(_ context.Context, _, newValue, _ interface{}) bool {
switch t := newValue.(type) {
case string:
return t != ""
case []interface{}:
Expand Down
28 changes: 14 additions & 14 deletions internal/schemautil/schemautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ func CreateOnlyDiffSuppressFunc(_, _, _ string, d *schema.ResourceData) bool {

// EmptyObjectDiffSuppressFunc suppresses a diff for service user configuration options when
// fields are not set by the user but have default or previously defined values.
func EmptyObjectDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
func EmptyObjectDiffSuppressFunc(k, oldValue, newValue string, d *schema.ResourceData) bool {
// When a map inside a list contains only default values without explicit values set by
// the user Terraform interprets the map as not being present and the array length being
// zero, resulting in bogus update that does nothing. Allow ignoring those.
if old == "1" && new == "0" && strings.HasSuffix(k, ".#") {
if oldValue == "1" && newValue == "0" && strings.HasSuffix(k, ".#") {
return true
}

// Ignore the field when it is not set to any value, but had a non-empty parameter before. This also accounts
// for the case when the field is not set to any value, but has a default value returned by the API.
if !d.HasChange(k) && (new == "" && old != "" || new == "0" && old != "0" || new == "false" && old == "true") {
if !d.HasChange(k) && (newValue == "" && oldValue != "" || newValue == "0" && oldValue != "0" || newValue == "false" && oldValue == "true") {
return true
}

// There is a bug in Terraform 0.11 which interprets "true" as "0" and "false" as "1"
if (new == "0" && old == "false") || (new == "1" && old == "true") {
if (newValue == "0" && oldValue == "false") || (newValue == "1" && oldValue == "true") {
return true
}

Expand All @@ -131,25 +131,25 @@ func EmptyObjectDiffSuppressFuncSkipArrays(s map[string]*schema.Schema) schema.S
}
}

return func(k, old, new string, d *schema.ResourceData) bool {
return func(k, oldValue, newValue string, d *schema.ResourceData) bool {
for _, key := range skipKeys {
if strings.Contains(k, fmt.Sprintf(".%s.", key)) {
return false
}
}

return EmptyObjectDiffSuppressFunc(k, old, new, d)
return EmptyObjectDiffSuppressFunc(k, oldValue, newValue, d)
}
}

// EmptyObjectNoChangeDiffSuppressFunc it suppresses a diff if a field is empty but have not
// been set before to any value
func EmptyObjectNoChangeDiffSuppressFunc(k, _, new string, d *schema.ResourceData) bool {
func EmptyObjectNoChangeDiffSuppressFunc(k, _, newValue string, d *schema.ResourceData) bool {
if d.HasChange(k) {
return false
}

if new == "" {
if newValue == "" {
return true
}

Expand All @@ -160,10 +160,10 @@ func EmptyObjectNoChangeDiffSuppressFunc(k, _, new string, d *schema.ResourceDat
// the IP filter user config value has default. We don't want to force users to always
// define explicit value just because of the Terraform restriction so suppress the
// change from default to empty (which would be nonsensical operation anyway)
func IPFilterArrayDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
func IPFilterArrayDiffSuppressFunc(k, oldValue, newValue string, d *schema.ResourceData) bool {
// TODO: Add support for ip_filter_object.

if old == "1" && new == "0" && strings.HasSuffix(k, ".ip_filter.#") {
if oldValue == "1" && newValue == "0" && strings.HasSuffix(k, ".ip_filter.#") {
if list, ok := d.Get(strings.TrimSuffix(k, ".#")).([]interface{}); ok {
if len(list) == 1 {
return list[0] == "0.0.0.0/0"
Expand All @@ -174,14 +174,14 @@ func IPFilterArrayDiffSuppressFunc(k, old, new string, d *schema.ResourceData) b
return false
}

func IPFilterValueDiffSuppressFunc(k, old, new string, _ *schema.ResourceData) bool {
func IPFilterValueDiffSuppressFunc(k, oldValue, newValue string, _ *schema.ResourceData) bool {
// TODO: Add support for ip_filter_object.

return old == "0.0.0.0/0" && new == "" && strings.HasSuffix(k, ".ip_filter.0")
return oldValue == "0.0.0.0/0" && newValue == "" && strings.HasSuffix(k, ".ip_filter.0")
}

func TrimSpaceDiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
return strings.TrimSpace(old) == strings.TrimSpace(new)
func TrimSpaceDiffSuppressFunc(_, oldValue, newValue string, _ *schema.ResourceData) bool {
return strings.TrimSpace(oldValue) == strings.TrimSpace(newValue)
}

// ValidateHumanByteSizeString is a ValidateFunc that ensures a string parses
Expand Down
12 changes: 6 additions & 6 deletions internal/schemautil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func ServiceCommonSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
Description: "Defines where the cloud provider and region where the service is hosted in. This can be changed freely after service is created. Changing the value will trigger a potentially lengthy migration process for the service. Format is cloud provider name (`aws`, `azure`, `do` `google`, `upcloud`, etc.), dash, and the cloud provider specific region name. These are documented on each Cloud provider's own support articles, like [here for Google](https://cloud.google.com/compute/docs/regions-zones/) and [here for AWS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html).",
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
// This is a workaround for a bug when migrating from V3 to V4 Aiven Provider.
// The bug is that the cloud_name is not set in the state file, but it is set
// on the API side. This causes a diff during plan, and it will not disappear
// even after consequent applies. This is because the state is not updated
// with the cloud_name value.
return new == ""
return newValue == ""
},
},
"plan": {
Expand Down Expand Up @@ -114,8 +114,8 @@ func ServiceCommonSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
Description: "Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.",
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
return new == ""
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
return newValue == ""
},
// There is also `never` value, which can't be set, but can be received from the backend.
// Sending `never` is suppressed in GetMaintenanceWindow function,
Expand All @@ -126,8 +126,8 @@ func ServiceCommonSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
Description: "Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.",
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
return new == ""
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
return newValue == ""
},
},
"termination_protection": {
Expand Down
16 changes: 8 additions & 8 deletions internal/sdkprovider/service/kafkaschema/kafka_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,33 @@ var aivenKafkaSchemaSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkaschemaregistry.CompatibilityTypeChoices(), false),
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
// When a compatibility level is not set to any value and consequently is null (empty string).
// Allow ignoring those.
return new == ""
return newValue == ""
},
Description: userconfig.Desc("Kafka Schemas compatibility level.").PossibleValuesString(kafkaschemaregistry.CompatibilityTypeChoices()...).Build(),
},
}

// diffSuppressJSONObject checks logical equivalences in JSON Kafka Schema values
func diffSuppressJSONObject(_, old, new string, _ *schema.ResourceData) bool {
func diffSuppressJSONObject(_, oldValue, newValue string, _ *schema.ResourceData) bool {
var objOld, objNew interface{}

if err := json.Unmarshal([]byte(old), &objOld); err != nil {
if err := json.Unmarshal([]byte(oldValue), &objOld); err != nil {
return false
}
if err := json.Unmarshal([]byte(new), &objNew); err != nil {
if err := json.Unmarshal([]byte(newValue), &objNew); err != nil {
return false
}

return reflect.DeepEqual(objNew, objOld)
}

// diffSuppressJSONObjectOrProtobufString checks logical equivalences in JSON or Protobuf Kafka Schema values.
func diffSuppressJSONObjectOrProtobufString(k, old, new string, d *schema.ResourceData) bool {
if !diffSuppressJSONObject(k, old, new, d) {
return normalizeProtobufString(old) == normalizeProtobufString(new)
func diffSuppressJSONObjectOrProtobufString(k, oldValue, newValue string, d *schema.ResourceData) bool {
if !diffSuppressJSONObject(k, oldValue, newValue, d) {
return normalizeProtobufString(oldValue) == normalizeProtobufString(newValue)
}

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ var aivenKafkaSchemaConfigurationSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkaschemaregistry.CompatibilityTypeChoices(), false),
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
// When a compatibility level is not set to any value and consequently is null (empty string).
// Allow ignoring those.
return new == ""
return newValue == ""
},
Description: userconfig.Desc("Kafka Schemas compatibility level.").PossibleValuesString(kafkaschemaregistry.CompatibilityTypeChoices()...).Build(),
},
Expand Down
4 changes: 2 additions & 2 deletions internal/sdkprovider/service/pg/pg_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
const defaultLC = "en_US.UTF-8"

// handleLcDefaults checks if the lc values have actually changed
func handleLcDefaults(_, old, new string, _ *schema.ResourceData) bool {
func handleLcDefaults(_, oldValue, newValue string, _ *schema.ResourceData) bool {
// NOTE! not all database resources return lc_* values even if
// they are set when the database is created; best we can do is
// to assume it was created using the default value.
return new == "" || (old == "" && new == defaultLC) || old == new
return newValue == "" || (oldValue == "" && newValue == defaultLC) || oldValue == newValue
}

var aivenPGDatabaseSchema = map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var aivenAWSVPCPeeringConnectionSchema = map[string]*schema.Schema{
ForceNew: true,
Required: true,
Type: schema.TypeString,
DiffSuppressFunc: func(_, _, new string, _ *schema.ResourceData) bool {
return new == ""
DiffSuppressFunc: func(_, _, newValue string, _ *schema.ResourceData) bool {
return newValue == ""
},
Description: userconfig.Desc("The AWS region of the peered VPC, if different from the Aiven VPC region.").ForceNew().Build(),
},
Expand Down
18 changes: 9 additions & 9 deletions internal/sdkprovider/userconfig/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ var (

// SuppressUnchanged suppresses diff for unchanged fields.
// Applied for all nested values: both for objects and arrays.
func SuppressUnchanged(k, old, new string, d *schema.ResourceData) bool {
func SuppressUnchanged(k, oldValue, newValue string, d *schema.ResourceData) bool {
// schema.TypeMap
if strings.HasSuffix(k, ".%") {
return old == new
return oldValue == newValue
}

// Lists, sets and objects (object is list with one item).
Expand All @@ -44,7 +44,7 @@ func SuppressUnchanged(k, old, new string, d *schema.ResourceData) bool {
// SuppressUnchanged is applied to each nested field.
// Ip filter items handled with a special suppressor.
if reIsIPFilterStrings.MatchString(k) {
return suppressIPFilterSet(k, old, new, d)
return suppressIPFilterSet(k, oldValue, newValue, d)
}

// Doesn't suppress "set" items.
Expand All @@ -53,13 +53,13 @@ func SuppressUnchanged(k, old, new string, d *schema.ResourceData) bool {
}

// Object properties.
// "old" — is something read from API
// "new" — is what is read from tf file
// If value is "computed" (received as default) it has non-empty old (any value) and empty "new" (zero value).
// "oldValue" — is something read from API
// "newValue" — is what is read from tf file
// If value is "computed" (received as default) it has non-empty oldValue (any value) and empty "newValue" (zero value).
// For instance, when you create kafka it gets "kafka_version = 3.5",
// while it's not in your tf file, terraform shows a diff.
// This switch suppresses that, as well, as other "default" values.
switch new {
switch newValue {
case "", "0", "false":
// "" — kafka_version = "3.5" -> ""
// 0 — backup_hour = "4" -> 0
Expand All @@ -70,13 +70,13 @@ func SuppressUnchanged(k, old, new string, d *schema.ResourceData) bool {
}

// suppressIPFilterSet ip_filter list has specific logic, like default list value
func suppressIPFilterSet(k, old, new string, d *schema.ResourceData) bool {
func suppressIPFilterSet(k, oldValue, newValue string, d *schema.ResourceData) bool {
// Suppresses ip_filter = [0.0.0.0/0]
path := strings.Split(k, ".")
// Turns ~ip_filter.1234 to ~ip_filter.#
v, ok := d.GetOk(strings.Join(path[:len(path)-1], ".") + ".#")
// Literally, if the value is "0.0.0.0/0" and the parent's length is "1"
return old == "0.0.0.0/0" && new == "" && ok && v.(int) == 1
return oldValue == "0.0.0.0/0" && newValue == "" && ok && v.(int) == 1
}

// isObjectSet returns true if given k is for collection of objects
Expand Down
Loading

0 comments on commit 179a133

Please sign in to comment.