SHA256 encode compute_certificate's private keys (#2976)

Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
The Magician 2019-02-01 11:02:20 -08:00 committed by Paddy
parent 856a977ddc
commit 69e445bd59
2 changed files with 13 additions and 4 deletions

View File

@ -49,10 +49,11 @@ func resourceComputeSslCertificate() *schema.Resource {
Sensitive: true, Sensitive: true,
}, },
"private_key": { "private_key": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
Sensitive: true, DiffSuppressFunc: sha256DiffSuppress,
Sensitive: true,
}, },
"description": { "description": {
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -3,6 +3,8 @@
package google package google
import ( import (
"crypto/sha256"
"encoding/hex"
"fmt" "fmt"
"log" "log"
"strings" "strings"
@ -179,6 +181,12 @@ func ipCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
return false return false
} }
// sha256DiffSuppress
// if old is the hex-encoded sha256 sum of new, treat them as equal
func sha256DiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
return hex.EncodeToString(sha256.New().Sum([]byte(old))) == new
}
func caseDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { func caseDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
return strings.ToUpper(old) == strings.ToUpper(new) return strings.ToUpper(old) == strings.ToUpper(new)
} }