Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_encoder to target proxy compute resources #17733

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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