Skip to content

Commit 7ab5706

Browse files
committed
store non-hashedvalue in diffsuppress if it match with stored hash
1 parent 1e5d6ea commit 7ab5706

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/services/container/namespace.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package container
22

33
import (
44
"context"
5+
"strings"
56

67
"github.com/alexedwards/argon2id"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -76,7 +77,25 @@ func ResourceNamespace() *schema.Resource {
7677
},
7778
ValidateDiagFunc: validation.MapKeyLenBetween(0, 100),
7879
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
79-
match, _ := argon2id.ComparePasswordAndHash(oldValue, newValue)
80+
secretKey := strings.TrimPrefix(k, "secret_environment_variables.")
81+
if secretKey == "" || secretKey == "%" {
82+
return false
83+
}
84+
85+
match, _ := argon2id.ComparePasswordAndHash(newValue, oldValue)
86+
87+
// If values match, we can store the correct value in state
88+
// This has impact when we import a namespace with secrets, check container_test.TestAccNamespace_ImportWithSecrets
89+
if match {
90+
secrets := expandContainerSecrets(d.Get("secret_environment_variables"))
91+
for _, secret := range secrets {
92+
if secret.Key == secretKey {
93+
secret.Value = scw.StringPtr(newValue)
94+
}
95+
}
96+
_ = d.Set("secret_environment_variables", flattenContainerSecretEnvironmentVariables(secrets))
97+
}
98+
8099
return match
81100
},
82101
},

0 commit comments

Comments
 (0)