Skip to content

Commit

Permalink
Add update_encoder to target proxy compute resources (#10261) (#17733)
Browse files Browse the repository at this point in the history
[upstream:6512a3d1c9e6e85e222e072af9d850772fa709d9]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 30, 2024
1 parent d87620a commit 287c9e3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/10261.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: Added explicit update_encoder to `ComputeTargetHttpsProxy` and `ComputeRegionTargetHttpsProxy` resources.
```
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ func resourceComputeRegionTargetHttpsProxyUpdate(d *schema.ResourceData, meta in
obj["sslCertificates"] = sslCertificatesProp
}

obj, err = resourceComputeRegionTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/targetHttpsProxies/{{name}}/setSslCertificates")
if err != nil {
return err
Expand Down Expand Up @@ -418,6 +423,11 @@ func resourceComputeRegionTargetHttpsProxyUpdate(d *schema.ResourceData, meta in
obj["urlMap"] = urlMapProp
}

obj, err = resourceComputeRegionTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/targetHttpsProxies/{{name}}/setUrlMap")
if err != nil {
return err
Expand Down Expand Up @@ -677,6 +687,19 @@ func resourceComputeRegionTargetHttpsProxyEncoder(d *schema.ResourceData, meta i
return obj, nil
}

func resourceComputeRegionTargetHttpsProxyUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {

if _, ok := obj["certificateManagerCertificates"]; ok {
// The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates`
// The API does not allow using both certificate manager certificates and sslCertificates. If that changes
// in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive.
log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request")
obj["sslCertificates"] = obj["certificateManagerCertificates"]
delete(obj, "certificateManagerCertificates")
}
return obj, nil
}

func resourceComputeRegionTargetHttpsProxyDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Since both sslCertificates and certificateManagerCertificates maps to the same API field (sslCertificates), we need to check the types
// of certificates that exist in the array and decide whether to change the field to certificateManagerCertificate or not.
Expand Down
38 changes: 38 additions & 0 deletions google/services/compute/resource_compute_target_https_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
obj["quicOverride"] = quicOverrideProp
}

obj, err = resourceComputeTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies/{{name}}/setQuicOverride")
if err != nil {
return err
Expand Down Expand Up @@ -496,6 +501,11 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
obj["sslCertificates"] = sslCertificatesProp
}

obj, err = resourceComputeTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates")
if err != nil {
return err
Expand Down Expand Up @@ -538,6 +548,11 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
obj["certificateMap"] = certificateMapProp
}

obj, err = resourceComputeTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies/{{name}}/setCertificateMap")
if err != nil {
return err
Expand Down Expand Up @@ -580,6 +595,11 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
obj["sslPolicy"] = sslPolicyProp
}

obj, err = resourceComputeTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies/{{name}}/setSslPolicy")
if err != nil {
return err
Expand Down Expand Up @@ -622,6 +642,11 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
obj["urlMap"] = urlMapProp
}

obj, err = resourceComputeTargetHttpsProxyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/targetHttpsProxies/{{name}}/setUrlMap")
if err != nil {
return err
Expand Down Expand Up @@ -925,6 +950,19 @@ func resourceComputeTargetHttpsProxyEncoder(d *schema.ResourceData, meta interfa
return obj, nil
}

func resourceComputeTargetHttpsProxyUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {

if _, ok := obj["certificateManagerCertificates"]; ok {
// The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates`
// The API does not allow using both certificate manager certificates and sslCertificates. If that changes
// in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive.
log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request")
obj["sslCertificates"] = obj["certificateManagerCertificates"]
delete(obj, "certificateManagerCertificates")
}
return obj, nil
}

func resourceComputeTargetHttpsProxyDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Since both sslCertificates and certificateManagerCertificates maps to the same API field (sslCertificates), we need to check the types
// of certificates that exist in the array and decide whether to change the field to certificateManagerCertificate or not.
Expand Down

0 comments on commit 287c9e3

Please sign in to comment.