hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.25k stars 1.7k forks source link

Functionality to provide hexadecimal hash of the object inside google cloud bucket #3888

Open sourabhxyz opened 5 years ago

sourabhxyz commented 5 years ago

Community Note

Description

Google cloud has a facility to give md5 hash in hexadecimal format as well by using -h flag in gsutil, see here. But this provider only provides the md5 hash (see here)which is obtained by converting this hexadecimal hash to binary and then doing base 64 encoding to it which is unusual. It would be helpful if this provider could simply leverage this built in feature provided by GCP.

New or Affected Resource(s)

Potential Terraform Configuration

output "uploaded_gcp_md5_hash_matched" {
  value = "${google_storage_bucket_object.gcp_controller_dir.md5hexhash == var.gcp_controller_md5 ? "Yes" : "No, please re-run the script as md5 hash didn't match"}"
}
mitj04 commented 1 year ago

b/262698141

mitj04 commented 1 year ago
// decode first
p, err := base64.StdEncoding.DecodeString(response["md5Hash"])
if err != nil {
    // handle error
}
// encode
hmd5HexHash:= hex.EncodeToString(p)
fmt.Println(md5HexHash) // prints md5HexHash
rileykarson commented 1 year ago

Note: If there's a builtin Terraform function we should close this based on that rather than implement it directly in the resource.