Skip to content

Commit 6d937be

Browse files
Add ceritificateManagerCertificates field to ComputeRegionTargetHttpsProxy resource (#10011) (#1983)
[upstream:1470d00e90e813f69d09aa9f55589884cbc27900] Signed-off-by: Modular Magician <[email protected]>
1 parent 06871a3 commit 6d937be

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/hcl/v2 v2.19.1
1212
github.com/hashicorp/terraform-json v0.18.0
1313
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
14-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240222220205-1f0cbd610fb4
14+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240223163750-a096da5673fd
1515
github.com/mitchellh/go-homedir v1.1.0 // indirect
1616
github.com/pkg/errors v0.9.1
1717
github.com/stretchr/testify v1.8.4

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwU
175175
github.com/hashicorp/terraform-plugin-mux v0.13.0 h1:79U401/3nd8CWwDGtTHc8F3miSCAS9XGtVarxSTDgwA=
176176
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 h1:Bl3e2ei2j/Z3Hc2HIS15Gal2KMKyLAZ2om1HCEvK6es=
177177
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE=
178-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240222220205-1f0cbd610fb4 h1:gszRru5nNQhRTGvviBmmgPSx7kvPAW6Bl12rBB1M+no=
179-
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240222220205-1f0cbd610fb4/go.mod h1:iQJGQHx40qba9wE8pOGbItSL5G+XRunVeL6RFRJTNcE=
178+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240223163750-a096da5673fd h1:jsRKC8HevknbrVWuq7fi2Wdp2b1768xe4/fEib1niHA=
179+
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240223163750-a096da5673fd/go.mod h1:iQJGQHx40qba9wE8pOGbItSL5G+XRunVeL6RFRJTNcE=
180180
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
181181
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
182182
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=

tfplan2cai/converters/google/resources/services/compute/compute_region_target_https_proxy.go

+47
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ package compute
1616

1717
import (
1818
"fmt"
19+
"log"
1920
"reflect"
21+
"regexp"
22+
"strings"
2023

2124
"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
2225
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
@@ -67,6 +70,12 @@ func GetComputeRegionTargetHttpsProxyApiObject(d tpgresource.TerraformResourceDa
6770
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
6871
obj["name"] = nameProp
6972
}
73+
certificateManagerCertificatesProp, err := expandComputeRegionTargetHttpsProxyCertificateManagerCertificates(d.Get("certificate_manager_certificates"), d, config)
74+
if err != nil {
75+
return nil, err
76+
} else if v, ok := d.GetOkExists("certificate_manager_certificates"); !tpgresource.IsEmptyValue(reflect.ValueOf(certificateManagerCertificatesProp)) && (ok || !reflect.DeepEqual(v, certificateManagerCertificatesProp)) {
77+
obj["certificateManagerCertificates"] = certificateManagerCertificatesProp
78+
}
7079
sslCertificatesProp, err := expandComputeRegionTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
7180
if err != nil {
7281
return nil, err
@@ -92,6 +101,19 @@ func GetComputeRegionTargetHttpsProxyApiObject(d tpgresource.TerraformResourceDa
92101
obj["region"] = regionProp
93102
}
94103

104+
return resourceComputeRegionTargetHttpsProxyEncoder(d, config, obj)
105+
}
106+
107+
func resourceComputeRegionTargetHttpsProxyEncoder(d tpgresource.TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
108+
109+
if _, ok := obj["certificateManagerCertificates"]; ok {
110+
// The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates`
111+
// The API does not allow using both certificate manager certificates and sslCertificates. If that changes
112+
// in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive.
113+
log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request")
114+
obj["sslCertificates"] = obj["certificateManagerCertificates"]
115+
delete(obj, "certificateManagerCertificates")
116+
}
95117
return obj, nil
96118
}
97119

@@ -103,6 +125,31 @@ func expandComputeRegionTargetHttpsProxyName(v interface{}, d tpgresource.Terraf
103125
return v, nil
104126
}
105127

128+
func expandComputeRegionTargetHttpsProxyCertificateManagerCertificates(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
129+
if v == nil {
130+
return nil, nil
131+
}
132+
l := v.([]interface{})
133+
req := make([]interface{}, 0, len(l))
134+
for _, raw := range l {
135+
if raw == nil {
136+
return nil, fmt.Errorf("Invalid value for certificate_manager_certificates: nil")
137+
}
138+
if strings.HasPrefix(raw.(string), "//") || strings.HasPrefix(raw.(string), "https://") {
139+
// Any full URL will be passed to the API request (regardless of the resource type). This is to allow self_links of CertificateManagerCeritificate resources.
140+
// If the full URL is an invalid reference, that should be handled by the API.
141+
req = append(req, raw.(string))
142+
} else if reg, _ := regexp.Compile("projects/(.*)/locations/(.*)/certificates/(.*)"); reg.MatchString(raw.(string)) {
143+
// If the input is the id pattern of CertificateManagerCertificate resource, a prefix will be added to construct the full URL before constructing the API request.
144+
self_link := "https://certificatemanager.googleapis.com/v1/" + raw.(string)
145+
req = append(req, self_link)
146+
} else {
147+
return nil, fmt.Errorf("Invalid value for certificate_manager_certificates: %v is an invalid format for a certificateManagerCertificate resource", raw.(string))
148+
}
149+
}
150+
return req, nil
151+
}
152+
106153
func expandComputeRegionTargetHttpsProxySslCertificates(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
107154
l := v.([]interface{})
108155
req := make([]interface{}, 0, len(l))

0 commit comments

Comments
 (0)