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,
},
"private_key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: sha256DiffSuppress,
Sensitive: true,
},
"description": {
Type: schema.TypeString,

View File

@ -3,6 +3,8 @@
package google
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"log"
"strings"
@ -179,6 +181,12 @@ func ipCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
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 {
return strings.ToUpper(old) == strings.ToUpper(new)
}